tree: convert parse_tree_indirect to struct object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sat, 6 May 2017 22:10:37 +0000 (22:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 06:12:58 +0000 (15:12 +0900)
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>
16 files changed:
archive.c
builtin/am.c
builtin/checkout.c
builtin/clone.c
builtin/commit.c
builtin/ls-files.c
builtin/ls-tree.c
builtin/merge.c
builtin/read-tree.c
builtin/reset.c
diff-lib.c
merge.c
sequencer.c
t/helper/test-match-trees.c
tree.c
tree.h
index 54701e8bb20dced0db67dd944d96f1b77ceff032..b15a922dab56a525ca3ce7f1143d215fe39f3132 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -369,7 +369,7 @@ static void parse_treeish_arg(const char **argv,
                archive_time = time(NULL);
        }
 
-       tree = parse_tree_indirect(oid.hash);
+       tree = parse_tree_indirect(&oid);
        if (tree == NULL)
                die("not a tree object");
 
@@ -383,7 +383,7 @@ static void parse_treeish_arg(const char **argv,
                if (err || !S_ISDIR(mode))
                        die("current working directory is untracked");
 
-               tree = parse_tree_indirect(tree_oid.hash);
+               tree = parse_tree_indirect(&tree_oid);
        }
        ar_args->tree = tree;
        ar_args->commit_sha1 = commit_sha1;
index 200d9dbed4644a87b2ba5ffc1d77585a4f0cd157..a2867f347b789fbca133586370d6dc8bbdf85edb 100644 (file)
@@ -2045,11 +2045,11 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
        struct tree *head_tree, *remote_tree, *index_tree;
        struct object_id index;
 
-       head_tree = parse_tree_indirect(head->hash);
+       head_tree = parse_tree_indirect(head);
        if (!head_tree)
                return error(_("Could not parse object '%s'."), oid_to_hex(head));
 
-       remote_tree = parse_tree_indirect(remote->hash);
+       remote_tree = parse_tree_indirect(remote);
        if (!remote_tree)
                return error(_("Could not parse object '%s'."), oid_to_hex(remote));
 
@@ -2061,7 +2061,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
        if (write_cache_as_tree(index.hash, 0, NULL))
                return -1;
 
-       index_tree = parse_tree_indirect(index.hash);
+       index_tree = parse_tree_indirect(&index);
        if (!index_tree)
                return error(_("Could not parse object '%s'."), oid_to_hex(&index));
 
index 7f1eeea94333021c89f4adb8106f98df1f85bbd6..13365fb621f548e5c3320d33b43ba1a64817bc16 100644 (file)
@@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
                        setup_standard_excludes(topts.dir);
                }
                tree = parse_tree_indirect(old->commit ?
-                                          old->commit->object.oid.hash :
-                                          EMPTY_TREE_SHA1_BIN);
+                                          &old->commit->object.oid :
+                                          &empty_tree_oid);
                init_tree_desc(&trees[0], tree->buffer, tree->size);
-               tree = parse_tree_indirect(new->commit->object.oid.hash);
+               tree = parse_tree_indirect(&new->commit->object.oid);
                init_tree_desc(&trees[1], tree->buffer, tree->size);
 
                ret = unpack_trees(2, trees, &topts);
@@ -1050,7 +1050,7 @@ static int parse_branchname_arg(int argc, const char **argv,
        new->commit = lookup_commit_reference_gently(rev, 1);
        if (!new->commit) {
                /* not a commit */
-               *source_tree = parse_tree_indirect(rev->hash);
+               *source_tree = parse_tree_indirect(rev);
        } else {
                parse_commit_or_die(new->commit);
                *source_tree = new->commit->tree;
index 646f2879258e5a023e83117a5d247c7c2d05aec1..da2d3c1aef0d22fbad7774ed72e09a2534e70523 100644 (file)
@@ -739,7 +739,7 @@ static int checkout(int submodule_progress)
        opts.src_index = &the_index;
        opts.dst_index = &the_index;
 
-       tree = parse_tree_indirect(oid.hash);
+       tree = parse_tree_indirect(&oid);
        parse_tree(tree);
        init_tree_desc(&t, tree->buffer, tree->size);
        if (unpack_trees(1, &t, &opts) < 0)
index e69f466d5b0e58a85faeb3b6a474b30b949816a9..6adc908b327ae6514af873426ef5ed1e589f0446 100644 (file)
@@ -313,7 +313,7 @@ static void create_base_index(const struct commit *current_head)
        opts.dst_index = &the_index;
 
        opts.fn = oneway_merge;
-       tree = parse_tree_indirect(current_head->object.oid.hash);
+       tree = parse_tree_indirect(&current_head->object.oid);
        if (!tree)
                die(_("failed to unpack HEAD tree object"));
        parse_tree(tree);
index da0ff849f02afbd273c165da65fe60b462d9e1f8..f20edabe6dd67628a4aed4d8a1bb709da00d3b5f 100644 (file)
@@ -421,7 +421,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
 
        if (get_oid(tree_name, &oid))
                die("tree-ish %s not found.", tree_name);
-       tree = parse_tree_indirect(oid.hash);
+       tree = parse_tree_indirect(&oid);
        if (!tree)
                die("bad tree-ish %s", tree_name);
 
index 5baac3ef2fa5d3d9ebabd2dd699f89e0d3115846..ee7b293b11eb5c73dd6fe1ea31c5d3bf52c79656 100644 (file)
@@ -180,7 +180,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
        for (i = 0; i < pathspec.nr; i++)
                pathspec.items[i].nowildcard_len = pathspec.items[i].len;
        pathspec.has_wildcard = 0;
-       tree = parse_tree_indirect(oid.hash);
+       tree = parse_tree_indirect(&oid);
        if (!tree)
                die("not a tree object");
        return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
index 5ea7f7da9a7436c8cfb18c839029df3855e25be7..a4a098f40f8e3e61c3f8b730a6b22a83c3c23566 100644 (file)
@@ -605,13 +605,13 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
        opts.verbose_update = 1;
        opts.trivial_merges_only = 1;
        opts.merge = 1;
-       trees[nr_trees] = parse_tree_indirect(common->hash);
+       trees[nr_trees] = parse_tree_indirect(common);
        if (!trees[nr_trees++])
                return -1;
-       trees[nr_trees] = parse_tree_indirect(head->hash);
+       trees[nr_trees] = parse_tree_indirect(head);
        if (!trees[nr_trees++])
                return -1;
-       trees[nr_trees] = parse_tree_indirect(one->hash);
+       trees[nr_trees] = parse_tree_indirect(one);
        if (!trees[nr_trees++])
                return -1;
        opts.fn = threeway_merge;
index 92eff23e45cbfdb83eb8dbab72e1471923c9a201..6d45175f6aa054ba0a1260a0a7976d471658a276 100644 (file)
@@ -29,7 +29,7 @@ static int list_tree(struct object_id *oid)
 
        if (nr_trees >= MAX_UNPACK_TREES)
                die("I cannot read more than %d trees", MAX_UNPACK_TREES);
-       tree = parse_tree_indirect(oid->hash);
+       tree = parse_tree_indirect(oid);
        if (!tree)
                return -1;
        trees[nr_trees++] = tree;
index 3415dac5d59815c7846c6631ecfe2e74e09a05a7..c782739c216004a61f5599e2b5d03e9ca2dafb61 100644 (file)
@@ -84,7 +84,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
                return -1;
 
        if (reset_type == MIXED || reset_type == HARD) {
-               tree = parse_tree_indirect(oid->hash);
+               tree = parse_tree_indirect(oid);
                prime_cache_tree(&the_index, tree);
        }
 
@@ -311,7 +311,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                struct tree *tree;
                if (get_sha1_treeish(rev, oid.hash))
                        die(_("Failed to resolve '%s' as a valid tree."), rev);
-               tree = parse_tree_indirect(oid.hash);
+               tree = parse_tree_indirect(&oid);
                if (!tree)
                        die(_("Could not parse object '%s'."), rev);
                oidcpy(&oid, &tree->object.oid);
index ee9df0f84721914506c6482f7d654c1ee01937ba..2982bf055acb6049a8cd6007244d60d985b7e619 100644 (file)
@@ -486,7 +486,7 @@ static int diff_cache(struct rev_info *revs,
        struct tree_desc t;
        struct unpack_trees_options opts;
 
-       tree = parse_tree_indirect(tree_oid->hash);
+       tree = parse_tree_indirect(tree_oid);
        if (!tree)
                return error("bad tree object %s",
                             tree_name ? tree_name : oid_to_hex(tree_oid));
diff --git a/merge.c b/merge.c
index b0cffe16fe368ee86e609d5d9fbd3b29620bba8c..1d441ad94254257ad2ac28b8a17dc0b8e5ce14f9 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -79,10 +79,10 @@ int checkout_fast_forward(const struct object_id *head,
        opts.fn = twoway_merge;
        setup_unpack_trees_porcelain(&opts, "merge");
 
-       trees[nr_trees] = parse_tree_indirect(head->hash);
+       trees[nr_trees] = parse_tree_indirect(head);
        if (!trees[nr_trees++])
                return -1;
-       trees[nr_trees] = parse_tree_indirect(remote->hash);
+       trees[nr_trees] = parse_tree_indirect(remote);
        if (!trees[nr_trees++])
                return -1;
        for (i = 0; i < nr_trees; i++) {
index adcc0a953fef533669a9c2deec4b5fbe08c5a6ac..5817d8a23d835ad8417d9a4f2d0dc57df76571f1 100644 (file)
@@ -446,7 +446,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
        if (is_rebase_i(opts))
                o.buffer_output = 2;
 
-       head_tree = parse_tree_indirect(head->hash);
+       head_tree = parse_tree_indirect(head);
        next_tree = next ? next->tree : empty_tree();
        base_tree = base ? base->tree : empty_tree();
 
index e9395028630bf26390366065aa07bc7b2827eb73..356d8edef1d25524abaae0f0fcb3bf072d229c30 100644 (file)
@@ -12,10 +12,10 @@ int cmd_main(int ac, const char **av)
                die("cannot parse %s as an object name", av[1]);
        if (get_oid(av[2], &hash2))
                die("cannot parse %s as an object name", av[2]);
-       one = parse_tree_indirect(hash1.hash);
+       one = parse_tree_indirect(&hash1);
        if (!one)
                die("not a tree-ish %s", av[1]);
-       two = parse_tree_indirect(hash2.hash);
+       two = parse_tree_indirect(&hash2);
        if (!two)
                die("not a tree-ish %s", av[2]);
 
diff --git a/tree.c b/tree.c
index 28ce930b95d93d04b1b15cab05339ba7479f3860..9adcd8bd428984e102b03f2088dd476a25eae3be 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -232,9 +232,9 @@ void free_tree_buffer(struct tree *tree)
        tree->object.parsed = 0;
 }
 
-struct tree *parse_tree_indirect(const unsigned char *sha1)
+struct tree *parse_tree_indirect(const struct object_id *oid)
 {
-       struct object *obj = parse_object(sha1);
+       struct object *obj = parse_object(oid->hash);
        do {
                if (!obj)
                        return NULL;
diff --git a/tree.h b/tree.h
index 2b2c8dbbe9e2d901eba2a312f6b75974ad0cdb76..0d4734b94b67603bc8f71a5273c3414f8785e066 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -24,7 +24,7 @@ static inline int parse_tree(struct tree *tree)
 void free_tree_buffer(struct tree *tree);
 
 /* Parses and returns the tree in the given ent, chasing tags and commits. */
-struct tree *parse_tree_indirect(const unsigned char *sha1);
+struct tree *parse_tree_indirect(const struct object_id *oid);
 
 #define READ_TREE_RECURSIVE 1
 typedef int (*read_tree_fn_t)(const unsigned char *, struct strbuf *, const char *, unsigned int, int, void *);