@@ -57,15 +57,6 @@ push_tree_stack_entry(struct view *view, const char *name, struct position *posi
5757 * 100644 blob 95925677ca47beb0b8cce7c0e0011bcc3f61470f 213045 tig.c
5858 */
5959
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-
6960#define tree_path_is_parent (path ) (!strcmp("..", (path)))
7061
7162struct tree_entry {
@@ -222,21 +213,50 @@ tree_read(struct view *view, struct buffer *buf, bool force_stop)
222213 struct tree_entry * data ;
223214 struct line * entry , * line ;
224215 enum line_type type ;
216+ char * pos ;
217+ char * mode ;
218+ char * id ;
225219 char * path ;
226220 size_t size ;
227221
228222 if (state -> read_date || !buf )
229223 return tree_read_date (view , buf , state );
230224
231- if (buf -> size <= SIZEOF_TREE_ATTR )
232- return false;
233225 if (view -> lines == 0 &&
234226 !tree_entry (view , LINE_HEADER , view -> env -> directory , NULL , NULL , 0 ))
235227 return false;
236228
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 )
240260 return false;
241261 path ++ ;
242262
@@ -255,8 +275,7 @@ tree_read(struct view *view, struct buffer *buf, bool force_stop)
255275 return false;
256276 }
257277
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 );
260279 if (!entry )
261280 return false;
262281 data = entry -> data ;
0 commit comments