Skip to content

Commit 82db3d4

Browse files
bk2204gitster
authored andcommitted
match-trees: convert shift_tree() and shift_tree_by() to use object_id
Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9baaf9 commit 82db3d4

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,8 +1738,8 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int
17381738
extern int diff_auto_refresh_index;
17391739

17401740
/* match-trees.c */
1741-
void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);
1742-
void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *, const char *);
1741+
void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);
1742+
void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);
17431743

17441744
/*
17451745
* whitespace rules.

match-trees.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -245,24 +245,24 @@ void shift_tree(const unsigned char *hash1,
245245
if (!depth_limit)
246246
depth_limit = 2;
247247

248-
add_score = del_score = score_trees(hash1, hash2);
248+
add_score = del_score = score_trees(hash1->hash, hash2->hash);
249249
add_prefix = xcalloc(1, 1);
250250
del_prefix = xcalloc(1, 1);
251251

252252
/*
253253
* See if one's subtree resembles two; if so we need to prefix
254254
* two with a few fake trees to match the prefix.
255255
*/
256-
match_trees(hash1, hash2, &add_score, &add_prefix, "", depth_limit);
256+
match_trees(hash1->hash, hash2->hash, &add_score, &add_prefix, "", depth_limit);
257257

258258
/*
259259
* See if two's subtree resembles one; if so we need to
260260
* pick only subtree of two.
261261
*/
262-
match_trees(hash2, hash1, &del_score, &del_prefix, "", depth_limit);
262+
match_trees(hash2->hash, hash1->hash, &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,61 +271,61 @@ 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

310310
if (candidate == 3) {
311311
/* Both are plausible -- we need to evaluate the score */
312-
int best_score = score_trees(hash1, hash2);
312+
int best_score = score_trees(hash1->hash, hash2->hash);
313313
int score;
314314

315315
candidate = 0;
316-
score = score_trees(sub1, hash2);
316+
score = score_trees(sub1.hash, hash2->hash);
317317
if (score > best_score) {
318318
candidate = 1;
319319
best_score = score;
320320
}
321-
score = score_trees(sub2, hash1);
321+
score = score_trees(sub2.hash, hash1->hash);
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
}

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
2929
struct object_id shifted;
3030

3131
if (!*subtree_shift) {
32-
shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, 0);
32+
shift_tree(&one->object.oid, &two->object.oid, &shifted, 0);
3333
} else {
34-
shift_tree_by(one->object.oid.hash, two->object.oid.hash, shifted.hash,
34+
shift_tree_by(&one->object.oid, &two->object.oid, &shifted,
3535
subtree_shift);
3636
}
3737
if (!oidcmp(&two->object.oid, &shifted))

test-match-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main(int ac, char **av)
1717
if (!two)
1818
die("not a tree-ish %s", av[2]);
1919

20-
shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, -1);
20+
shift_tree(&one->object.oid, &two->object.oid, &shifted, -1);
2121
printf("shifted: %s\n", oid_to_hex(&shifted));
2222

2323
exit(0);

0 commit comments

Comments
 (0)