1- #define USE_THE_REPOSITORY_VARIABLE
21#define DISABLE_SIGN_COMPARE_WARNINGS
32
43#include "git-compat-util.h"
87#include "tree.h"
98#include "tree-walk.h"
109#include "object-store-ll.h"
10+ #include "repository.h"
1111
1212static int score_missing (unsigned mode )
1313{
@@ -54,14 +54,15 @@ static int score_matches(unsigned mode1, unsigned mode2)
5454 return score ;
5555}
5656
57- static void * fill_tree_desc_strict (struct tree_desc * desc ,
57+ static void * fill_tree_desc_strict (struct repository * r ,
58+ struct tree_desc * desc ,
5859 const struct object_id * hash )
5960{
6061 void * buffer ;
6162 enum object_type type ;
6263 unsigned long size ;
6364
64- buffer = repo_read_object_file (the_repository , hash , & type , & size );
65+ buffer = repo_read_object_file (r , hash , & type , & size );
6566 if (!buffer )
6667 die ("unable to read tree (%s)" , oid_to_hex (hash ));
6768 if (type != OBJ_TREE )
@@ -80,12 +81,13 @@ static int base_name_entries_compare(const struct name_entry *a,
8081/*
8182 * Inspect two trees, and give a score that tells how similar they are.
8283 */
83- static int score_trees (const struct object_id * hash1 , const struct object_id * hash2 )
84+ static int score_trees (struct repository * r ,
85+ const struct object_id * hash1 , const struct object_id * hash2 )
8486{
8587 struct tree_desc one ;
8688 struct tree_desc two ;
87- void * one_buf = fill_tree_desc_strict (& one , hash1 );
88- void * two_buf = fill_tree_desc_strict (& two , hash2 );
89+ void * one_buf = fill_tree_desc_strict (r , & one , hash1 );
90+ void * two_buf = fill_tree_desc_strict (r , & two , hash2 );
8991 int score = 0 ;
9092
9193 for (;;) {
@@ -133,15 +135,16 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha
133135/*
134136 * Match one itself and its subtrees with two and pick the best match.
135137 */
136- static void match_trees (const struct object_id * hash1 ,
138+ static void match_trees (struct repository * r ,
139+ const struct object_id * hash1 ,
137140 const struct object_id * hash2 ,
138141 int * best_score ,
139142 char * * best_match ,
140143 const char * base ,
141144 int recurse_limit )
142145{
143146 struct tree_desc one ;
144- void * one_buf = fill_tree_desc_strict (& one , hash1 );
147+ void * one_buf = fill_tree_desc_strict (r , & one , hash1 );
145148
146149 while (one .size ) {
147150 const char * path ;
@@ -152,15 +155,15 @@ static void match_trees(const struct object_id *hash1,
152155 elem = tree_entry_extract (& one , & path , & mode );
153156 if (!S_ISDIR (mode ))
154157 goto next ;
155- score = score_trees (elem , hash2 );
158+ score = score_trees (r , elem , hash2 );
156159 if (* best_score < score ) {
157160 free (* best_match );
158161 * best_match = xstrfmt ("%s%s" , base , path );
159162 * best_score = score ;
160163 }
161164 if (recurse_limit ) {
162165 char * newbase = xstrfmt ("%s%s/" , base , path );
163- match_trees (elem , hash2 , best_score , best_match ,
166+ match_trees (r , elem , hash2 , best_score , best_match ,
164167 newbase , recurse_limit - 1 );
165168 free (newbase );
166169 }
@@ -175,7 +178,8 @@ static void match_trees(const struct object_id *hash1,
175178 * A tree "oid1" has a subdirectory at "prefix". Come up with a tree object by
176179 * replacing it with another tree "oid2".
177180 */
178- static int splice_tree (const struct object_id * oid1 , const char * prefix ,
181+ static int splice_tree (struct repository * r ,
182+ const struct object_id * oid1 , const char * prefix ,
179183 const struct object_id * oid2 , struct object_id * result )
180184{
181185 char * subpath ;
@@ -194,7 +198,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
194198 if (* subpath )
195199 subpath ++ ;
196200
197- buf = repo_read_object_file (the_repository , oid1 , & type , & sz );
201+ buf = repo_read_object_file (r , oid1 , & type , & sz );
198202 if (!buf )
199203 die ("cannot read tree %s" , oid_to_hex (oid1 ));
200204 init_tree_desc (& desc , oid1 , buf , sz );
@@ -232,15 +236,15 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
232236 oid_to_hex (oid1 ));
233237 if (* subpath ) {
234238 struct object_id tree_oid ;
235- oidread (& tree_oid , rewrite_here , the_repository -> hash_algo );
236- status = splice_tree (& tree_oid , subpath , oid2 , & subtree );
239+ oidread (& tree_oid , rewrite_here , r -> hash_algo );
240+ status = splice_tree (r , & tree_oid , subpath , oid2 , & subtree );
237241 if (status )
238242 return status ;
239243 rewrite_with = & subtree ;
240244 } else {
241245 rewrite_with = oid2 ;
242246 }
243- hashcpy (rewrite_here , rewrite_with -> hash , the_repository -> hash_algo );
247+ hashcpy (rewrite_here , rewrite_with -> hash , r -> hash_algo );
244248 status = write_object_file (buf , sz , OBJ_TREE , result );
245249 free (buf );
246250 return status ;
@@ -271,21 +275,21 @@ void shift_tree(struct repository *r,
271275 if (!depth_limit )
272276 depth_limit = 2 ;
273277
274- add_score = del_score = score_trees (hash1 , hash2 );
278+ add_score = del_score = score_trees (r , hash1 , hash2 );
275279 add_prefix = xcalloc (1 , 1 );
276280 del_prefix = xcalloc (1 , 1 );
277281
278282 /*
279283 * See if one's subtree resembles two; if so we need to prefix
280284 * two with a few fake trees to match the prefix.
281285 */
282- match_trees (hash1 , hash2 , & add_score , & add_prefix , "" , depth_limit );
286+ match_trees (r , hash1 , hash2 , & add_score , & add_prefix , "" , depth_limit );
283287
284288 /*
285289 * See if two's subtree resembles one; if so we need to
286290 * pick only subtree of two.
287291 */
288- match_trees (hash2 , hash1 , & del_score , & del_prefix , "" , depth_limit );
292+ match_trees (r , hash2 , hash1 , & del_score , & del_prefix , "" , depth_limit );
289293
290294 /* Assume we do not have to do any shifting */
291295 oidcpy (shifted , hash2 );
@@ -306,7 +310,7 @@ void shift_tree(struct repository *r,
306310 if (!* add_prefix )
307311 goto out ;
308312
309- splice_tree (hash1 , add_prefix , hash2 , shifted );
313+ splice_tree (r , hash1 , add_prefix , hash2 , shifted );
310314
311315out :
312316 free (add_prefix );
@@ -340,16 +344,16 @@ void shift_tree_by(struct repository *r,
340344
341345 if (candidate == 3 ) {
342346 /* Both are plausible -- we need to evaluate the score */
343- int best_score = score_trees (hash1 , hash2 );
347+ int best_score = score_trees (r , hash1 , hash2 );
344348 int score ;
345349
346350 candidate = 0 ;
347- score = score_trees (& sub1 , hash2 );
351+ score = score_trees (r , & sub1 , hash2 );
348352 if (score > best_score ) {
349353 candidate = 1 ;
350354 best_score = score ;
351355 }
352- score = score_trees (& sub2 , hash1 );
356+ score = score_trees (r , & sub2 , hash1 );
353357 if (score > best_score )
354358 candidate = 2 ;
355359 }
@@ -365,7 +369,7 @@ void shift_tree_by(struct repository *r,
365369 * shift tree2 down by adding shift_prefix above it
366370 * to match tree1.
367371 */
368- splice_tree (hash1 , shift_prefix , hash2 , shifted );
372+ splice_tree (r , hash1 , shift_prefix , hash2 , shifted );
369373 else
370374 /*
371375 * shift tree2 up by removing shift_prefix from it
0 commit comments