@@ -47,6 +47,22 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
47
47
return score ;
48
48
}
49
49
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
+
50
66
static int base_name_entries_compare (const struct name_entry * a ,
51
67
const struct name_entry * b )
52
68
{
@@ -61,23 +77,10 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
61
77
{
62
78
struct tree_desc one ;
63
79
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 );
65
82
int score = 0 ;
66
- enum object_type type ;
67
- unsigned long size ;
68
83
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 );
81
84
for (;;) {
82
85
struct name_entry e1 , e2 ;
83
86
int got_entry_from_one = tree_entry (& one , & e1 );
@@ -124,16 +127,7 @@ static void match_trees(const unsigned char *hash1,
124
127
int recurse_limit )
125
128
{
126
129
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 );
137
131
138
132
while (one .size ) {
139
133
const char * path ;
0 commit comments