Skip to content

Commit 1eb0a12

Browse files
committed
Merge branch 'nd/tree-walk-with-repo'
The tree-walk API learned to pass an in-core repository instance throughout more codepaths. * nd/tree-walk-with-repo: t7814: do not generate same commits in different repos Use the right 'struct repository' instead of the_repository match-trees.c: remove the_repo from shift_tree*() tree-walk.c: remove the_repo from get_tree_entry_follow_symlinks() tree-walk.c: remove the_repo from get_tree_entry() tree-walk.c: remove the_repo from fill_tree_descriptor() sha1-file.c: remove the_repo from read_object_with_reference()
2 parents d97c62c + 663d250 commit 1eb0a12

26 files changed

+146
-98
lines changed

archive.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,
418418
unsigned short mode;
419419
int err;
420420

421-
err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
421+
err = get_tree_entry(ar_args->repo,
422+
&tree->object.oid,
423+
prefix, &tree_oid,
422424
&mode);
423425
if (err || !S_ISDIR(mode))
424426
die(_("current working directory is untracked"));

blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void verify_working_tree_path(struct repository *r,
101101
struct object_id blob_oid;
102102
unsigned short mode;
103103

104-
if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
104+
if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
105105
oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
106106
return;
107107
}
@@ -1232,7 +1232,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
12321232
{
12331233
if (!is_null_oid(&origin->blob_oid))
12341234
return 0;
1235-
if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
1235+
if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
12361236
goto error_out;
12371237
if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
12381238
goto error_out;

builtin/cat-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
172172
* fall-back to the usual case.
173173
*/
174174
}
175-
buf = read_object_with_reference(&oid, exp_type, &size, NULL);
175+
buf = read_object_with_reference(the_repository,
176+
&oid, exp_type, &size, NULL);
176177
break;
177178

178179
default:

builtin/grep.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ static int grep_submodule(struct grep_opt *opt,
458458
object = parse_object_or_die(oid, oid_to_hex(oid));
459459

460460
grep_read_lock();
461-
data = read_object_with_reference(&object->oid, tree_type,
461+
data = read_object_with_reference(&subrepo,
462+
&object->oid, tree_type,
462463
&size, NULL);
463464
grep_read_unlock();
464465

@@ -623,7 +624,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
623624
int hit, len;
624625

625626
grep_read_lock();
626-
data = read_object_with_reference(&obj->oid, tree_type,
627+
data = read_object_with_reference(opt->repo,
628+
&obj->oid, tree_type,
627629
&size, NULL);
628630
grep_read_unlock();
629631

builtin/merge-tree.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
205205
static void unresolved_directory(const struct traverse_info *info,
206206
struct name_entry n[3])
207207
{
208+
struct repository *r = the_repository;
208209
char *newbase;
209210
struct name_entry *p;
210211
struct tree_desc t[3];
@@ -220,9 +221,9 @@ static void unresolved_directory(const struct traverse_info *info,
220221
newbase = traverse_path(info, p);
221222

222223
#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? &(e)->oid : NULL)
223-
buf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));
224-
buf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));
225-
buf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));
224+
buf0 = fill_tree_descriptor(r, t + 0, ENTRY_OID(n + 0));
225+
buf1 = fill_tree_descriptor(r, t + 1, ENTRY_OID(n + 1));
226+
buf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2));
226227
#undef ENTRY_OID
227228

228229
merge_trees(t, newbase);
@@ -351,30 +352,33 @@ static void merge_trees(struct tree_desc t[3], const char *base)
351352
traverse_trees(&the_index, 3, t, &info);
352353
}
353354

354-
static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
355+
static void *get_tree_descriptor(struct repository *r,
356+
struct tree_desc *desc,
357+
const char *rev)
355358
{
356359
struct object_id oid;
357360
void *buf;
358361

359-
if (get_oid(rev, &oid))
362+
if (repo_get_oid(r, rev, &oid))
360363
die("unknown rev %s", rev);
361-
buf = fill_tree_descriptor(desc, &oid);
364+
buf = fill_tree_descriptor(r, desc, &oid);
362365
if (!buf)
363366
die("%s is not a tree", rev);
364367
return buf;
365368
}
366369

367370
int cmd_merge_tree(int argc, const char **argv, const char *prefix)
368371
{
372+
struct repository *r = the_repository;
369373
struct tree_desc t[3];
370374
void *buf1, *buf2, *buf3;
371375

372376
if (argc != 4)
373377
usage(merge_tree_usage);
374378

375-
buf1 = get_tree_descriptor(t+0, argv[1]);
376-
buf2 = get_tree_descriptor(t+1, argv[2]);
377-
buf3 = get_tree_descriptor(t+2, argv[3]);
379+
buf1 = get_tree_descriptor(r, t+0, argv[1]);
380+
buf2 = get_tree_descriptor(r, t+1, argv[2]);
381+
buf3 = get_tree_descriptor(r, t+2, argv[3]);
378382
merge_trees(t, "");
379383
free(buf1);
380384
free(buf2);

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,8 @@ static void add_preferred_base(struct object_id *oid)
14281428
if (window <= num_preferred_base++)
14291429
return;
14301430

1431-
data = read_object_with_reference(oid, tree_type, &size, &tree_oid);
1431+
data = read_object_with_reference(the_repository, oid,
1432+
tree_type, &size, &tree_oid);
14321433
if (!data)
14331434
return;
14341435

builtin/rebase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,13 @@ static int reset_head(struct object_id *oid, const char *action,
850850
goto leave_reset_head;
851851
}
852852

853-
if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {
853+
if (!reset_hard && !fill_tree_descriptor(the_repository, &desc[nr++], &head_oid)) {
854854
ret = error(_("failed to find tree of %s"),
855855
oid_to_hex(&head_oid));
856856
goto leave_reset_head;
857857
}
858858

859-
if (!fill_tree_descriptor(&desc[nr++], oid)) {
859+
if (!fill_tree_descriptor(the_repository, &desc[nr++], oid)) {
860860
ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
861861
goto leave_reset_head;
862862
}

builtin/reset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
7979
struct object_id head_oid;
8080
if (get_oid("HEAD", &head_oid))
8181
return error(_("You do not have a valid HEAD."));
82-
if (!fill_tree_descriptor(desc + nr, &head_oid))
82+
if (!fill_tree_descriptor(the_repository, desc + nr, &head_oid))
8383
return error(_("Failed to find tree of HEAD."));
8484
nr++;
8585
opts.fn = twoway_merge;
8686
}
8787

88-
if (!fill_tree_descriptor(desc + nr, oid)) {
88+
if (!fill_tree_descriptor(the_repository, desc + nr, oid)) {
8989
error(_("Failed to find tree of %s."), oid_to_hex(oid));
9090
goto out;
9191
}

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)
179179
* way as changed from the HEAD.
180180
*/
181181
if (no_head
182-
|| get_tree_entry(head, name, &oid, &mode)
182+
|| get_tree_entry(the_repository, head, name, &oid, &mode)
183183
|| ce->ce_mode != create_ce_mode(mode)
184184
|| !oideq(&ce->oid, &oid))
185185
staged_changes = 1;

builtin/update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,
601601
struct object_id oid;
602602
struct cache_entry *ce;
603603

604-
if (get_tree_entry(ent, path, &oid, &mode)) {
604+
if (get_tree_entry(the_repository, ent, path, &oid, &mode)) {
605605
if (which)
606606
error("%s: not in %s branch.", path, which);
607607
return NULL;

cache.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,8 @@ int df_name_compare(const char *name1, int len1, int mode1, const char *name2, i
14761476
int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
14771477
int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
14781478

1479-
void *read_object_with_reference(const struct object_id *oid,
1479+
void *read_object_with_reference(struct repository *r,
1480+
const struct object_id *oid,
14801481
const char *required_type,
14811482
unsigned long *size,
14821483
struct object_id *oid_ret);
@@ -1762,8 +1763,8 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int
17621763
extern int diff_auto_refresh_index;
17631764

17641765
/* match-trees.c */
1765-
void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);
1766-
void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);
1766+
void shift_tree(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, int);
1767+
void shift_tree_by(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, const char *);
17671768

17681769
/*
17691770
* whitespace rules.

fast-import.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
24102410
oidcpy(&commit_oid, &commit_oe->idx.oid);
24112411
} else if (!get_oid(p, &commit_oid)) {
24122412
unsigned long size;
2413-
char *buf = read_object_with_reference(&commit_oid,
2413+
char *buf = read_object_with_reference(the_repository,
2414+
&commit_oid,
24142415
commit_type, &size,
24152416
&commit_oid);
24162417
if (!buf || size < the_hash_algo->hexsz + 6)
@@ -2482,7 +2483,8 @@ static void parse_from_existing(struct branch *b)
24822483
unsigned long size;
24832484
char *buf;
24842485

2485-
buf = read_object_with_reference(&b->oid, commit_type, &size,
2486+
buf = read_object_with_reference(the_repository,
2487+
&b->oid, commit_type, &size,
24862488
&b->oid);
24872489
parse_from_commit(b, buf, size);
24882490
free(buf);
@@ -2560,7 +2562,8 @@ static struct hash_list *parse_merge(unsigned int *count)
25602562
oidcpy(&n->oid, &oe->idx.oid);
25612563
} else if (!get_oid(from, &n->oid)) {
25622564
unsigned long size;
2563-
char *buf = read_object_with_reference(&n->oid,
2565+
char *buf = read_object_with_reference(the_repository,
2566+
&n->oid,
25642567
commit_type,
25652568
&size, &n->oid);
25662569
if (!buf || size < the_hash_algo->hexsz + 6)

line-log.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,13 @@ static struct commit *check_single_commit(struct rev_info *revs)
496496
return (struct commit *) commit;
497497
}
498498

499-
static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)
499+
static void fill_blob_sha1(struct repository *r, struct commit *commit,
500+
struct diff_filespec *spec)
500501
{
501502
unsigned short mode;
502503
struct object_id oid;
503504

504-
if (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))
505+
if (get_tree_entry(r, &commit->object.oid, spec->path, &oid, &mode))
505506
die("There is no path %s in the commit", spec->path);
506507
fill_filespec(spec, &oid, 1, mode);
507508

@@ -585,7 +586,7 @@ parse_lines(struct repository *r, struct commit *commit,
585586
name_part);
586587

587588
spec = alloc_filespec(full_name);
588-
fill_blob_sha1(commit, spec);
589+
fill_blob_sha1(r, commit, spec);
589590
fill_line_ends(r, spec, &lines, &ends);
590591
cb_data.spec = spec;
591592
cb_data.lines = lines;

match-trees.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
248248
* other hand, it could cover tree one and we might need to pick a
249249
* subtree of it.
250250
*/
251-
void shift_tree(const struct object_id *hash1,
251+
void shift_tree(struct repository *r,
252+
const struct object_id *hash1,
252253
const struct object_id *hash2,
253254
struct object_id *shifted,
254255
int depth_limit)
@@ -290,7 +291,7 @@ void shift_tree(const struct object_id *hash1,
290291
if (!*del_prefix)
291292
return;
292293

293-
if (get_tree_entry(hash2, del_prefix, shifted, &mode))
294+
if (get_tree_entry(r, hash2, del_prefix, shifted, &mode))
294295
die("cannot find path %s in tree %s",
295296
del_prefix, oid_to_hex(hash2));
296297
return;
@@ -307,7 +308,8 @@ void shift_tree(const struct object_id *hash1,
307308
* Unfortunately we cannot fundamentally tell which one to
308309
* be prefixed, as recursive merge can work in either direction.
309310
*/
310-
void shift_tree_by(const struct object_id *hash1,
311+
void shift_tree_by(struct repository *r,
312+
const struct object_id *hash1,
311313
const struct object_id *hash2,
312314
struct object_id *shifted,
313315
const char *shift_prefix)
@@ -317,12 +319,12 @@ void shift_tree_by(const struct object_id *hash1,
317319
unsigned candidate = 0;
318320

319321
/* Can hash2 be a tree at shift_prefix in tree hash1? */
320-
if (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&
322+
if (!get_tree_entry(r, hash1, shift_prefix, &sub1, &mode1) &&
321323
S_ISDIR(mode1))
322324
candidate |= 1;
323325

324326
/* Can hash1 be a tree at shift_prefix in tree hash2? */
325-
if (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&
327+
if (!get_tree_entry(r, hash2, shift_prefix, &sub2, &mode2) &&
326328
S_ISDIR(mode2))
327329
candidate |= 2;
328330

0 commit comments

Comments
 (0)