Skip to content

Commit 5e57580

Browse files
pcloudsgitster
authored andcommitted
tree-walk.c: remove the_repo from fill_tree_descriptor()
While at there, clean up the_repo usage in builtin/merge-tree.c a tiny bit. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d3b4705 commit 5e57580

File tree

9 files changed

+29
-21
lines changed

9 files changed

+29
-21
lines changed

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/rebase.c

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

843-
if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {
843+
if (!reset_hard && !fill_tree_descriptor(the_repository, &desc[nr++], &head_oid)) {
844844
ret = error(_("failed to find tree of %s"),
845845
oid_to_hex(&head_oid));
846846
goto leave_reset_head;
847847
}
848848

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

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
}

notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
397397
struct name_entry entry;
398398
const unsigned hashsz = the_hash_algo->rawsz;
399399

400-
buf = fill_tree_descriptor(&desc, &subtree->val_oid);
400+
buf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);
401401
if (!buf)
402402
die("Could not read %s for notes-index",
403403
oid_to_hex(&subtree->val_oid));

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,7 @@ static int do_reset(struct repository *r,
31943194
return error_resolve_conflict(_(action_name(opts)));
31953195
}
31963196

3197-
if (!fill_tree_descriptor(&desc, &oid)) {
3197+
if (!fill_tree_descriptor(r, &desc, &oid)) {
31983198
error(_("failed to find tree of %s"), oid_to_hex(&oid));
31993199
rollback_lock_file(&lock);
32003200
free((void *)desc.buffer);

tree-diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ static struct combine_diff_path *ll_diff_tree_paths(
422422
* diff_tree_oid(parent, commit) )
423423
*/
424424
for (i = 0; i < nparent; ++i)
425-
tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]);
426-
ttree = fill_tree_descriptor(&t, oid);
425+
tptree[i] = fill_tree_descriptor(opt->repo, &tp[i], parents_oid[i]);
426+
ttree = fill_tree_descriptor(opt->repo, &t, oid);
427427

428428
/* Enable recursion indefinitely */
429429
opt->pathspec.recursive = opt->flags.recursive;

tree-walk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l
8181
return result;
8282
}
8383

84-
void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
84+
void *fill_tree_descriptor(struct repository *r,
85+
struct tree_desc *desc,
86+
const struct object_id *oid)
8587
{
8688
unsigned long size = 0;
8789
void *buf = NULL;
8890

8991
if (oid) {
90-
buf = read_object_with_reference(the_repository, oid, tree_type, &size, NULL);
92+
buf = read_object_with_reference(r, oid, tree_type, &size, NULL);
9193
if (!buf)
9294
die("unable to read tree %s", oid_to_hex(oid));
9395
}

tree-walk.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long
4545
int tree_entry(struct tree_desc *, struct name_entry *);
4646
int tree_entry_gently(struct tree_desc *, struct name_entry *);
4747

48-
void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
48+
void *fill_tree_descriptor(struct repository *r,
49+
struct tree_desc *desc,
50+
const struct object_id *oid);
4951

5052
struct traverse_info;
5153
typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
840840
const struct object_id *oid = NULL;
841841
if (dirmask & 1)
842842
oid = &names[i].oid;
843-
buf[nr_buf++] = fill_tree_descriptor(t + i, oid);
843+
buf[nr_buf++] = fill_tree_descriptor(the_repository, t + i, oid);
844844
}
845845
}
846846

0 commit comments

Comments
 (0)