Skip to content

Commit ec7a16b

Browse files
rscharfegitster
authored andcommitted
cocci: convert parse_tree functions to repo_ variants
Add and apply a semantic patch to convert calls to parse_tree() and friends to the corresponding variant that takes a repository argument, to allow the functions that implicitly use the_repository to be retired once all potential in-flight topics are settled and converted as well. The changes in .c files were generated by Coccinelle, but I fixed a whitespace bug it would have introduced to builtin/commit.c. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a8a50f2 commit ec7a16b

27 files changed

+73
-56
lines changed

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static void parse_treeish_arg(const char **argv,
519519
if (ar_args->mtime_option)
520520
archive_time = approxidate(ar_args->mtime_option);
521521

522-
tree = parse_tree_indirect(&oid);
522+
tree = repo_parse_tree_indirect(the_repository, &oid);
523523
if (!tree)
524524
die(_("not a tree object: %s"), oid_to_hex(&oid));
525525

builtin/am.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
19981998
struct unpack_trees_options opts;
19991999
struct tree_desc t[2];
20002000

2001-
if (parse_tree(head) || parse_tree(remote))
2001+
if (repo_parse_tree(the_repository, head) || repo_parse_tree(the_repository, remote))
20022002
return -1;
20032003

20042004
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
@@ -2038,7 +2038,7 @@ static int merge_tree(struct tree *tree)
20382038
struct unpack_trees_options opts;
20392039
struct tree_desc t[1];
20402040

2041-
if (parse_tree(tree))
2041+
if (repo_parse_tree(the_repository, tree))
20422042
return -1;
20432043

20442044
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
@@ -2071,11 +2071,11 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20712071
struct tree *head_tree, *remote_tree, *index_tree;
20722072
struct object_id index;
20732073

2074-
head_tree = parse_tree_indirect(head);
2074+
head_tree = repo_parse_tree_indirect(the_repository, head);
20752075
if (!head_tree)
20762076
return error(_("Could not parse object '%s'."), oid_to_hex(head));
20772077

2078-
remote_tree = parse_tree_indirect(remote);
2078+
remote_tree = repo_parse_tree_indirect(the_repository, remote);
20792079
if (!remote_tree)
20802080
return error(_("Could not parse object '%s'."), oid_to_hex(remote));
20812081

@@ -2089,7 +2089,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20892089
0, NULL))
20902090
return -1;
20912091

2092-
index_tree = parse_tree_indirect(&index);
2092+
index_tree = repo_parse_tree_indirect(the_repository, &index);
20932093
if (!index_tree)
20942094
return error(_("Could not parse object '%s'."), oid_to_hex(&index));
20952095

builtin/checkout.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
724724
init_checkout_metadata(&opts.meta, info->refname,
725725
info->commit ? &info->commit->object.oid : null_oid(the_hash_algo),
726726
NULL);
727-
if (parse_tree(tree) < 0)
727+
if (repo_parse_tree(the_repository, tree) < 0)
728728
return 128;
729729
init_tree_desc(&tree_desc, &tree->object.oid, tree->buffer, tree->size);
730730
switch (unpack_trees(1, &tree_desc, &opts)) {
@@ -803,7 +803,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
803803
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
804804
if (new_branch_info->commit)
805805
BUG("'switch --orphan' should never accept a commit as starting point");
806-
new_tree = parse_tree_indirect(the_hash_algo->empty_tree);
806+
new_tree = repo_parse_tree_indirect(the_repository,
807+
the_hash_algo->empty_tree);
807808
if (!new_tree)
808809
BUG("unable to read empty tree");
809810
} else {
@@ -841,14 +842,15 @@ static int merge_working_tree(const struct checkout_opts *opts,
841842
old_commit_oid = old_branch_info->commit ?
842843
&old_branch_info->commit->object.oid :
843844
the_hash_algo->empty_tree;
844-
tree = parse_tree_indirect(old_commit_oid);
845+
tree = repo_parse_tree_indirect(the_repository,
846+
old_commit_oid);
845847
if (!tree)
846848
die(_("unable to parse commit %s"),
847849
oid_to_hex(old_commit_oid));
848850

849851
init_tree_desc(&trees[0], &tree->object.oid,
850852
tree->buffer, tree->size);
851-
if (parse_tree(new_tree) < 0)
853+
if (repo_parse_tree(the_repository, new_tree) < 0)
852854
die(NULL);
853855
tree = new_tree;
854856
init_tree_desc(&trees[1], &tree->object.oid,
@@ -1278,7 +1280,7 @@ static void setup_new_branch_info_and_source_tree(
12781280
new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1);
12791281
if (!new_branch_info->commit) {
12801282
/* not a commit */
1281-
*source_tree = parse_tree_indirect(rev);
1283+
*source_tree = repo_parse_tree_indirect(the_repository, rev);
12821284
if (!*source_tree)
12831285
die(_("unable to read tree (%s)"), oid_to_hex(rev));
12841286
} else {

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,10 @@ static int checkout(int submodule_progress, int filter_submodules,
680680
opts.dst_index = the_repository->index;
681681
init_checkout_metadata(&opts.meta, head, &oid, NULL);
682682

683-
tree = parse_tree_indirect(&oid);
683+
tree = repo_parse_tree_indirect(the_repository, &oid);
684684
if (!tree)
685685
die(_("unable to parse commit %s"), oid_to_hex(&oid));
686-
if (parse_tree(tree) < 0)
686+
if (repo_parse_tree(the_repository, tree) < 0)
687687
exit(128);
688688
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
689689
if (unpack_trees(1, &t, &opts) < 0)

builtin/commit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,11 @@ static void create_base_index(const struct commit *current_head)
327327
opts.dst_index = the_repository->index;
328328

329329
opts.fn = oneway_merge;
330-
tree = parse_tree_indirect(&current_head->object.oid);
330+
tree = repo_parse_tree_indirect(the_repository,
331+
&current_head->object.oid);
331332
if (!tree)
332333
die(_("failed to unpack HEAD tree object"));
333-
if (parse_tree(tree) < 0)
334+
if (repo_parse_tree(the_repository, tree) < 0)
334335
exit(128);
335336
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
336337
if (unpack_trees(1, &t, &opts))

builtin/diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
5252
if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
5353
return error("Need exactly two trees, separated by a space");
5454
tree2 = lookup_tree(the_repository, &oid);
55-
if (!tree2 || parse_tree(tree2))
55+
if (!tree2 || repo_parse_tree(the_repository, tree2))
5656
return -1;
5757
printf("%s %s\n", oid_to_hex(&tree1->object.oid),
5858
oid_to_hex(&tree2->object.oid));

builtin/ls-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ int cmd_ls_tree(int argc,
421421
for (i = 0; i < options.pathspec.nr; i++)
422422
options.pathspec.items[i].nowildcard_len = options.pathspec.items[i].len;
423423
options.pathspec.has_wildcard = 0;
424-
tree = parse_tree_indirect(&oid);
424+
tree = repo_parse_tree_indirect(the_repository, &oid);
425425
if (!tree)
426426
die("not a tree object");
427427
/*

builtin/merge-tree.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,20 @@ static int real_merge(struct merge_tree_options *o,
447447

448448
if (repo_get_oid_treeish(the_repository, merge_base, &base_oid))
449449
die(_("could not parse as tree '%s'"), merge_base);
450-
base_tree = parse_tree_indirect(&base_oid);
450+
base_tree = repo_parse_tree_indirect(the_repository,
451+
&base_oid);
451452
if (!base_tree)
452453
die(_("unable to read tree (%s)"), oid_to_hex(&base_oid));
453454
if (repo_get_oid_treeish(the_repository, branch1, &head_oid))
454455
die(_("could not parse as tree '%s'"), branch1);
455-
parent1_tree = parse_tree_indirect(&head_oid);
456+
parent1_tree = repo_parse_tree_indirect(the_repository,
457+
&head_oid);
456458
if (!parent1_tree)
457459
die(_("unable to read tree (%s)"), oid_to_hex(&head_oid));
458460
if (repo_get_oid_treeish(the_repository, branch2, &merge_oid))
459461
die(_("could not parse as tree '%s'"), branch2);
460-
parent2_tree = parse_tree_indirect(&merge_oid);
462+
parent2_tree = repo_parse_tree_indirect(the_repository,
463+
&merge_oid);
461464
if (!parent2_tree)
462465
die(_("unable to read tree (%s)"), oid_to_hex(&merge_oid));
463466

builtin/merge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,19 +756,19 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
756756
opts.trivial_merges_only = 1;
757757
opts.merge = 1;
758758
opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
759-
trees[nr_trees] = parse_tree_indirect(common);
759+
trees[nr_trees] = repo_parse_tree_indirect(the_repository, common);
760760
if (!trees[nr_trees++])
761761
return -1;
762-
trees[nr_trees] = parse_tree_indirect(head);
762+
trees[nr_trees] = repo_parse_tree_indirect(the_repository, head);
763763
if (!trees[nr_trees++])
764764
return -1;
765-
trees[nr_trees] = parse_tree_indirect(one);
765+
trees[nr_trees] = repo_parse_tree_indirect(the_repository, one);
766766
if (!trees[nr_trees++])
767767
return -1;
768768
opts.fn = threeway_merge;
769769
cache_tree_free(&the_repository->index->cache_tree);
770770
for (i = 0; i < nr_trees; i++) {
771-
parse_tree(trees[i]);
771+
repo_parse_tree(the_repository, trees[i]);
772772
init_tree_desc(t+i, &trees[i]->object.oid,
773773
trees[i]->buffer, trees[i]->size);
774774
}

builtin/read-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int list_tree(struct object_id *oid)
3232

3333
if (nr_trees >= MAX_UNPACK_TREES)
3434
die("I cannot read more than %d trees", MAX_UNPACK_TREES);
35-
tree = parse_tree_indirect(oid);
35+
tree = repo_parse_tree_indirect(the_repository, oid);
3636
if (!tree)
3737
return -1;
3838
trees[nr_trees++] = tree;
@@ -268,7 +268,7 @@ int cmd_read_tree(int argc,
268268
cache_tree_free(&the_repository->index->cache_tree);
269269
for (i = 0; i < nr_trees; i++) {
270270
struct tree *tree = trees[i];
271-
if (parse_tree(tree) < 0)
271+
if (repo_parse_tree(the_repository, tree) < 0)
272272
return 128;
273273
init_tree_desc(t+i, &tree->object.oid, tree->buffer, tree->size);
274274
}

0 commit comments

Comments
 (0)