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>
René Scharfe committed
Jan 9, 2026 at 22:30 UTC
ec7a16b14551fed736ecfe0a9d4f6d6f9e03be79
27 files changed
+73
-56
archive.c
+1
-1
@@ -519,7 +519,7 @@ static void parse_treeish_arg(const char **argv,
519
if (ar_args->mtime_option)
520
archive_time = approxidate(ar_args->mtime_option);
521
522
- tree = parse_tree_indirect(&oid);
522
+ tree = repo_parse_tree_indirect(the_repository, &oid);
523
if (!tree)
524
die(_("not a tree object: %s"), oid_to_hex(&oid));
525
builtin/am.c
+5
-5
@@ -1998,7 +1998,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
1998
struct unpack_trees_options opts;
1999
struct tree_desc t[2];
2000
2001
- if (parse_tree(head) || parse_tree(remote))
2001
+ if (repo_parse_tree(the_repository, head) || repo_parse_tree(the_repository, remote))
2002
return -1;
2003
2004
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
@@ -2038,7 +2038,7 @@ static int merge_tree(struct tree *tree)
2038
struct unpack_trees_options opts;
2039
struct tree_desc t[1];
2040
2041
- if (parse_tree(tree))
2041
+ if (repo_parse_tree(the_repository, tree))
2042
return -1;
2043
2044
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
2071
struct tree *head_tree, *remote_tree, *index_tree;
2072
struct object_id index;
2073
2074
- head_tree = parse_tree_indirect(head);
2074
+ head_tree = repo_parse_tree_indirect(the_repository, head);
2075
if (!head_tree)
2076
return error(_("Could not parse object '%s'."), oid_to_hex(head));
2077
2078
- remote_tree = parse_tree_indirect(remote);
2078
+ remote_tree = repo_parse_tree_indirect(the_repository, remote);
2079
if (!remote_tree)
2080
return error(_("Could not parse object '%s'."), oid_to_hex(remote));
2081
@@ -2089,7 +2089,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
2089
0, NULL))
2090
return -1;
2091
2092
- index_tree = parse_tree_indirect(&index);
2092
+ index_tree = repo_parse_tree_indirect(the_repository, &index);
2093
if (!index_tree)
2094
return error(_("Could not parse object '%s'."), oid_to_hex(&index));
2095
builtin/checkout.c
+7
-5
@@ -724,7 +724,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
724
init_checkout_metadata(&opts.meta, info->refname,
725
info->commit ? &info->commit->object.oid : null_oid(the_hash_algo),
726
NULL);
727
- if (parse_tree(tree) < 0)
727
+ if (repo_parse_tree(the_repository, tree) < 0)
728
return 128;
729
init_tree_desc(&tree_desc, &tree->object.oid, tree->buffer, tree->size);
730
switch (unpack_trees(1, &tree_desc, &opts)) {
@@ -803,7 +803,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
803
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
804
if (new_branch_info->commit)
805
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);
808
if (!new_tree)
809
BUG("unable to read empty tree");
810
} else {
@@ -841,14 +842,15 @@ static int merge_working_tree(const struct checkout_opts *opts,
842
old_commit_oid = old_branch_info->commit ?
843
&old_branch_info->commit->object.oid :
844
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);
847
if (!tree)
848
die(_("unable to parse commit %s"),
849
oid_to_hex(old_commit_oid));
850
851
init_tree_desc(&trees[0], &tree->object.oid,
852
tree->buffer, tree->size);
851
- if (parse_tree(new_tree) < 0)
853
+ if (repo_parse_tree(the_repository, new_tree) < 0)
854
die(NULL);
855
tree = new_tree;
856
init_tree_desc(&trees[1], &tree->object.oid,
@@ -1278,7 +1280,7 @@ static void setup_new_branch_info_and_source_tree(
1280
new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1);
1281
if (!new_branch_info->commit) {
1282
/* not a commit */
1281
- *source_tree = parse_tree_indirect(rev);
1283
+ *source_tree = repo_parse_tree_indirect(the_repository, rev);
1284
if (!*source_tree)
1285
die(_("unable to read tree (%s)"), oid_to_hex(rev));
1286
} else {
builtin/clone.c
+2
-2
@@ -680,10 +680,10 @@ static int checkout(int submodule_progress, int filter_submodules,
680
opts.dst_index = the_repository->index;
681
init_checkout_metadata(&opts.meta, head, &oid, NULL);
682
683
- tree = parse_tree_indirect(&oid);
683
+ tree = repo_parse_tree_indirect(the_repository, &oid);
684
if (!tree)
685
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)
687
exit(128);
688
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
689
if (unpack_trees(1, &t, &opts) < 0)
builtin/commit.c
+3
-2
@@ -327,10 +327,11 @@ static void create_base_index(const struct commit *current_head)
327
opts.dst_index = the_repository->index;
328
329
opts.fn = oneway_merge;
330
- tree = parse_tree_indirect(¤t_head->object.oid);
330
+ tree = repo_parse_tree_indirect(the_repository,
331
+ ¤t_head->object.oid);
332
if (!tree)
333
die(_("failed to unpack HEAD tree object"));
333
- if (parse_tree(tree) < 0)
334
+ if (repo_parse_tree(the_repository, tree) < 0)
335
exit(128);
336
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
337
if (unpack_trees(1, &t, &opts))
builtin/diff-tree.c
+1
-1
@@ -52,7 +52,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
52
if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
53
return error("Need exactly two trees, separated by a space");
54
tree2 = lookup_tree(the_repository, &oid);
55
- if (!tree2 || parse_tree(tree2))
55
+ if (!tree2 || repo_parse_tree(the_repository, tree2))
56
return -1;
57
printf("%s %s\n", oid_to_hex(&tree1->object.oid),
58
oid_to_hex(&tree2->object.oid));
builtin/ls-tree.c
+1
-1
@@ -421,7 +421,7 @@ int cmd_ls_tree(int argc,
421
for (i = 0; i < options.pathspec.nr; i++)
422
options.pathspec.items[i].nowildcard_len = options.pathspec.items[i].len;
423
options.pathspec.has_wildcard = 0;
424
- tree = parse_tree_indirect(&oid);
424
+ tree = repo_parse_tree_indirect(the_repository, &oid);
425
if (!tree)
426
die("not a tree object");
427
/*
builtin/merge-tree.c
+6
-3
@@ -447,17 +447,20 @@ static int real_merge(struct merge_tree_options *o,
447
448
if (repo_get_oid_treeish(the_repository, merge_base, &base_oid))
449
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);
452
if (!base_tree)
453
die(_("unable to read tree (%s)"), oid_to_hex(&base_oid));
454
if (repo_get_oid_treeish(the_repository, branch1, &head_oid))
455
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);
458
if (!parent1_tree)
459
die(_("unable to read tree (%s)"), oid_to_hex(&head_oid));
460
if (repo_get_oid_treeish(the_repository, branch2, &merge_oid))
461
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);
464
if (!parent2_tree)
465
die(_("unable to read tree (%s)"), oid_to_hex(&merge_oid));
466
builtin/merge.c
+4
-4
@@ -756,19 +756,19 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
756
opts.trivial_merges_only = 1;
757
opts.merge = 1;
758
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);
760
if (!trees[nr_trees++])
761
return -1;
762
- trees[nr_trees] = parse_tree_indirect(head);
762
+ trees[nr_trees] = repo_parse_tree_indirect(the_repository, head);
763
if (!trees[nr_trees++])
764
return -1;
765
- trees[nr_trees] = parse_tree_indirect(one);
765
+ trees[nr_trees] = repo_parse_tree_indirect(the_repository, one);
766
if (!trees[nr_trees++])
767
return -1;
768
opts.fn = threeway_merge;
769
cache_tree_free(&the_repository->index->cache_tree);
770
for (i = 0; i < nr_trees; i++) {
771
- parse_tree(trees[i]);
771
+ repo_parse_tree(the_repository, trees[i]);
772
init_tree_desc(t+i, &trees[i]->object.oid,
773
trees[i]->buffer, trees[i]->size);
774
}
builtin/read-tree.c
+2
-2
@@ -32,7 +32,7 @@ static int list_tree(struct object_id *oid)
32
33
if (nr_trees >= MAX_UNPACK_TREES)
34
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);
36
if (!tree)
37
return -1;
38
trees[nr_trees++] = tree;
@@ -268,7 +268,7 @@ int cmd_read_tree(int argc,
268
cache_tree_free(&the_repository->index->cache_tree);
269
for (i = 0; i < nr_trees; i++) {
270
struct tree *tree = trees[i];
271
- if (parse_tree(tree) < 0)
271
+ if (repo_parse_tree(the_repository, tree) < 0)
272
return 128;
273
init_tree_desc(t+i, &tree->object.oid, tree->buffer, tree->size);
274
}
builtin/reset.c
+2
-2
@@ -118,7 +118,7 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
118
goto out;
119
120
if (reset_type == MIXED || reset_type == HARD) {
121
- tree = parse_tree_indirect(oid);
121
+ tree = repo_parse_tree_indirect(the_repository, oid);
122
if (!tree) {
123
error(_("unable to read tree (%s)"), oid_to_hex(oid));
124
goto out;
@@ -417,7 +417,7 @@ int cmd_reset(int argc,
417
struct tree *tree;
418
if (repo_get_oid_treeish(the_repository, rev, &oid))
419
die(_("Failed to resolve '%s' as a valid tree."), rev);
420
- tree = parse_tree_indirect(&oid);
420
+ tree = repo_parse_tree_indirect(the_repository, &oid);
421
if (!tree)
422
die(_("Could not parse object '%s'."), rev);
423
oidcpy(&oid, &tree->object.oid);
builtin/stash.c
+4
-4
@@ -347,8 +347,8 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
347
348
memset(&opts, 0, sizeof(opts));
349
350
- tree = parse_tree_indirect(i_tree);
351
- if (parse_tree(tree))
350
+ tree = repo_parse_tree_indirect(the_repository, i_tree);
351
+ if (repo_parse_tree(the_repository, tree))
352
return -1;
353
354
init_tree_desc(t, &tree->object.oid, tree->buffer, tree->size);
@@ -940,8 +940,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op
940
struct unpack_trees_options unpack_tree_opt = { 0 };
941
942
for (size_t i = 0; i < ARRAY_SIZE(oid); i++) {
943
- tree[i] = parse_tree_indirect(oid[i]);
944
- if (parse_tree(tree[i]) < 0)
943
+ tree[i] = repo_parse_tree_indirect(the_repository, oid[i]);
944
+ if (repo_parse_tree(the_repository, tree[i]) < 0)
945
die(_("failed to parse tree"));
946
init_tree_desc(&tree_desc[i], &tree[i]->object.oid,
947
tree[i]->buffer, tree[i]->size);
cache-tree.c
+1
-1
@@ -813,7 +813,7 @@ static void prime_cache_tree_rec(struct repository *r,
813
struct cache_tree_sub *sub;
814
struct tree *subtree = lookup_tree(r, &entry.oid);
815
816
- if (parse_tree(subtree) < 0)
816
+ if (repo_parse_tree(the_repository, subtree) < 0)
817
exit(128);
818
sub = cache_tree_sub(it, entry.path);
819
sub->cache_tree = cache_tree();
contrib/coccinelle/the_repository.cocci
+10
@@ -117,6 +117,16 @@
117
|
118
- init_revisions
119
+ repo_init_revisions
120
+// tree.h
121
+|
122
+- parse_tree
123
++ repo_parse_tree
124
+|
125
+- parse_tree_gently
126
++ repo_parse_tree_gently
127
+|
128
+- parse_tree_indirect
129
++ repo_parse_tree_indirect
130
)
131
(
132
+ the_repository,
diff-lib.c
+1
-1
@@ -552,7 +552,7 @@ static int diff_cache(struct rev_info *revs,
552
struct tree_desc t;
553
struct unpack_trees_options opts;
554
555
- tree = parse_tree_indirect(tree_oid);
555
+ tree = repo_parse_tree_indirect(the_repository, tree_oid);
556
if (!tree)
557
return error("bad tree object %s",
558
tree_name ? tree_name : oid_to_hex(tree_oid));
fsck.c
+1
-1
@@ -360,7 +360,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
360
int res = 0;
361
const char *name;
362
363
- if (parse_tree(tree))
363
+ if (repo_parse_tree(the_repository, tree))
364
return -1;
365
366
name = fsck_get_object_name(options, &tree->object.oid);
http-push.c
+1
-1
@@ -1311,7 +1311,7 @@ static struct object_list **process_tree(struct tree *tree,
1311
1312
if (obj->flags & (UNINTERESTING | SEEN))
1313
return p;
1314
- if (parse_tree(tree) < 0)
1314
+ if (repo_parse_tree(the_repository, tree) < 0)
1315
die("bad tree object %s", oid_to_hex(&obj->oid));
1316
1317
obj->flags |= SEEN;
list-objects.c
+1
-1
@@ -170,7 +170,7 @@ static void process_tree(struct traversal_context *ctx,
170
if (ctx->depth > revs->repo->settings.max_allowed_tree_depth)
171
die("exceeded maximum allowed tree depth");
172
173
- failed_parse = parse_tree_gently(tree, 1);
173
+ failed_parse = repo_parse_tree_gently(the_repository, tree, 1);
174
if (failed_parse) {
175
if (revs->ignore_missing_links)
176
return;
merge-ort.c
+7
-6
@@ -1732,9 +1732,9 @@ static int collect_merge_info(struct merge_options *opt,
1732
info.data = opt;
1733
info.show_all_errors = 1;
1734
1735
- if (parse_tree(merge_base) < 0 ||
1736
- parse_tree(side1) < 0 ||
1737
- parse_tree(side2) < 0)
1735
+ if (repo_parse_tree(the_repository, merge_base) < 0 ||
1736
+ repo_parse_tree(the_repository, side1) < 0 ||
1737
+ repo_parse_tree(the_repository, side2) < 0)
1738
return -1;
1739
init_tree_desc(t + 0, &merge_base->object.oid,
1740
merge_base->buffer, merge_base->size);
@@ -4619,10 +4619,10 @@ static int checkout(struct merge_options *opt,
4619
unpack_opts.verbose_update = (opt->verbosity > 2);
4620
unpack_opts.fn = twoway_merge;
4621
unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */
4622
- if (parse_tree(prev) < 0)
4622
+ if (repo_parse_tree(the_repository, prev) < 0)
4623
return -1;
4624
init_tree_desc(&trees[0], &prev->object.oid, prev->buffer, prev->size);
4625
- if (parse_tree(next) < 0)
4625
+ if (repo_parse_tree(the_repository, next) < 0)
4626
return -1;
4627
init_tree_desc(&trees[1], &next->object.oid, next->buffer, next->size);
4628
@@ -5280,7 +5280,8 @@ redo:
5280
5281
if (result->clean >= 0) {
5282
if (!opt->mergeability_only) {
5283
- result->tree = parse_tree_indirect(&working_tree_oid);
5283
+ result->tree = repo_parse_tree_indirect(the_repository,
5284
+ &working_tree_oid);
5285
if (!result->tree)
5286
die(_("unable to read tree (%s)"),
5287
oid_to_hex(&working_tree_oid));
merge.c
+3
-3
@@ -68,18 +68,18 @@ int checkout_fast_forward(struct repository *r,
68
memset(&trees, 0, sizeof(trees));
69
memset(&t, 0, sizeof(t));
70
71
- trees[nr_trees] = parse_tree_indirect(head);
71
+ trees[nr_trees] = repo_parse_tree_indirect(the_repository, head);
72
if (!trees[nr_trees++]) {
73
rollback_lock_file(&lock_file);
74
return -1;
75
}
76
- trees[nr_trees] = parse_tree_indirect(remote);
76
+ trees[nr_trees] = repo_parse_tree_indirect(the_repository, remote);
77
if (!trees[nr_trees++]) {
78
rollback_lock_file(&lock_file);
79
return -1;
80
}
81
for (i = 0; i < nr_trees; i++) {
82
- if (parse_tree(trees[i]) < 0) {
82
+ if (repo_parse_tree(the_repository, trees[i]) < 0) {
83
rollback_lock_file(&lock_file);
84
return -1;
85
}
read-cache.c
+1
-1
@@ -3807,7 +3807,7 @@ void overlay_tree_on_index(struct index_state *istate,
3807
3808
if (repo_get_oid(the_repository, tree_name, &oid))
3809
die("tree-ish %s not found.", tree_name);
3810
- tree = parse_tree_indirect(&oid);
3810
+ tree = repo_parse_tree_indirect(the_repository, &oid);
3811
if (!tree)
3812
die("bad tree-ish %s", tree_name);
3813
reset.c
+1
-1
@@ -163,7 +163,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)
163
goto leave_reset_head;
164
}
165
166
- tree = parse_tree_indirect(oid);
166
+ tree = repo_parse_tree_indirect(the_repository, oid);
167
if (!tree) {
168
ret = error(_("unable to read tree (%s)"), oid_to_hex(oid));
169
goto leave_reset_head;
revision.c
+2
-2
@@ -72,7 +72,7 @@ static void mark_tree_contents_uninteresting(struct repository *r,
72
struct tree_desc desc;
73
struct name_entry entry;
74
75
- if (parse_tree_gently(tree, 1) < 0)
75
+ if (repo_parse_tree_gently(the_repository, tree, 1) < 0)
76
return;
77
78
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
@@ -179,7 +179,7 @@ static void add_children_by_path(struct repository *r,
179
if (!tree)
180
return;
181
182
- if (parse_tree_gently(tree, 1) < 0)
182
+ if (repo_parse_tree_gently(the_repository, tree, 1) < 0)
183
return;
184
185
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
sequencer.c
+2
-2
@@ -767,7 +767,7 @@ static int do_recursive_merge(struct repository *r,
767
o.buffer_output = 2;
768
o.show_rename_progress = 1;
769
770
- head_tree = parse_tree_indirect(head);
770
+ head_tree = repo_parse_tree_indirect(the_repository, head);
771
if (!head_tree)
772
return error(_("unable to read tree (%s)"), oid_to_hex(head));
773
next_tree = next ? repo_get_commit_tree(r, next) : empty_tree(r);
@@ -4052,7 +4052,7 @@ static int do_reset(struct repository *r,
4052
goto cleanup;
4053
}
4054
4055
- tree = parse_tree_indirect(&oid);
4055
+ tree = repo_parse_tree_indirect(the_repository, &oid);
4056
if (!tree)
4057
return error(_("unable to read tree (%s)"), oid_to_hex(&oid));
4058
prime_cache_tree(r, r->index, tree);
t/helper/test-cache-tree.c
+1
-1
@@ -41,7 +41,7 @@ int cmd__cache_tree(int argc, const char **argv)
41
die(_("unable to read index file"));
42
43
oidcpy(&oid, &the_repository->index->cache_tree->oid);
44
- tree = parse_tree_indirect(&oid);
44
+ tree = repo_parse_tree_indirect(the_repository, &oid);
45
if (!tree)
46
die(_("not a tree object: %s"), oid_to_hex(&oid));
47
t/helper/test-match-trees.c
+2
-2
@@ -19,10 +19,10 @@ int cmd__match_trees(int ac UNUSED, const char **av)
19
die("cannot parse %s as an object name", av[1]);
20
if (repo_get_oid(the_repository, av[2], &hash2))
21
die("cannot parse %s as an object name", av[2]);
22
- one = parse_tree_indirect(&hash1);
22
+ one = repo_parse_tree_indirect(the_repository, &hash1);
23
if (!one)
24
die("not a tree-ish %s", av[1]);
25
- two = parse_tree_indirect(&hash2);
25
+ two = repo_parse_tree_indirect(the_repository, &hash2);
26
if (!two)
27
die("not a tree-ish %s", av[2]);
28
walker.c
+1
-1
@@ -45,7 +45,7 @@ static int process_tree(struct walker *walker, struct tree *tree)
45
struct tree_desc desc;
46
struct name_entry entry;
47
48
- if (parse_tree(tree))
48
+ if (repo_parse_tree(the_repository, tree))
49
return -1;
50
51
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);