tree: add repository argument to lookup_tree
authorStefan Beller <sbeller@google.com>
Fri, 29 Jun 2018 01:21:56 +0000 (18:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Jun 2018 17:43:38 +0000 (10:43 -0700)
Add a repository argument to allow the callers of lookup_tree
to be more specific about which repository to act on. This is a small
mechanical change; it doesn't change the implementation to handle
repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a
repository other than the_repository at compile time.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
19 files changed:
builtin/am.c
builtin/diff-tree.c
builtin/diff.c
builtin/reflog.c
cache-tree.c
commit-graph.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 6273ea5195bb7f7f2296155753c5e7982d533d66..72e928cee7903d5d7390d07fc8be13f464eb2610 100644 (file)
@@ -32,6 +32,7 @@
 #include "apply.h"
 #include "string-list.h"
 #include "packfile.h"
 #include "apply.h"
 #include "string-list.h"
 #include "packfile.h"
+#include "repository.h"
 
 /**
  * Returns 1 if the file is empty or does not exist, 0 otherwise.
 
 /**
  * Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -1400,9 +1401,10 @@ static void write_index_patch(const struct am_state *state)
        FILE *fp;
 
        if (!get_oid_tree("HEAD", &head))
        FILE *fp;
 
        if (!get_oid_tree("HEAD", &head))
-               tree = lookup_tree(&head);
+               tree = lookup_tree(the_repository, &head);
        else
        else
-               tree = lookup_tree(the_hash_algo->empty_tree);
+               tree = lookup_tree(the_repository,
+                                  the_repository->hash_algo->empty_tree);
 
        fp = xfopen(am_path(state, "patch"), "w");
        init_revisions(&rev_info, NULL);
 
        fp = xfopen(am_path(state, "patch"), "w");
        init_revisions(&rev_info, NULL);
index d8db8f682f03ca93fd25e0d4aaff365eb0bb7b65..29901515a13491c2d2c3145998733109e531d3d4 100644 (file)
@@ -46,7 +46,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");
        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);
+       tree2 = lookup_tree(the_repository, &oid);
        if (!tree2 || parse_tree(tree2))
                return -1;
        printf("%s %s\n", oid_to_hex(&tree1->object.oid),
        if (!tree2 || parse_tree(tree2))
                return -1;
        printf("%s %s\n", oid_to_hex(&tree1->object.oid),
index d0421c90e298c4fd5bd6e75c6025aeebef8e745a..7971530b9b3034f3af326cc035978927a2c18c73 100644 (file)
@@ -386,7 +386,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                                add_head_to_pending(&rev);
                                if (!rev.pending.nr) {
                                        struct tree *tree;
                                add_head_to_pending(&rev);
                                if (!rev.pending.nr) {
                                        struct tree *tree;
-                                       tree = lookup_tree(the_hash_algo->empty_tree);
+                                       tree = lookup_tree(the_repository,
+                                                          the_repository->hash_algo->empty_tree);
                                        add_pending_object(&rev, &tree->object, "HEAD");
                                }
                                break;
                                        add_pending_object(&rev, &tree->object, "HEAD");
                                }
                                break;
index 948002b81ea61ae367f89eed2b7702347feb6005..5e12c856049e87696a15085777497234e3df5486 100644 (file)
@@ -66,7 +66,7 @@ static int tree_is_complete(const struct object_id *oid)
        int complete;
        struct tree *tree;
 
        int complete;
        struct tree *tree;
 
-       tree = lookup_tree(oid);
+       tree = lookup_tree(the_repository, oid);
        if (!tree)
                return 0;
        if (tree->object.flags & SEEN)
        if (!tree)
                return 0;
        if (tree->object.flags & SEEN)
index 6b467119960b03540e38209aa1a10f1dbe36c4dd..181d5919f0fd4d8e838684cd14adafc8fa31ab71 100644 (file)
@@ -671,7 +671,8 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
                        cnt++;
                else {
                        struct cache_tree_sub *sub;
                        cnt++;
                else {
                        struct cache_tree_sub *sub;
-                       struct tree *subtree = lookup_tree(entry.oid);
+                       struct tree *subtree = lookup_tree(the_repository,
+                                                          entry.oid);
                        if (!subtree->object.parsed)
                                parse_tree(subtree);
                        sub = cache_tree_sub(it, entry.path);
                        if (!subtree->object.parsed)
                                parse_tree(subtree);
                        sub = cache_tree_sub(it, entry.path);
index b63a1fc85eaded844fcb1a2634067f9509b5937c..d1a68f0128f6f03c3c47299384a6a0388c39dfb5 100644 (file)
@@ -344,7 +344,7 @@ static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *
                                           GRAPH_DATA_WIDTH * (c->graph_pos);
 
        hashcpy(oid.hash, commit_data);
                                           GRAPH_DATA_WIDTH * (c->graph_pos);
 
        hashcpy(oid.hash, commit_data);
-       c->maybe_tree = lookup_tree(&oid);
+       c->maybe_tree = lookup_tree(the_repository, &oid);
 
        return c->maybe_tree;
 }
 
        return c->maybe_tree;
 }
index 0d55600e643225f02738f5b1c7943c9a95cc9014..2fa4220ac86fdd963e40ef18111b565f56f75f78 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -383,7 +383,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
        if (get_oid_hex(bufptr + 5, &parent) < 0)
                return error("bad tree pointer in commit %s",
                             oid_to_hex(&item->object.oid));
        if (get_oid_hex(bufptr + 5, &parent) < 0)
                return error("bad tree pointer in commit %s",
                             oid_to_hex(&item->object.oid));
-       item->maybe_tree = lookup_tree(&parent);
+       item->maybe_tree = lookup_tree(the_repository, &parent);
        bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
        pptr = &item->parents;
 
        bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
        pptr = &item->parents;
 
diff --git a/fsck.c b/fsck.c
index ea00f7228df5694817b321d3f0ea654dadf6405b..93459798bcb2144081b829c3a860b294ba5a3be3 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -407,7 +407,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
                        continue;
 
                if (S_ISDIR(entry.mode)) {
                        continue;
 
                if (S_ISDIR(entry.mode)) {
-                       obj = (struct object *)lookup_tree(entry.oid);
+                       obj = (struct object *)lookup_tree(the_repository, entry.oid);
                        if (name && obj)
                                put_object_name(options, obj, "%s%s/", name,
                                        entry.path);
                        if (name && obj)
                                put_object_name(options, obj, "%s%s/", name,
                                        entry.path);
index 191b51cb59193d55742ffd9b959a609360124f55..f7b70c4efb11b834dc1960a8ccbcb6ae9dae8aa3 100644 (file)
@@ -1311,7 +1311,8 @@ static struct object_list **process_tree(struct tree *tree,
        while (tree_entry(&desc, &entry))
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
        while (tree_entry(&desc, &entry))
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       p = process_tree(lookup_tree(entry.oid), p);
+                       p = process_tree(lookup_tree(the_repository, entry.oid),
+                                        p);
                        break;
                case OBJ_BLOB:
                        p = process_blob(lookup_blob(the_repository, entry.oid),
                        break;
                case OBJ_BLOB:
                        p = process_blob(lookup_blob(the_repository, entry.oid),
index 04c45f66e8830e9c965621b4fd4a879326bcfe5b..782c0e189f933869d3df4f1ba1e17398e95b215b 100644 (file)
@@ -158,7 +158,7 @@ static void process_tree(struct rev_info *revs,
 
                if (S_ISDIR(entry.mode))
                        process_tree(revs,
 
                if (S_ISDIR(entry.mode))
                        process_tree(revs,
-                                    lookup_tree(entry.oid),
+                                    lookup_tree(the_repository, entry.oid),
                                     show, base, entry.path,
                                     cb_data, filter_fn, filter_data);
                else if (S_ISGITLINK(entry.mode))
                                     show, base, entry.path,
                                     cb_data, filter_fn, filter_data);
                else if (S_ISGITLINK(entry.mode))
index 63bc0e2a04243c7e10701609fa49f80cc0124456..fbb044e6f6fd1b575622d37c1e15580ac95604d6 100644 (file)
@@ -158,7 +158,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
        }
        if (!oidcmp(&two->object.oid, &shifted))
                return two;
        }
        if (!oidcmp(&two->object.oid, &shifted))
                return two;
-       return lookup_tree(&shifted);
+       return lookup_tree(the_repository, &shifted);
 }
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
 }
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -416,7 +416,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
                return NULL;
        }
 
                return NULL;
        }
 
-       result = lookup_tree(&active_cache_tree->oid);
+       result = lookup_tree(the_repository, &active_cache_tree->oid);
 
        return result;
 }
 
        return result;
 }
@@ -3405,7 +3405,7 @@ int merge_recursive(struct merge_options *o,
                /* if there is no common ancestor, use an empty tree */
                struct tree *tree;
 
                /* if there is no common ancestor, use an empty tree */
                struct tree *tree;
 
-               tree = lookup_tree(the_hash_algo->empty_tree);
+               tree = lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
                merged_common_ancestors = make_virtual_commit(tree, "ancestor");
        }
 
                merged_common_ancestors = make_virtual_commit(tree, "ancestor");
        }
 
index fde816ad952289fc9c336a37984d6a95aa4e3e90..2acd3a03e392c1941d9b91e2353faa6719ddd2ed 100644 (file)
--- a/object.c
+++ b/object.c
@@ -200,7 +200,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
                        obj = &blob->object;
                }
        } else if (type == OBJ_TREE) {
                        obj = &blob->object;
                }
        } else if (type == OBJ_TREE) {
-               struct tree *tree = lookup_tree(oid);
+               struct tree *tree = lookup_tree(the_repository, oid);
                if (tree) {
                        obj = &tree->object;
                        if (!tree->buffer)
                if (tree) {
                        obj = &tree->object;
                        if (!tree->buffer)
index cc25f012e5df10fd04f2e4739a10297bc546a9d3..6e9b810d2a5e03dc613fe1e58938086f1ed9b684 100644 (file)
@@ -88,7 +88,7 @@ static void add_recent_object(const struct object_id *oid,
                obj = parse_object_or_die(oid, NULL);
                break;
        case OBJ_TREE:
                obj = parse_object_or_die(oid, NULL);
                break;
        case OBJ_TREE:
-               obj = (struct object *)lookup_tree(oid);
+               obj = (struct object *)lookup_tree(the_repository, oid);
                break;
        case OBJ_BLOB:
                obj = (struct object *)lookup_blob(the_repository, oid);
                break;
        case OBJ_BLOB:
                obj = (struct object *)lookup_blob(the_repository, oid);
index e3824127567ba483ebb5f16d6b87d91260d1597b..02e1296e36d2fe703d046d69869fd20931353116 100644 (file)
@@ -63,7 +63,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
        while (tree_entry(&desc, &entry)) {
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
        while (tree_entry(&desc, &entry)) {
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       mark_tree_uninteresting(lookup_tree(entry.oid));
+                       mark_tree_uninteresting(lookup_tree(the_repository, entry.oid));
                        break;
                case OBJ_BLOB:
                        mark_blob_uninteresting(lookup_blob(the_repository, entry.oid));
                        break;
                case OBJ_BLOB:
                        mark_blob_uninteresting(lookup_blob(the_repository, entry.oid));
@@ -1322,7 +1322,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
        int i;
 
        if (it->entry_count >= 0) {
        int i;
 
        if (it->entry_count >= 0) {
-               struct tree *tree = lookup_tree(&it->oid);
+               struct tree *tree = lookup_tree(the_repository, &it->oid);
                add_pending_object_with_path(revs, &tree->object, "",
                                             040000, path->buf);
        }
                add_pending_object_with_path(revs, &tree->object, "",
                                             040000, path->buf);
        }
index 0a291c91fe8937428c063db5e22afc93ea7691b6..4cf7afbab6de22184697c45c4d8e757c79ec925f 100644 (file)
@@ -433,7 +433,7 @@ static int read_oneliner(struct strbuf *buf,
 
 static struct tree *empty_tree(void)
 {
 
 static struct tree *empty_tree(void)
 {
-       return lookup_tree(the_hash_algo->empty_tree);
+       return lookup_tree(the_repository, the_repository->hash_algo->empty_tree);
 }
 
 static int error_dirty_index(struct replay_opts *opts)
 }
 
 static int error_dirty_index(struct replay_opts *opts)
diff --git a/tag.c b/tag.c
index a31ae75e9608e1fa8f434715cfc015cad0438ea6..310102150abc072308d0d82a5b8b8c7b2a83e853 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -156,7 +156,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
        if (!strcmp(type, blob_type)) {
                item->tagged = (struct object *)lookup_blob(the_repository, &oid);
        } else if (!strcmp(type, tree_type)) {
        if (!strcmp(type, blob_type)) {
                item->tagged = (struct object *)lookup_blob(the_repository, &oid);
        } else if (!strcmp(type, tree_type)) {
-               item->tagged = (struct object *)lookup_tree(&oid);
+               item->tagged = (struct object *)lookup_tree(the_repository, &oid);
        } else if (!strcmp(type, commit_type)) {
                item->tagged = (struct object *)lookup_commit(&oid);
        } else if (!strcmp(type, tag_type)) {
        } else if (!strcmp(type, commit_type)) {
                item->tagged = (struct object *)lookup_commit(&oid);
        } else if (!strcmp(type, tag_type)) {
diff --git a/tree.c b/tree.c
index f31afb81be0292b4bf5eadcbc5ecb451e5fb69ab..12b69606ab0dafc90ea139e9b0191581cb788b8e 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -120,7 +120,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, '/');
                len = tree_entry_len(&entry);
                strbuf_add(base, entry.path, len);
                strbuf_addch(base, '/');
-               retval = read_tree_1(lookup_tree(&oid),
+               retval = read_tree_1(lookup_tree(the_repository, &oid),
                                     base, stage, pathspec,
                                     fn, context);
                strbuf_setlen(base, oldlen);
                                     base, stage, pathspec,
                                     fn, context);
                strbuf_setlen(base, oldlen);
@@ -195,7 +195,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
        return 0;
 }
 
        return 0;
 }
 
-struct tree *lookup_tree(const struct object_id *oid)
+struct tree *lookup_tree_the_repository(const struct object_id *oid)
 {
        struct object *obj = lookup_object(the_repository, oid->hash);
        if (!obj)
 {
        struct object *obj = lookup_object(the_repository, oid->hash);
        if (!obj)
diff --git a/tree.h b/tree.h
index e2a80be4ef87e35d895e8591a0f8a75df347d347..2ea21ed174b63c042c1044f7806d0a4582aba620 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -12,7 +12,8 @@ struct tree {
        unsigned long size;
 };
 
        unsigned long size;
 };
 
-struct tree *lookup_tree(const struct object_id *oid);
+#define lookup_tree(r, oid) lookup_tree_##r(oid)
+struct tree *lookup_tree_the_repository(const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
index 5b56c72a73841763b94f7be59aaf094916e51bc8..a3a256676116731dc5155e2bf2c616b5686dd9d7 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -49,7 +49,8 @@ static int process_tree(struct walker *walker, struct tree *tree)
                if (S_ISGITLINK(entry.mode))
                        continue;
                if (S_ISDIR(entry.mode)) {
                if (S_ISGITLINK(entry.mode))
                        continue;
                if (S_ISDIR(entry.mode)) {
-                       struct tree *tree = lookup_tree(entry.oid);
+                       struct tree *tree = lookup_tree(the_repository,
+                                                       entry.oid);
                        if (tree)
                                obj = &tree->object;
                }
                        if (tree)
                                obj = &tree->object;
                }