Skip to content

Commit a9dbc17

Browse files
bk2204gitster
authored andcommitted
tree: convert parse_tree_indirect to struct object_id
Convert parse_tree_indirect to take a pointer to struct object_id. Update all the callers. This transformation was achieved using the following semantic patch and manual updates to the declaration and definition. Update builtin/checkout.c manually as well, since it uses a ternary expression not handled by the semantic patch. @@ expression E1; @@ - parse_tree_indirect(E1.hash) + parse_tree_indirect(&E1) @@ expression E1; @@ - parse_tree_indirect(E1->hash) + parse_tree_indirect(E1) Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48be4c6 commit a9dbc17

16 files changed

+28
-28
lines changed

archive.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static void parse_treeish_arg(const char **argv,
369369
archive_time = time(NULL);
370370
}
371371

372-
tree = parse_tree_indirect(oid.hash);
372+
tree = parse_tree_indirect(&oid);
373373
if (tree == NULL)
374374
die("not a tree object");
375375

@@ -383,7 +383,7 @@ static void parse_treeish_arg(const char **argv,
383383
if (err || !S_ISDIR(mode))
384384
die("current working directory is untracked");
385385

386-
tree = parse_tree_indirect(tree_oid.hash);
386+
tree = parse_tree_indirect(&tree_oid);
387387
}
388388
ar_args->tree = tree;
389389
ar_args->commit_sha1 = commit_sha1;

builtin/am.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2045,11 +2045,11 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20452045
struct tree *head_tree, *remote_tree, *index_tree;
20462046
struct object_id index;
20472047

2048-
head_tree = parse_tree_indirect(head->hash);
2048+
head_tree = parse_tree_indirect(head);
20492049
if (!head_tree)
20502050
return error(_("Could not parse object '%s'."), oid_to_hex(head));
20512051

2052-
remote_tree = parse_tree_indirect(remote->hash);
2052+
remote_tree = parse_tree_indirect(remote);
20532053
if (!remote_tree)
20542054
return error(_("Could not parse object '%s'."), oid_to_hex(remote));
20552055

@@ -2061,7 +2061,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20612061
if (write_cache_as_tree(index.hash, 0, NULL))
20622062
return -1;
20632063

2064-
index_tree = parse_tree_indirect(index.hash);
2064+
index_tree = parse_tree_indirect(&index);
20652065
if (!index_tree)
20662066
return error(_("Could not parse object '%s'."), oid_to_hex(&index));
20672067

builtin/checkout.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
527527
setup_standard_excludes(topts.dir);
528528
}
529529
tree = parse_tree_indirect(old->commit ?
530-
old->commit->object.oid.hash :
531-
EMPTY_TREE_SHA1_BIN);
530+
&old->commit->object.oid :
531+
&empty_tree_oid);
532532
init_tree_desc(&trees[0], tree->buffer, tree->size);
533-
tree = parse_tree_indirect(new->commit->object.oid.hash);
533+
tree = parse_tree_indirect(&new->commit->object.oid);
534534
init_tree_desc(&trees[1], tree->buffer, tree->size);
535535

536536
ret = unpack_trees(2, trees, &topts);
@@ -1050,7 +1050,7 @@ static int parse_branchname_arg(int argc, const char **argv,
10501050
new->commit = lookup_commit_reference_gently(rev, 1);
10511051
if (!new->commit) {
10521052
/* not a commit */
1053-
*source_tree = parse_tree_indirect(rev->hash);
1053+
*source_tree = parse_tree_indirect(rev);
10541054
} else {
10551055
parse_commit_or_die(new->commit);
10561056
*source_tree = new->commit->tree;

builtin/clone.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ static int checkout(int submodule_progress)
739739
opts.src_index = &the_index;
740740
opts.dst_index = &the_index;
741741

742-
tree = parse_tree_indirect(oid.hash);
742+
tree = parse_tree_indirect(&oid);
743743
parse_tree(tree);
744744
init_tree_desc(&t, tree->buffer, tree->size);
745745
if (unpack_trees(1, &t, &opts) < 0)

builtin/commit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static void create_base_index(const struct commit *current_head)
313313
opts.dst_index = &the_index;
314314

315315
opts.fn = oneway_merge;
316-
tree = parse_tree_indirect(current_head->object.oid.hash);
316+
tree = parse_tree_indirect(&current_head->object.oid);
317317
if (!tree)
318318
die(_("failed to unpack HEAD tree object"));
319319
parse_tree(tree);

builtin/ls-files.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
421421

422422
if (get_oid(tree_name, &oid))
423423
die("tree-ish %s not found.", tree_name);
424-
tree = parse_tree_indirect(oid.hash);
424+
tree = parse_tree_indirect(&oid);
425425
if (!tree)
426426
die("bad tree-ish %s", tree_name);
427427

builtin/ls-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
180180
for (i = 0; i < pathspec.nr; i++)
181181
pathspec.items[i].nowildcard_len = pathspec.items[i].len;
182182
pathspec.has_wildcard = 0;
183-
tree = parse_tree_indirect(oid.hash);
183+
tree = parse_tree_indirect(&oid);
184184
if (!tree)
185185
die("not a tree object");
186186
return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);

builtin/merge.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,13 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
605605
opts.verbose_update = 1;
606606
opts.trivial_merges_only = 1;
607607
opts.merge = 1;
608-
trees[nr_trees] = parse_tree_indirect(common->hash);
608+
trees[nr_trees] = parse_tree_indirect(common);
609609
if (!trees[nr_trees++])
610610
return -1;
611-
trees[nr_trees] = parse_tree_indirect(head->hash);
611+
trees[nr_trees] = parse_tree_indirect(head);
612612
if (!trees[nr_trees++])
613613
return -1;
614-
trees[nr_trees] = parse_tree_indirect(one->hash);
614+
trees[nr_trees] = parse_tree_indirect(one);
615615
if (!trees[nr_trees++])
616616
return -1;
617617
opts.fn = threeway_merge;

builtin/read-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static int list_tree(struct object_id *oid)
2929

3030
if (nr_trees >= MAX_UNPACK_TREES)
3131
die("I cannot read more than %d trees", MAX_UNPACK_TREES);
32-
tree = parse_tree_indirect(oid->hash);
32+
tree = parse_tree_indirect(oid);
3333
if (!tree)
3434
return -1;
3535
trees[nr_trees++] = tree;

builtin/reset.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
8484
return -1;
8585

8686
if (reset_type == MIXED || reset_type == HARD) {
87-
tree = parse_tree_indirect(oid->hash);
87+
tree = parse_tree_indirect(oid);
8888
prime_cache_tree(&the_index, tree);
8989
}
9090

@@ -311,7 +311,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
311311
struct tree *tree;
312312
if (get_sha1_treeish(rev, oid.hash))
313313
die(_("Failed to resolve '%s' as a valid tree."), rev);
314-
tree = parse_tree_indirect(oid.hash);
314+
tree = parse_tree_indirect(&oid);
315315
if (!tree)
316316
die(_("Could not parse object '%s'."), rev);
317317
oidcpy(&oid, &tree->object.oid);

diff-lib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static int diff_cache(struct rev_info *revs,
486486
struct tree_desc t;
487487
struct unpack_trees_options opts;
488488

489-
tree = parse_tree_indirect(tree_oid->hash);
489+
tree = parse_tree_indirect(tree_oid);
490490
if (!tree)
491491
return error("bad tree object %s",
492492
tree_name ? tree_name : oid_to_hex(tree_oid));

merge.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ int checkout_fast_forward(const struct object_id *head,
7979
opts.fn = twoway_merge;
8080
setup_unpack_trees_porcelain(&opts, "merge");
8181

82-
trees[nr_trees] = parse_tree_indirect(head->hash);
82+
trees[nr_trees] = parse_tree_indirect(head);
8383
if (!trees[nr_trees++])
8484
return -1;
85-
trees[nr_trees] = parse_tree_indirect(remote->hash);
85+
trees[nr_trees] = parse_tree_indirect(remote);
8686
if (!trees[nr_trees++])
8787
return -1;
8888
for (i = 0; i < nr_trees; i++) {

sequencer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
446446
if (is_rebase_i(opts))
447447
o.buffer_output = 2;
448448

449-
head_tree = parse_tree_indirect(head->hash);
449+
head_tree = parse_tree_indirect(head);
450450
next_tree = next ? next->tree : empty_tree();
451451
base_tree = base ? base->tree : empty_tree();
452452

t/helper/test-match-trees.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ int cmd_main(int ac, const char **av)
1212
die("cannot parse %s as an object name", av[1]);
1313
if (get_oid(av[2], &hash2))
1414
die("cannot parse %s as an object name", av[2]);
15-
one = parse_tree_indirect(hash1.hash);
15+
one = parse_tree_indirect(&hash1);
1616
if (!one)
1717
die("not a tree-ish %s", av[1]);
18-
two = parse_tree_indirect(hash2.hash);
18+
two = parse_tree_indirect(&hash2);
1919
if (!two)
2020
die("not a tree-ish %s", av[2]);
2121

tree.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ void free_tree_buffer(struct tree *tree)
232232
tree->object.parsed = 0;
233233
}
234234

235-
struct tree *parse_tree_indirect(const unsigned char *sha1)
235+
struct tree *parse_tree_indirect(const struct object_id *oid)
236236
{
237-
struct object *obj = parse_object(sha1);
237+
struct object *obj = parse_object(oid->hash);
238238
do {
239239
if (!obj)
240240
return NULL;

tree.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static inline int parse_tree(struct tree *tree)
2424
void free_tree_buffer(struct tree *tree);
2525

2626
/* Parses and returns the tree in the given ent, chasing tags and commits. */
27-
struct tree *parse_tree_indirect(const unsigned char *sha1);
27+
struct tree *parse_tree_indirect(const struct object_id *oid);
2828

2929
#define READ_TREE_RECURSIVE 1
3030
typedef int (*read_tree_fn_t)(const unsigned char *, struct strbuf *, const char *, unsigned int, int, void *);

0 commit comments

Comments
 (0)