@@ -48,17 +48,17 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
4848}
4949
5050static void * fill_tree_desc_strict (struct tree_desc * desc ,
51- const unsigned char * hash )
51+ const struct object_id * hash )
5252{
5353 void * buffer ;
5454 enum object_type type ;
5555 unsigned long size ;
5656
57- buffer = read_sha1_file (hash , & type , & size );
57+ buffer = read_sha1_file (hash -> hash , & type , & size );
5858 if (!buffer )
59- die ("unable to read tree (%s)" , sha1_to_hex (hash ));
59+ die ("unable to read tree (%s)" , oid_to_hex (hash ));
6060 if (type != OBJ_TREE )
61- die ("%s is not a tree" , sha1_to_hex (hash ));
61+ die ("%s is not a tree" , oid_to_hex (hash ));
6262 init_tree_desc (desc , buffer , size );
6363 return buffer ;
6464}
@@ -73,7 +73,7 @@ static int base_name_entries_compare(const struct name_entry *a,
7373/*
7474 * Inspect two trees, and give a score that tells how similar they are.
7575 */
76- static int score_trees (const unsigned char * hash1 , const unsigned char * hash2 )
76+ static int score_trees (const struct object_id * hash1 , const struct object_id * hash2 )
7777{
7878 struct tree_desc one ;
7979 struct tree_desc two ;
@@ -104,7 +104,7 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
104104 else if (cmp > 0 )
105105 /* path2 does not appear in one */
106106 score += score_missing (e2 .mode , e2 .path );
107- else if (hashcmp (e1 .sha1 , e2 .sha1 ))
107+ else if (oidcmp (e1 .oid , e2 .oid ))
108108 /* they are different */
109109 score += score_differs (e1 .mode , e2 .mode , e1 .path );
110110 else
@@ -119,8 +119,8 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
119119/*
120120 * Match one itself and its subtrees with two and pick the best match.
121121 */
122- static void match_trees (const unsigned char * hash1 ,
123- const unsigned char * hash2 ,
122+ static void match_trees (const struct object_id * hash1 ,
123+ const struct object_id * hash2 ,
124124 int * best_score ,
125125 char * * best_match ,
126126 const char * base ,
@@ -131,7 +131,7 @@ static void match_trees(const unsigned char *hash1,
131131
132132 while (one .size ) {
133133 const char * path ;
134- const unsigned char * elem ;
134+ const struct object_id * elem ;
135135 unsigned mode ;
136136 int score ;
137137
@@ -191,15 +191,15 @@ static int splice_tree(const unsigned char *hash1,
191191 while (desc .size ) {
192192 const char * name ;
193193 unsigned mode ;
194- const unsigned char * sha1 ;
194+ const struct object_id * oid ;
195195
196- sha1 = tree_entry_extract (& desc , & name , & mode );
196+ oid = tree_entry_extract (& desc , & name , & mode );
197197 if (strlen (name ) == toplen &&
198198 !memcmp (name , prefix , toplen )) {
199199 if (!S_ISDIR (mode ))
200200 die ("entry %s in tree %s is not a tree" ,
201201 name , sha1_to_hex (hash1 ));
202- rewrite_here = (unsigned char * ) sha1 ;
202+ rewrite_here = (unsigned char * ) oid -> hash ;
203203 break ;
204204 }
205205 update_tree_entry (& desc );
@@ -229,9 +229,9 @@ static int splice_tree(const unsigned char *hash1,
229229 * other hand, it could cover tree one and we might need to pick a
230230 * subtree of it.
231231 */
232- void shift_tree (const unsigned char * hash1 ,
233- const unsigned char * hash2 ,
234- unsigned char * shifted ,
232+ void shift_tree (const struct object_id * hash1 ,
233+ const struct object_id * hash2 ,
234+ struct object_id * shifted ,
235235 int depth_limit )
236236{
237237 char * add_prefix ;
@@ -262,7 +262,7 @@ void shift_tree(const unsigned char *hash1,
262262 match_trees (hash2 , hash1 , & del_score , & del_prefix , "" , depth_limit );
263263
264264 /* Assume we do not have to do any shifting */
265- hashcpy (shifted , hash2 );
265+ oidcpy (shifted , hash2 );
266266
267267 if (add_score < del_score ) {
268268 /* We need to pick a subtree of two */
@@ -271,39 +271,39 @@ void shift_tree(const unsigned char *hash1,
271271 if (!* del_prefix )
272272 return ;
273273
274- if (get_tree_entry (hash2 , del_prefix , shifted , & mode ))
274+ if (get_tree_entry (hash2 -> hash , del_prefix , shifted -> hash , & mode ))
275275 die ("cannot find path %s in tree %s" ,
276- del_prefix , sha1_to_hex (hash2 ));
276+ del_prefix , oid_to_hex (hash2 ));
277277 return ;
278278 }
279279
280280 if (!* add_prefix )
281281 return ;
282282
283- splice_tree (hash1 , add_prefix , hash2 , shifted );
283+ splice_tree (hash1 -> hash , add_prefix , hash2 -> hash , shifted -> hash );
284284}
285285
286286/*
287287 * The user says the trees will be shifted by this much.
288288 * Unfortunately we cannot fundamentally tell which one to
289289 * be prefixed, as recursive merge can work in either direction.
290290 */
291- void shift_tree_by (const unsigned char * hash1 ,
292- const unsigned char * hash2 ,
293- unsigned char * shifted ,
291+ void shift_tree_by (const struct object_id * hash1 ,
292+ const struct object_id * hash2 ,
293+ struct object_id * shifted ,
294294 const char * shift_prefix )
295295{
296- unsigned char sub1 [ 20 ] , sub2 [ 20 ] ;
296+ struct object_id sub1 , sub2 ;
297297 unsigned mode1 , mode2 ;
298298 unsigned candidate = 0 ;
299299
300300 /* Can hash2 be a tree at shift_prefix in tree hash1? */
301- if (!get_tree_entry (hash1 , shift_prefix , sub1 , & mode1 ) &&
301+ if (!get_tree_entry (hash1 -> hash , shift_prefix , sub1 . hash , & mode1 ) &&
302302 S_ISDIR (mode1 ))
303303 candidate |= 1 ;
304304
305305 /* Can hash1 be a tree at shift_prefix in tree hash2? */
306- if (!get_tree_entry (hash2 , shift_prefix , sub2 , & mode2 ) &&
306+ if (!get_tree_entry (hash2 -> hash , shift_prefix , sub2 . hash , & mode2 ) &&
307307 S_ISDIR (mode2 ))
308308 candidate |= 2 ;
309309
@@ -313,19 +313,19 @@ void shift_tree_by(const unsigned char *hash1,
313313 int score ;
314314
315315 candidate = 0 ;
316- score = score_trees (sub1 , hash2 );
316+ score = score_trees (& sub1 , hash2 );
317317 if (score > best_score ) {
318318 candidate = 1 ;
319319 best_score = score ;
320320 }
321- score = score_trees (sub2 , hash1 );
321+ score = score_trees (& sub2 , hash1 );
322322 if (score > best_score )
323323 candidate = 2 ;
324324 }
325325
326326 if (!candidate ) {
327327 /* Neither is plausible -- do not shift */
328- hashcpy (shifted , hash2 );
328+ oidcpy (shifted , hash2 );
329329 return ;
330330 }
331331
@@ -334,11 +334,11 @@ void shift_tree_by(const unsigned char *hash1,
334334 * shift tree2 down by adding shift_prefix above it
335335 * to match tree1.
336336 */
337- splice_tree (hash1 , shift_prefix , hash2 , shifted );
337+ splice_tree (hash1 -> hash , shift_prefix , hash2 -> hash , shifted -> hash );
338338 else
339339 /*
340340 * shift tree2 up by removing shift_prefix from it
341341 * to match tree1.
342342 */
343- hashcpy (shifted , sub2 );
343+ oidcpy (shifted , & sub2 );
344344}
0 commit comments