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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 6, 2017 at 22:10 UTC
a9dbc179100b7119cb44eb5b4adcb47967f346a6
16 files changed
+28
-28
archive.c
+2
-2
@@ -369,7 +369,7 @@ static void parse_treeish_arg(const char **argv,
369
archive_time = time(NULL);
370
}
371
372
- tree = parse_tree_indirect(oid.hash);
372
+ tree = parse_tree_indirect(&oid);
373
if (tree == NULL)
374
die("not a tree object");
375
@@ -383,7 +383,7 @@ static void parse_treeish_arg(const char **argv,
383
if (err || !S_ISDIR(mode))
384
die("current working directory is untracked");
385
386
- tree = parse_tree_indirect(tree_oid.hash);
386
+ tree = parse_tree_indirect(&tree_oid);
387
}
388
ar_args->tree = tree;
389
ar_args->commit_sha1 = commit_sha1;
builtin/am.c
+3
-3
@@ -2045,11 +2045,11 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
2045
struct tree *head_tree, *remote_tree, *index_tree;
2046
struct object_id index;
2047
2048
- head_tree = parse_tree_indirect(head->hash);
2048
+ head_tree = parse_tree_indirect(head);
2049
if (!head_tree)
2050
return error(_("Could not parse object '%s'."), oid_to_hex(head));
2051
2052
- remote_tree = parse_tree_indirect(remote->hash);
2052
+ remote_tree = parse_tree_indirect(remote);
2053
if (!remote_tree)
2054
return error(_("Could not parse object '%s'."), oid_to_hex(remote));
2055
@@ -2061,7 +2061,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
2061
if (write_cache_as_tree(index.hash, 0, NULL))
2062
return -1;
2063
2064
- index_tree = parse_tree_indirect(index.hash);
2064
+ index_tree = parse_tree_indirect(&index);
2065
if (!index_tree)
2066
return error(_("Could not parse object '%s'."), oid_to_hex(&index));
2067
builtin/checkout.c
+4
-4
@@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
527
setup_standard_excludes(topts.dir);
528
}
529
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);
532
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);
534
init_tree_desc(&trees[1], tree->buffer, tree->size);
535
536
ret = unpack_trees(2, trees, &topts);
@@ -1050,7 +1050,7 @@ static int parse_branchname_arg(int argc, const char **argv,
1050
new->commit = lookup_commit_reference_gently(rev, 1);
1051
if (!new->commit) {
1052
/* not a commit */
1053
- *source_tree = parse_tree_indirect(rev->hash);
1053
+ *source_tree = parse_tree_indirect(rev);
1054
} else {
1055
parse_commit_or_die(new->commit);
1056
*source_tree = new->commit->tree;
builtin/clone.c
+1
-1
@@ -739,7 +739,7 @@ static int checkout(int submodule_progress)
739
opts.src_index = &the_index;
740
opts.dst_index = &the_index;
741
742
- tree = parse_tree_indirect(oid.hash);
742
+ tree = parse_tree_indirect(&oid);
743
parse_tree(tree);
744
init_tree_desc(&t, tree->buffer, tree->size);
745
if (unpack_trees(1, &t, &opts) < 0)
builtin/commit.c
+1
-1
@@ -313,7 +313,7 @@ static void create_base_index(const struct commit *current_head)
313
opts.dst_index = &the_index;
314
315
opts.fn = oneway_merge;
316
- tree = parse_tree_indirect(current_head->object.oid.hash);
316
+ tree = parse_tree_indirect(¤t_head->object.oid);
317
if (!tree)
318
die(_("failed to unpack HEAD tree object"));
319
parse_tree(tree);
builtin/ls-files.c
+1
-1
@@ -421,7 +421,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
421
422
if (get_oid(tree_name, &oid))
423
die("tree-ish %s not found.", tree_name);
424
- tree = parse_tree_indirect(oid.hash);
424
+ tree = parse_tree_indirect(&oid);
425
if (!tree)
426
die("bad tree-ish %s", tree_name);
427
builtin/ls-tree.c
+1
-1
@@ -180,7 +180,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
180
for (i = 0; i < pathspec.nr; i++)
181
pathspec.items[i].nowildcard_len = pathspec.items[i].len;
182
pathspec.has_wildcard = 0;
183
- tree = parse_tree_indirect(oid.hash);
183
+ tree = parse_tree_indirect(&oid);
184
if (!tree)
185
die("not a tree object");
186
return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
builtin/merge.c
+3
-3
@@ -605,13 +605,13 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
605
opts.verbose_update = 1;
606
opts.trivial_merges_only = 1;
607
opts.merge = 1;
608
- trees[nr_trees] = parse_tree_indirect(common->hash);
608
+ trees[nr_trees] = parse_tree_indirect(common);
609
if (!trees[nr_trees++])
610
return -1;
611
- trees[nr_trees] = parse_tree_indirect(head->hash);
611
+ trees[nr_trees] = parse_tree_indirect(head);
612
if (!trees[nr_trees++])
613
return -1;
614
- trees[nr_trees] = parse_tree_indirect(one->hash);
614
+ trees[nr_trees] = parse_tree_indirect(one);
615
if (!trees[nr_trees++])
616
return -1;
617
opts.fn = threeway_merge;
builtin/read-tree.c
+1
-1
@@ -29,7 +29,7 @@ static int list_tree(struct object_id *oid)
29
30
if (nr_trees >= MAX_UNPACK_TREES)
31
die("I cannot read more than %d trees", MAX_UNPACK_TREES);
32
- tree = parse_tree_indirect(oid->hash);
32
+ tree = parse_tree_indirect(oid);
33
if (!tree)
34
return -1;
35
trees[nr_trees++] = tree;
builtin/reset.c
+2
-2
@@ -84,7 +84,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
84
return -1;
85
86
if (reset_type == MIXED || reset_type == HARD) {
87
- tree = parse_tree_indirect(oid->hash);
87
+ tree = parse_tree_indirect(oid);
88
prime_cache_tree(&the_index, tree);
89
}
90
@@ -311,7 +311,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
311
struct tree *tree;
312
if (get_sha1_treeish(rev, oid.hash))
313
die(_("Failed to resolve '%s' as a valid tree."), rev);
314
- tree = parse_tree_indirect(oid.hash);
314
+ tree = parse_tree_indirect(&oid);
315
if (!tree)
316
die(_("Could not parse object '%s'."), rev);
317
oidcpy(&oid, &tree->object.oid);
diff-lib.c
+1
-1
@@ -486,7 +486,7 @@ static int diff_cache(struct rev_info *revs,
486
struct tree_desc t;
487
struct unpack_trees_options opts;
488
489
- tree = parse_tree_indirect(tree_oid->hash);
489
+ tree = parse_tree_indirect(tree_oid);
490
if (!tree)
491
return error("bad tree object %s",
492
tree_name ? tree_name : oid_to_hex(tree_oid));
merge.c
+2
-2
@@ -79,10 +79,10 @@ int checkout_fast_forward(const struct object_id *head,
79
opts.fn = twoway_merge;
80
setup_unpack_trees_porcelain(&opts, "merge");
81
82
- trees[nr_trees] = parse_tree_indirect(head->hash);
82
+ trees[nr_trees] = parse_tree_indirect(head);
83
if (!trees[nr_trees++])
84
return -1;
85
- trees[nr_trees] = parse_tree_indirect(remote->hash);
85
+ trees[nr_trees] = parse_tree_indirect(remote);
86
if (!trees[nr_trees++])
87
return -1;
88
for (i = 0; i < nr_trees; i++) {
sequencer.c
+1
-1
@@ -446,7 +446,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
446
if (is_rebase_i(opts))
447
o.buffer_output = 2;
448
449
- head_tree = parse_tree_indirect(head->hash);
449
+ head_tree = parse_tree_indirect(head);
450
next_tree = next ? next->tree : empty_tree();
451
base_tree = base ? base->tree : empty_tree();
452
t/helper/test-match-trees.c
+2
-2
@@ -12,10 +12,10 @@ int cmd_main(int ac, const char **av)
12
die("cannot parse %s as an object name", av[1]);
13
if (get_oid(av[2], &hash2))
14
die("cannot parse %s as an object name", av[2]);
15
- one = parse_tree_indirect(hash1.hash);
15
+ one = parse_tree_indirect(&hash1);
16
if (!one)
17
die("not a tree-ish %s", av[1]);
18
- two = parse_tree_indirect(hash2.hash);
18
+ two = parse_tree_indirect(&hash2);
19
if (!two)
20
die("not a tree-ish %s", av[2]);
21
tree.c
+2
-2
@@ -232,9 +232,9 @@ void free_tree_buffer(struct tree *tree)
232
tree->object.parsed = 0;
233
}
234
235
-struct tree *parse_tree_indirect(const unsigned char *sha1)
235
+struct tree *parse_tree_indirect(const struct object_id *oid)
236
{
237
- struct object *obj = parse_object(sha1);
237
+ struct object *obj = parse_object(oid->hash);
238
do {
239
if (!obj)
240
return NULL;
tree.h
+1
-1
@@ -24,7 +24,7 @@ static inline int parse_tree(struct tree *tree)
24
void free_tree_buffer(struct tree *tree);
25
26
/* 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);
28
29
#define READ_TREE_RECURSIVE 1
30
typedef int (*read_tree_fn_t)(const unsigned char *, struct strbuf *, const char *, unsigned int, int, void *);