@@ -47,6 +47,22 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
4747 return score ;
4848}
4949
50+ static void * fill_tree_desc_strict (struct tree_desc * desc ,
51+ const unsigned char * hash )
52+ {
53+ void * buffer ;
54+ enum object_type type ;
55+ unsigned long size ;
56+
57+ buffer = read_sha1_file (hash , & type , & size );
58+ if (!buffer )
59+ die ("unable to read tree (%s)" , sha1_to_hex (hash ));
60+ if (type != OBJ_TREE )
61+ die ("%s is not a tree" , sha1_to_hex (hash ));
62+ init_tree_desc (desc , buffer , size );
63+ return buffer ;
64+ }
65+
5066static int base_name_entries_compare (const struct name_entry * a ,
5167 const struct name_entry * b )
5268{
@@ -61,23 +77,10 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
6177{
6278 struct tree_desc one ;
6379 struct tree_desc two ;
64- void * one_buf , * two_buf ;
80+ void * one_buf = fill_tree_desc_strict (& one , hash1 );
81+ void * two_buf = fill_tree_desc_strict (& two , hash2 );
6582 int score = 0 ;
66- enum object_type type ;
67- unsigned long size ;
6883
69- one_buf = read_sha1_file (hash1 , & type , & size );
70- if (!one_buf )
71- die ("unable to read tree (%s)" , sha1_to_hex (hash1 ));
72- if (type != OBJ_TREE )
73- die ("%s is not a tree" , sha1_to_hex (hash1 ));
74- init_tree_desc (& one , one_buf , size );
75- two_buf = read_sha1_file (hash2 , & type , & size );
76- if (!two_buf )
77- die ("unable to read tree (%s)" , sha1_to_hex (hash2 ));
78- if (type != OBJ_TREE )
79- die ("%s is not a tree" , sha1_to_hex (hash2 ));
80- init_tree_desc (& two , two_buf , size );
8184 for (;;) {
8285 struct name_entry e1 , e2 ;
8386 int got_entry_from_one = tree_entry (& one , & e1 );
@@ -124,16 +127,7 @@ static void match_trees(const unsigned char *hash1,
124127 int recurse_limit )
125128{
126129 struct tree_desc one ;
127- void * one_buf ;
128- enum object_type type ;
129- unsigned long size ;
130-
131- one_buf = read_sha1_file (hash1 , & type , & size );
132- if (!one_buf )
133- die ("unable to read tree (%s)" , sha1_to_hex (hash1 ));
134- if (type != OBJ_TREE )
135- die ("%s is not a tree" , sha1_to_hex (hash1 ));
136- init_tree_desc (& one , one_buf , size );
130+ void * one_buf = fill_tree_desc_strict (& one , hash1 );
137131
138132 while (one .size ) {
139133 const char * path ;
0 commit comments