]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Convert lookup_tree to struct object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sat, 6 May 2017 22:10:17 +0000 (22:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 06:12:57 +0000 (15:12 +0900)
Convert the lookup_tree function to take a pointer to struct object_id.

The commit was created with manual changes to tree.c, tree.h, and
object.c, plus the following semantic patch:

@@
@@
- lookup_tree(EMPTY_TREE_SHA1_BIN)
+ lookup_tree(&empty_tree_oid)

@@
expression E1;
@@
- lookup_tree(E1.hash)
+ lookup_tree(&E1)

@@
expression E1;
@@
- lookup_tree(E1->hash)
+ lookup_tree(E1)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 files changed:
builtin/am.c
builtin/diff-tree.c
builtin/diff.c
builtin/reflog.c
cache-tree.c
commit.c
fsck.c
http-push.c
list-objects.c
merge-recursive.c
object.c
reachable.c
revision.c
sequencer.c
tag.c
tree.c
tree.h
walker.c

index 650269ac5e0b17a4c2e50470e5d32db55e23de01..7663f12e64e7adacb4fc437438946bdb5cb1fd92 100644 (file)
@@ -1453,9 +1453,9 @@ static void write_index_patch(const struct am_state *state)
        FILE *fp;
 
        if (!get_sha1_tree("HEAD", head.hash))
-               tree = lookup_tree(head.hash);
+               tree = lookup_tree(&head);
        else
-               tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+               tree = lookup_tree(&empty_tree_oid);
 
        fp = xfopen(am_path(state, "patch"), "w");
        init_revisions(&rev_info, NULL);
index e85a449df1305a4c29b398e35b42cc7fd8367830..95b8d1ba7cfe1edd6ed6bfe0047fc9256c8bb60f 100644 (file)
@@ -44,7 +44,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
        struct tree *tree2;
        if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
                return error("Need exactly two trees, separated by a space");
-       tree2 = lookup_tree(oid.hash);
+       tree2 = lookup_tree(&oid);
        if (!tree2 || parse_tree(tree2))
                return -1;
        printf("%s %s\n", oid_to_hex(&tree1->object.oid),
index a25b4e4ae689ab10f8fd8b37d39f10f84549eb51..895f92897829f35cae26ab3e7eb7cfb9ac7884e6 100644 (file)
@@ -381,7 +381,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                                add_head_to_pending(&rev);
                                if (!rev.pending.nr) {
                                        struct tree *tree;
-                                       tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+                                       tree = lookup_tree(&empty_tree_oid);
                                        add_pending_object(&rev, &tree->object, "HEAD");
                                }
                                break;
index 7866a034123258611977055a8d39cf5066c32712..7e89e84dce04775dbf9809b6e43c4c06607e9d4e 100644 (file)
@@ -62,7 +62,7 @@ static int tree_is_complete(const struct object_id *oid)
        int complete;
        struct tree *tree;
 
-       tree = lookup_tree(oid->hash);
+       tree = lookup_tree(oid);
        if (!tree)
                return 0;
        if (tree->object.flags & SEEN)
index 35d507ed79641f114e6af9e39466c26c744f022c..48924102123b019f3f6d69f7f07047a3d4a68d50 100644 (file)
@@ -672,7 +672,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
                        cnt++;
                else {
                        struct cache_tree_sub *sub;
-                       struct tree *subtree = lookup_tree(entry.oid->hash);
+                       struct tree *subtree = lookup_tree(entry.oid);
                        if (!subtree->object.parsed)
                                parse_tree(subtree);
                        sub = cache_tree_sub(it, entry.path);
index 0f6c9b6bf3ad275edcce2690579c5d480df64e13..8004008bc395c649940faec327e5e34b4c39b34d 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -331,7 +331,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
        if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
                return error("bad tree pointer in commit %s",
                             oid_to_hex(&item->object.oid));
-       item->tree = lookup_tree(parent.hash);
+       item->tree = lookup_tree(&parent);
        bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
        pptr = &item->parents;
 
diff --git a/fsck.c b/fsck.c
index ab3016c0e1f96f00a17a5b8dfe1fec1956ac5ff3..ee5224aea97e0b1dede40bc527abda08e474c909 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -358,7 +358,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
                        continue;
 
                if (S_ISDIR(entry.mode)) {
-                       obj = &lookup_tree(entry.oid->hash)->object;
+                       obj = &lookup_tree(entry.oid)->object;
                        if (name)
                                put_object_name(options, obj, "%s%s/", name,
                                        entry.path);
index 9bb5e06482b2dd59411d9f70b49cc4ab72a49c6f..7781f4078818133903b7a0caf8aefc1f883a8e54 100644 (file)
@@ -1312,7 +1312,7 @@ static struct object_list **process_tree(struct tree *tree,
        while (tree_entry(&desc, &entry))
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       p = process_tree(lookup_tree(entry.oid->hash), p);
+                       p = process_tree(lookup_tree(entry.oid), p);
                        break;
                case OBJ_BLOB:
                        p = process_blob(lookup_blob(entry.oid), p);
index 721e5fb08b7f9695aeaac33649d3e5d98ddb676d..b3931fa434dc99a481569697585e3bb21190c932 100644 (file)
@@ -110,7 +110,7 @@ static void process_tree(struct rev_info *revs,
 
                if (S_ISDIR(entry.mode))
                        process_tree(revs,
-                                    lookup_tree(entry.oid->hash),
+                                    lookup_tree(entry.oid),
                                     show, base, entry.path,
                                     cb_data);
                else if (S_ISGITLINK(entry.mode))
index 1315a45b9388a133228d5fe7749d4a994390f880..92e0a63dcc8a4040fbdadf1f35d679a42e6d27d1 100644 (file)
@@ -67,7 +67,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
        }
        if (!oidcmp(&two->object.oid, &shifted))
                return two;
-       return lookup_tree(shifted.hash);
+       return lookup_tree(&shifted);
 }
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -304,7 +304,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
                return NULL;
        }
 
-       result = lookup_tree(active_cache_tree->oid.hash);
+       result = lookup_tree(&active_cache_tree->oid);
 
        return result;
 }
@@ -2042,7 +2042,7 @@ int merge_recursive(struct merge_options *o,
                /* if there is no common ancestor, use an empty tree */
                struct tree *tree;
 
-               tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+               tree = lookup_tree(&empty_tree_oid);
                merged_common_ancestors = make_virtual_commit(tree, "ancestor");
        }
 
index 2c8d1e5d314702a532e799d254093d948b4ff421..d23c5fad388f01c6bda7cb7abfb183c554f3aff9 100644 (file)
--- a/object.c
+++ b/object.c
@@ -197,7 +197,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
                        obj = &blob->object;
                }
        } else if (type == OBJ_TREE) {
-               struct tree *tree = lookup_tree(sha1);
+               struct tree *tree = lookup_tree(&oid);
                if (tree) {
                        obj = &tree->object;
                        if (!tree->buffer)
index 8ea0bdd7c045002df53ad9098f88b8e55b3136c9..3bbc84417f47e5d5e872c2d1cc66f3b844a3f160 100644 (file)
@@ -85,7 +85,7 @@ static void add_recent_object(const struct object_id *oid,
                obj = parse_object_or_die(oid->hash, NULL);
                break;
        case OBJ_TREE:
-               obj = (struct object *)lookup_tree(oid->hash);
+               obj = (struct object *)lookup_tree(oid);
                break;
        case OBJ_BLOB:
                obj = (struct object *)lookup_blob(oid);
index db2de7a7a8d4a9dfcb72cc102866e6f41b06836c..c2091b6de7cd17e30779946b2631bcf42283951c 100644 (file)
@@ -59,7 +59,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
        while (tree_entry(&desc, &entry)) {
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       mark_tree_uninteresting(lookup_tree(entry.oid->hash));
+                       mark_tree_uninteresting(lookup_tree(entry.oid));
                        break;
                case OBJ_BLOB:
                        mark_blob_uninteresting(lookup_blob(entry.oid));
@@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
        int i;
 
        if (it->entry_count >= 0) {
-               struct tree *tree = lookup_tree(it->oid.hash);
+               struct tree *tree = lookup_tree(&it->oid);
                add_pending_object_with_path(revs, &tree->object, "",
                                             040000, path->buf);
        }
index 08676336026de0c82735f1bed4689f6b9673cbd6..218895fde1ba0f1059e60227f3695ee60fb589c3 100644 (file)
@@ -344,7 +344,7 @@ static int read_oneliner(struct strbuf *buf,
 
 static struct tree *empty_tree(void)
 {
-       return lookup_tree(EMPTY_TREE_SHA1_BIN);
+       return lookup_tree(&empty_tree_oid);
 }
 
 static int error_dirty_index(struct replay_opts *opts)
diff --git a/tag.c b/tag.c
index dff251673ec2b3723262a0c5676c482529c29f62..062516b405cb957767ec06fd06619546900df2d5 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -144,7 +144,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
        if (!strcmp(type, blob_type)) {
                item->tagged = &lookup_blob(&oid)->object;
        } else if (!strcmp(type, tree_type)) {
-               item->tagged = &lookup_tree(oid.hash)->object;
+               item->tagged = &lookup_tree(&oid)->object;
        } else if (!strcmp(type, commit_type)) {
                item->tagged = &lookup_commit(&oid)->object;
        } else if (!strcmp(type, tag_type)) {
diff --git a/tree.c b/tree.c
index 21fd80b801aec559cdc88d8b9e7fc88054b8a6be..28ce930b95d93d04b1b15cab05339ba7479f3860 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -110,7 +110,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
                len = tree_entry_len(&entry);
                strbuf_add(base, entry.path, len);
                strbuf_addch(base, '/');
-               retval = read_tree_1(lookup_tree(oid.hash),
+               retval = read_tree_1(lookup_tree(&oid),
                                     base, stage, pathspec,
                                     fn, context);
                strbuf_setlen(base, oldlen);
@@ -184,11 +184,11 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
        return 0;
 }
 
-struct tree *lookup_tree(const unsigned char *sha1)
+struct tree *lookup_tree(const struct object_id *oid)
 {
-       struct object *obj = lookup_object(sha1);
+       struct object *obj = lookup_object(oid->hash);
        if (!obj)
-               return create_object(sha1, alloc_tree_node());
+               return create_object(oid->hash, alloc_tree_node());
        return object_as_type(obj, OBJ_TREE, 0);
 }
 
diff --git a/tree.h b/tree.h
index d24786cba2ca91d0bffd63490b4f71ac4a58de13..2b2c8dbbe9e2d901eba2a312f6b75974ad0cdb76 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -12,7 +12,7 @@ struct tree {
        unsigned long size;
 };
 
-struct tree *lookup_tree(const unsigned char *sha1);
+struct tree *lookup_tree(const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
index 3d6029c8e226c1de37b38a379fe47d82976bd758..eae9fb974f145b2ac9477357c260044a416f8c7f 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -47,7 +47,7 @@ static int process_tree(struct walker *walker, struct tree *tree)
                if (S_ISGITLINK(entry.mode))
                        continue;
                if (S_ISDIR(entry.mode)) {
-                       struct tree *tree = lookup_tree(entry.oid->hash);
+                       struct tree *tree = lookup_tree(entry.oid);
                        if (tree)
                                obj = &tree->object;
                }