1
- #define USE_THE_REPOSITORY_VARIABLE
2
1
#define DISABLE_SIGN_COMPARE_WARNINGS
3
2
4
3
#include "git-compat-util.h"
8
7
#include "tree.h"
9
8
#include "tree-walk.h"
10
9
#include "object-store-ll.h"
10
+ #include "repository.h"
11
11
12
12
static int score_missing (unsigned mode )
13
13
{
@@ -54,14 +54,15 @@ static int score_matches(unsigned mode1, unsigned mode2)
54
54
return score ;
55
55
}
56
56
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 ,
58
59
const struct object_id * hash )
59
60
{
60
61
void * buffer ;
61
62
enum object_type type ;
62
63
unsigned long size ;
63
64
64
- buffer = repo_read_object_file (the_repository , hash , & type , & size );
65
+ buffer = repo_read_object_file (r , hash , & type , & size );
65
66
if (!buffer )
66
67
die ("unable to read tree (%s)" , oid_to_hex (hash ));
67
68
if (type != OBJ_TREE )
@@ -80,12 +81,13 @@ static int base_name_entries_compare(const struct name_entry *a,
80
81
/*
81
82
* Inspect two trees, and give a score that tells how similar they are.
82
83
*/
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 )
84
86
{
85
87
struct tree_desc one ;
86
88
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 );
89
91
int score = 0 ;
90
92
91
93
for (;;) {
@@ -133,15 +135,16 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha
133
135
/*
134
136
* Match one itself and its subtrees with two and pick the best match.
135
137
*/
136
- static void match_trees (const struct object_id * hash1 ,
138
+ static void match_trees (struct repository * r ,
139
+ const struct object_id * hash1 ,
137
140
const struct object_id * hash2 ,
138
141
int * best_score ,
139
142
char * * best_match ,
140
143
const char * base ,
141
144
int recurse_limit )
142
145
{
143
146
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 );
145
148
146
149
while (one .size ) {
147
150
const char * path ;
@@ -152,15 +155,15 @@ static void match_trees(const struct object_id *hash1,
152
155
elem = tree_entry_extract (& one , & path , & mode );
153
156
if (!S_ISDIR (mode ))
154
157
goto next ;
155
- score = score_trees (elem , hash2 );
158
+ score = score_trees (r , elem , hash2 );
156
159
if (* best_score < score ) {
157
160
free (* best_match );
158
161
* best_match = xstrfmt ("%s%s" , base , path );
159
162
* best_score = score ;
160
163
}
161
164
if (recurse_limit ) {
162
165
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 ,
164
167
newbase , recurse_limit - 1 );
165
168
free (newbase );
166
169
}
@@ -175,7 +178,8 @@ static void match_trees(const struct object_id *hash1,
175
178
* A tree "oid1" has a subdirectory at "prefix". Come up with a tree object by
176
179
* replacing it with another tree "oid2".
177
180
*/
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 ,
179
183
const struct object_id * oid2 , struct object_id * result )
180
184
{
181
185
char * subpath ;
@@ -194,7 +198,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
194
198
if (* subpath )
195
199
subpath ++ ;
196
200
197
- buf = repo_read_object_file (the_repository , oid1 , & type , & sz );
201
+ buf = repo_read_object_file (r , oid1 , & type , & sz );
198
202
if (!buf )
199
203
die ("cannot read tree %s" , oid_to_hex (oid1 ));
200
204
init_tree_desc (& desc , oid1 , buf , sz );
@@ -232,15 +236,15 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
232
236
oid_to_hex (oid1 ));
233
237
if (* subpath ) {
234
238
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 );
237
241
if (status )
238
242
return status ;
239
243
rewrite_with = & subtree ;
240
244
} else {
241
245
rewrite_with = oid2 ;
242
246
}
243
- hashcpy (rewrite_here , rewrite_with -> hash , the_repository -> hash_algo );
247
+ hashcpy (rewrite_here , rewrite_with -> hash , r -> hash_algo );
244
248
status = write_object_file (buf , sz , OBJ_TREE , result );
245
249
free (buf );
246
250
return status ;
@@ -271,21 +275,21 @@ void shift_tree(struct repository *r,
271
275
if (!depth_limit )
272
276
depth_limit = 2 ;
273
277
274
- add_score = del_score = score_trees (hash1 , hash2 );
278
+ add_score = del_score = score_trees (r , hash1 , hash2 );
275
279
add_prefix = xcalloc (1 , 1 );
276
280
del_prefix = xcalloc (1 , 1 );
277
281
278
282
/*
279
283
* See if one's subtree resembles two; if so we need to prefix
280
284
* two with a few fake trees to match the prefix.
281
285
*/
282
- match_trees (hash1 , hash2 , & add_score , & add_prefix , "" , depth_limit );
286
+ match_trees (r , hash1 , hash2 , & add_score , & add_prefix , "" , depth_limit );
283
287
284
288
/*
285
289
* See if two's subtree resembles one; if so we need to
286
290
* pick only subtree of two.
287
291
*/
288
- match_trees (hash2 , hash1 , & del_score , & del_prefix , "" , depth_limit );
292
+ match_trees (r , hash2 , hash1 , & del_score , & del_prefix , "" , depth_limit );
289
293
290
294
/* Assume we do not have to do any shifting */
291
295
oidcpy (shifted , hash2 );
@@ -306,7 +310,7 @@ void shift_tree(struct repository *r,
306
310
if (!* add_prefix )
307
311
goto out ;
308
312
309
- splice_tree (hash1 , add_prefix , hash2 , shifted );
313
+ splice_tree (r , hash1 , add_prefix , hash2 , shifted );
310
314
311
315
out :
312
316
free (add_prefix );
@@ -340,16 +344,16 @@ void shift_tree_by(struct repository *r,
340
344
341
345
if (candidate == 3 ) {
342
346
/* 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 );
344
348
int score ;
345
349
346
350
candidate = 0 ;
347
- score = score_trees (& sub1 , hash2 );
351
+ score = score_trees (r , & sub1 , hash2 );
348
352
if (score > best_score ) {
349
353
candidate = 1 ;
350
354
best_score = score ;
351
355
}
352
- score = score_trees (& sub2 , hash1 );
356
+ score = score_trees (r , & sub2 , hash1 );
353
357
if (score > best_score )
354
358
candidate = 2 ;
355
359
}
@@ -365,7 +369,7 @@ void shift_tree_by(struct repository *r,
365
369
* shift tree2 down by adding shift_prefix above it
366
370
* to match tree1.
367
371
*/
368
- splice_tree (hash1 , shift_prefix , hash2 , shifted );
372
+ splice_tree (r , hash1 , shift_prefix , hash2 , shifted );
369
373
else
370
374
/*
371
375
* shift tree2 up by removing shift_prefix from it
0 commit comments