@@ -57,15 +57,6 @@ push_tree_stack_entry(struct view *view, const char *name, struct position *posi
57
57
* 100644 blob 95925677ca47beb0b8cce7c0e0011bcc3f61470f 213045 tig.c
58
58
*/
59
59
60
- #define SIZEOF_TREE_ATTR \
61
- STRING_SIZE("100644 blob f931e1d229c3e185caad4449bf5b66ed72462657\t")
62
-
63
- #define SIZEOF_TREE_MODE \
64
- STRING_SIZE("100644 ")
65
-
66
- #define TREE_ID_OFFSET \
67
- STRING_SIZE("100644 blob ")
68
-
69
60
#define tree_path_is_parent (path ) (!strcmp("..", (path)))
70
61
71
62
struct tree_entry {
@@ -222,21 +213,50 @@ tree_read(struct view *view, struct buffer *buf, bool force_stop)
222
213
struct tree_entry * data ;
223
214
struct line * entry , * line ;
224
215
enum line_type type ;
216
+ char * pos ;
217
+ char * mode ;
218
+ char * id ;
225
219
char * path ;
226
220
size_t size ;
227
221
228
222
if (state -> read_date || !buf )
229
223
return tree_read_date (view , buf , state );
230
224
231
- if (buf -> size <= SIZEOF_TREE_ATTR )
232
- return false;
233
225
if (view -> lines == 0 &&
234
226
!tree_entry (view , LINE_HEADER , view -> env -> directory , NULL , NULL , 0 ))
235
227
return false;
236
228
237
- size = parse_size (buf -> data + SIZEOF_TREE_ATTR );
238
- path = strchr (buf -> data + SIZEOF_TREE_ATTR , '\t' );
239
- if (!path )
229
+ /* 100644 */
230
+ mode = buf -> data ;
231
+
232
+ /* blob */
233
+ pos = strchr (mode , ' ' );
234
+ if (!pos || !* pos )
235
+ return false;
236
+ pos ++ ;
237
+ if (!strncmp (pos , "blob" , STRING_SIZE ("blob" )))
238
+ type = LINE_FILE ;
239
+ else if (!strncmp (pos , "tree" , STRING_SIZE ("tree" )))
240
+ type = LINE_DIRECTORY ;
241
+ else
242
+ type = LINE_DEFAULT ;
243
+
244
+ /* 95925677ca47beb0b8cce7c0e0011bcc3f61470f */
245
+ id = strchr (pos , ' ' );
246
+ if (!id || !* id )
247
+ return false;
248
+ id ++ ;
249
+
250
+ /* 213045 */
251
+ pos = strchr (id , ' ' );
252
+ if (!pos || !* pos )
253
+ return false;
254
+ pos ++ ;
255
+ size = parse_size (pos );
256
+
257
+ /* tig.c */
258
+ path = strchr (pos , '\t' );
259
+ if (!path || !* path )
240
260
return false;
241
261
path ++ ;
242
262
@@ -255,8 +275,7 @@ tree_read(struct view *view, struct buffer *buf, bool force_stop)
255
275
return false;
256
276
}
257
277
258
- type = buf -> data [SIZEOF_TREE_MODE ] == 't' ? LINE_DIRECTORY : LINE_FILE ;
259
- entry = tree_entry (view , type , path , buf -> data , buf -> data + TREE_ID_OFFSET , size );
278
+ entry = tree_entry (view , type , path , mode , id , size );
260
279
if (!entry )
261
280
return false;
262
281
data = entry -> data ;
0 commit comments