object: add repository argument to lookup_object
authorStefan Beller <sbeller@google.com>
Fri, 29 Jun 2018 01:21:52 +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 callers of lookup_object to be more
specific about which repository to handle. 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: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 files changed:
blob.c
builtin/fast-export.c
builtin/fsck.c
builtin/name-rev.c
builtin/prune.c
builtin/unpack-objects.c
commit.c
fetch-pack.c
http-push.c
object.c
object.h
reachable.c
tag.c
tree.c
upload-pack.c
diff --git a/blob.c b/blob.c
index 458dafa811edf74e01e10777cf580c696bf0b1a8..75b737a761e369d2c184d4fb38aee6a69bc62222 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -7,7 +7,7 @@ const char *blob_type = "blob";
 
 struct blob *lookup_blob(const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
        if (!obj)
                return create_object(the_repository, oid->hash,
                                     alloc_blob_node(the_repository));
index a16aeaa826f90a6f7e20f8e7e0e5137d1c3006bc..e39c4e2c1d00e4090965d01305e952539395f1ea 100644 (file)
@@ -230,7 +230,7 @@ static void export_blob(const struct object_id *oid)
        if (is_null_oid(oid))
                return;
 
-       object = lookup_object(oid->hash);
+       object = lookup_object(the_repository, oid->hash);
        if (object && object->flags & SHOWN)
                return;
 
@@ -402,7 +402,8 @@ static void show_filemodify(struct diff_queue_struct *q,
                                                   anonymize_sha1(&spec->oid) :
                                                   spec->oid.hash));
                        else {
-                               struct object *object = lookup_object(spec->oid.hash);
+                               struct object *object = lookup_object(the_repository,
+                                                                     spec->oid.hash);
                                printf("M %06o :%d ", spec->mode,
                                       get_object_mark(object));
                        }
index 2b0930101d3e4efae805ee21e39f9247a4cf6a14..12d01e917475eb04a15156dad1e367495ef09a71 100644 (file)
@@ -410,7 +410,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
        struct object *obj;
 
        if (!is_null_oid(oid)) {
-               obj = lookup_object(oid->hash);
+               obj = lookup_object(the_repository, oid->hash);
                if (obj && (obj->flags & HAS_OBJ)) {
                        if (timestamp && name_objects)
                                add_decoration(fsck_walk_options.object_names,
@@ -763,7 +763,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                const char *arg = argv[i];
                struct object_id oid;
                if (!get_oid(arg, &oid)) {
-                       struct object *obj = lookup_object(oid.hash);
+                       struct object *obj = lookup_object(the_repository,
+                                                          oid.hash);
 
                        if (!obj || !(obj->flags & HAS_OBJ)) {
                                if (is_promisor_object(&oid))
index de54fa93e4f6b19efef8464b64f6e9bd87ee8b5b..f6eb419a029700db5e88220de95cea8e3dd6a732 100644 (file)
@@ -379,7 +379,8 @@ static void name_rev_line(char *p, struct name_ref_data *data)
                        *(p+1) = 0;
                        if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
                                struct object *o =
-                                       lookup_object(oid.hash);
+                                       lookup_object(the_repository,
+                                                     oid.hash);
                                if (o)
                                        name = get_rev_name(o, &buf);
                        }
index 70ec35aa0582386d233b4d49d4bbdbb9cef985cb..72b0621b7683e4c7b8efced044b831bf9ebc1941 100644 (file)
@@ -40,7 +40,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
         * Do we know about this object?
         * It must have been reachable
         */
-       if (lookup_object(oid->hash))
+       if (lookup_object(the_repository, oid->hash))
                return 0;
 
        if (lstat(fullpath, &st)) {
index cf585fcc5eee5e41aac066a08d6db080f33011b8..335b5ed9a0f1d17c1d1a2b67319c1282d77272a5 100644 (file)
@@ -331,7 +331,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
 {
        struct object *obj;
        struct obj_buffer *obj_buffer;
-       obj = lookup_object(base->hash);
+       obj = lookup_object(the_repository, base->hash);
        if (!obj)
                return 0;
        obj_buffer = lookup_object_buffer(obj);
index a29070a8133b135e51483ab8097358a3a1d18101..b4dbfd889a337090bc5d4d2a5401a9bc3784f9ee 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -54,7 +54,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 
 struct commit *lookup_commit(const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
        if (!obj)
                return create_object(the_repository, oid->hash,
                                     alloc_commit_node(the_repository));
index 6b406f1d0081dd77bf572a6094b66458477cbd3d..771eb8ae471a48f55620486395bcd6c0d4a8ecb1 100644 (file)
@@ -362,7 +362,7 @@ static int find_common(struct fetch_pack_args *args,
                 * interested in the case we *know* the object is
                 * reachable and we have already scanned it.
                 */
-               if (((o = lookup_object(remote->hash)) != NULL) &&
+               if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
                                (o->flags & COMPLETE)) {
                        continue;
                }
@@ -436,7 +436,7 @@ static int find_common(struct fetch_pack_args *args,
                        if (skip_prefix(line, "unshallow ", &arg)) {
                                if (get_oid_hex(arg, &oid))
                                        die(_("invalid unshallow line: %s"), line);
-                               if (!lookup_object(oid.hash))
+                               if (!lookup_object(the_repository, oid.hash))
                                        die(_("object not found: %s"), line);
                                /* make sure that it is parsed as shallow */
                                if (!parse_object(the_repository, &oid))
@@ -801,7 +801,8 @@ static int everything_local(struct fetch_pack_args *args,
                 * Don't mark them common yet; the server has to be told so first.
                 */
                for (ref = *refs; ref; ref = ref->next) {
-                       struct object *o = deref_tag(lookup_object(ref->old_oid.hash),
+                       struct object *o = deref_tag(lookup_object(the_repository,
+                                                    ref->old_oid.hash),
                                                     NULL, 0);
 
                        if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -821,7 +822,7 @@ static int everything_local(struct fetch_pack_args *args,
                const struct object_id *remote = &ref->old_oid;
                struct object *o;
 
-               o = lookup_object(remote->hash);
+               o = lookup_object(the_repository, remote->hash);
                if (!o || !(o->flags & COMPLETE)) {
                        retval = 0;
                        print_verbose(args, "want %s (%s)", oid_to_hex(remote),
@@ -1120,7 +1121,7 @@ static void add_wants(const struct ref *wants, struct strbuf *req_buf)
                 * interested in the case we *know* the object is
                 * reachable and we have already scanned it.
                 */
-               if (((o = lookup_object(remote->hash)) != NULL) &&
+               if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
                    (o->flags & COMPLETE)) {
                        continue;
                }
@@ -1317,7 +1318,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
                if (skip_prefix(reader->line, "unshallow ", &arg)) {
                        if (get_oid_hex(arg, &oid))
                                die(_("invalid unshallow line: %s"), reader->line);
-                       if (!lookup_object(oid.hash))
+                       if (!lookup_object(the_repository, oid.hash))
                                die(_("object not found: %s"), reader->line);
                        /* make sure that it is parsed as shallow */
                        if (!parse_object(the_repository, &oid))
index 37cbf0769ba725dc5b47082229ff7124e0b6e5c8..d2245cc73802fec76ed8613adf84c3995e70b716 100644 (file)
@@ -722,7 +722,7 @@ static void one_remote_object(const struct object_id *oid)
 {
        struct object *obj;
 
-       obj = lookup_object(oid->hash);
+       obj = lookup_object(the_repository, oid->hash);
        if (!obj)
                obj = parse_object(the_repository, oid);
 
index bf1d9c6b5ff8e7aaeef52e4167bd6a5338bb445b..002ebb69e3ba8c215f5ec7688afb4045543d5151 100644 (file)
--- a/object.c
+++ b/object.c
@@ -84,7 +84,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
  * Look up the record for the given sha1 in the hash map stored in
  * obj_hash.  Return NULL if it was not found.
  */
-struct object *lookup_object(const unsigned char *sha1)
+struct object *lookup_object_the_repository(const unsigned char *sha1)
 {
        unsigned int i, first;
        struct object *obj;
@@ -179,7 +179,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
 
 struct object *lookup_unknown_object(const unsigned char *sha1)
 {
-       struct object *obj = lookup_object(sha1);
+       struct object *obj = lookup_object(the_repository, sha1);
        if (!obj)
                obj = create_object(the_repository, sha1,
                                    alloc_object_node(the_repository));
@@ -255,7 +255,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
        void *buffer;
        struct object *obj;
 
-       obj = lookup_object(oid->hash);
+       obj = lookup_object(the_repository, oid->hash);
        if (obj && obj->parsed)
                return obj;
 
@@ -267,7 +267,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
                        return NULL;
                }
                parse_blob_buffer(lookup_blob(oid), NULL, 0);
-               return lookup_object(oid->hash);
+               return lookup_object(the_repository, oid->hash);
        }
 
        buffer = read_object_file(oid, &type, &size);
index 882f47fbc891da4ce292ed868aac7161cf563782..f840a428859eadd9054e9d7dbd4a29b794ab5d8d 100644 (file)
--- a/object.h
+++ b/object.h
@@ -109,7 +109,8 @@ extern struct object *get_indexed_object(unsigned int);
  * half-initialised objects, the caller is expected to initialize them
  * by calling parse_object() on them.
  */
-struct object *lookup_object(const unsigned char *sha1);
+#define lookup_object(r, s) lookup_object_##r(s)
+struct object *lookup_object_the_repository(const unsigned char *sha1);
 
 extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
index ffb976c33c6936a7b178c7c478bcf4cd2840d472..2ee55695595937aeac54280daf2da9815b5988ec 100644 (file)
@@ -108,7 +108,7 @@ static int add_recent_loose(const struct object_id *oid,
                            const char *path, void *data)
 {
        struct stat st;
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
 
        if (obj && obj->flags & SEEN)
                return 0;
@@ -133,7 +133,7 @@ static int add_recent_packed(const struct object_id *oid,
                             struct packed_git *p, uint32_t pos,
                             void *data)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
 
        if (obj && obj->flags & SEEN)
                return 0;
diff --git a/tag.c b/tag.c
index 7d282df06972c57cc028ea7f6a8ef9c0e77df149..1b95eb9f07fe3c2932611d297558e3b020db4f1e 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -94,7 +94,7 @@ struct object *deref_tag_noverify(struct object *o)
 
 struct tag *lookup_tag(const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
        if (!obj)
                return create_object(the_repository, oid->hash,
                                     alloc_tag_node(the_repository));
diff --git a/tree.c b/tree.c
index 533b6e69755e998d7c161ac133b5713736282cc0..73e8a8a948dc20b6e1fbe11cced5919477de67bb 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -197,7 +197,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
 
 struct tree *lookup_tree(const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(the_repository, oid->hash);
        if (!obj)
                return create_object(the_repository, oid->hash,
                                     alloc_tree_node(the_repository));
index d2b85112d08b26ad3b4563c43b72483542184aae..45e3a94788f387b9068b4b20f7175a70edf94394 100644 (file)
@@ -570,7 +570,7 @@ static int get_reachable_list(struct object_array *src,
                if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n')
                        break;
 
-               o = lookup_object(sha1.hash);
+               o = lookup_object(the_repository, sha1.hash);
                if (o && o->type == OBJ_COMMIT) {
                        o->flags &= ~TMP_MARK;
                }