object: convert lookup_object() to use object_id
authorJeff King <peff@peff.net>
Thu, 20 Jun 2019 07:41:14 +0000 (03:41 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2019 17:18:09 +0000 (10:18 -0700)
There are no callers left of lookup_object() that aren't just passing us
the "hash" member of a "struct object_id". Let's take the whole struct,
which gets us closer to removing all raw sha1 variables. It also
matches the existing conversions of lookup_blob(), etc.

The conversions of callers were done by hand, but they're all mechanical
one-liners.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 files changed:
blob.c
builtin/fast-export.c
builtin/fsck.c
builtin/name-rev.c
builtin/prune.c
builtin/unpack-objects.c
commit.c
delta-islands.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 342bdbb1bbea78dced090b815cab5ff9bfed9cd9..b9c7180b7cc112fb17661b075586970e4949905e 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -7,7 +7,7 @@ const char *blob_type = "blob";
 
 struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(r, oid->hash);
+       struct object *obj = lookup_object(r, oid);
        if (!obj)
                return create_object(r, oid->hash,
                                     alloc_blob_node(r));
index c22cef3b2faff945148029197a32253540c24f73..f541f55d333b7a29fcdca88919dc316a1fe0b931 100644 (file)
@@ -275,7 +275,7 @@ static void export_blob(const struct object_id *oid)
        if (is_null_oid(oid))
                return;
 
-       object = lookup_object(the_repository, oid->hash);
+       object = lookup_object(the_repository, oid);
        if (object && object->flags & SHOWN)
                return;
 
@@ -453,7 +453,7 @@ static void show_filemodify(struct diff_queue_struct *q,
                                                  &spec->oid));
                        else {
                                struct object *object = lookup_object(the_repository,
-                                                                     spec->oid.hash);
+                                                                     &spec->oid);
                                printf("M %06o :%d ", spec->mode,
                                       get_object_mark(object));
                        }
index e422c82465a5c6dcdd842063f008382093773e38..18403a94fa4224e0d108dec3cfeb8e9cd24481b8 100644 (file)
@@ -238,7 +238,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
 static void mark_unreachable_referents(const struct object_id *oid)
 {
        struct fsck_options options = FSCK_OPTIONS_DEFAULT;
-       struct object *obj = lookup_object(the_repository, oid->hash);
+       struct object *obj = lookup_object(the_repository, oid);
 
        if (!obj || !(obj->flags & HAS_OBJ))
                return; /* not part of our original set */
@@ -497,7 +497,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(the_repository, oid->hash);
+               obj = lookup_object(the_repository, oid);
                if (obj && (obj->flags & HAS_OBJ)) {
                        if (timestamp && name_objects)
                                add_decoration(fsck_walk_options.object_names,
@@ -879,7 +879,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                struct object_id oid;
                if (!get_oid(arg, &oid)) {
                        struct object *obj = lookup_object(the_repository,
-                                                          oid.hash);
+                                                          &oid);
 
                        if (!obj || !(obj->flags & HAS_OBJ)) {
                                if (is_promisor_object(&oid))
index 16df43473aaf61fe9b6f95fa449068ccf0eacafb..c785fe16bade1a67d4da782d91b61bdd61d99115 100644 (file)
@@ -378,8 +378,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
                        *(p+1) = 0;
                        if (!get_oid(p - (hexsz - 1), &oid)) {
                                struct object *o =
-                                       lookup_object(the_repository,
-                                                     oid.hash);
+                                       lookup_object(the_repository, &oid);
                                if (o)
                                        name = get_rev_name(o, &buf);
                        }
index 97613eccb54dcba31d9fb35df54673fdf1f57817..2b76872ad2207857077f4ecf285780e94388d00d 100644 (file)
@@ -53,7 +53,7 @@ static int is_object_reachable(const struct object_id *oid,
 
        perform_reachability_traversal(revs);
 
-       obj = lookup_object(the_repository, oid->hash);
+       obj = lookup_object(the_repository, oid);
        return obj && (obj->flags & SEEN);
 }
 
index 80478808b3dcc7f98e5989140de1451783454c01..a87a4bfd2c557755cc0c49d28cf8597449e4d0b1 100644 (file)
@@ -332,7 +332,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
 {
        struct object *obj;
        struct obj_buffer *obj_buffer;
-       obj = lookup_object(the_repository, base->hash);
+       obj = lookup_object(the_repository, base);
        if (!obj)
                return 0;
        obj_buffer = lookup_object_buffer(obj);
index 8fa1883c61c580578a755cdf2da009203d8d386e..f47c75afae7f14a6f0e15aaa89890dcdfeeba8ce 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -57,7 +57,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
 
 struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(r, oid->hash);
+       struct object *obj = lookup_object(r, oid);
        if (!obj)
                return create_object(r, oid->hash,
                                     alloc_commit_node(r));
index 2186bd0738ed2fcbe216cf24a6c99ed4dc4ccd9b..5f3ab914f5de16dbe5dd0e3035746276d820b52f 100644 (file)
@@ -296,7 +296,7 @@ void resolve_tree_islands(struct repository *r,
                        if (S_ISGITLINK(entry.mode))
                                continue;
 
-                       obj = lookup_object(r, entry.oid.hash);
+                       obj = lookup_object(r, &entry.oid);
                        if (!obj)
                                continue;
 
index 1c10f54e788ca53b548a226a66dd1eec96a8cb22..07bc48a1a561bf554b8a18f337efe6ffda722c86 100644 (file)
@@ -286,7 +286,7 @@ static int find_common(struct fetch_negotiator *negotiator,
                 * we cannot trust the object flags).
                 */
                if (!args->no_dependents &&
-                   ((o = lookup_object(the_repository, remote->hash)) != NULL) &&
+                   ((o = lookup_object(the_repository, remote)) != NULL) &&
                                (o->flags & COMPLETE)) {
                        continue;
                }
@@ -364,7 +364,7 @@ static int find_common(struct fetch_negotiator *negotiator,
                        if (skip_prefix(reader.line, "unshallow ", &arg)) {
                                if (get_oid_hex(arg, &oid))
                                        die(_("invalid unshallow line: %s"), reader.line);
-                               if (!lookup_object(the_repository, oid.hash))
+                               if (!lookup_object(the_repository, &oid))
                                        die(_("object not found: %s"), reader.line);
                                /* make sure that it is parsed as shallow */
                                if (!parse_object(the_repository, &oid))
@@ -707,7 +707,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
        for (ref = *refs; ref; ref = ref->next) {
                struct object *o = deref_tag(the_repository,
                                             lookup_object(the_repository,
-                                            ref->old_oid.hash),
+                                            &ref->old_oid),
                                             NULL, 0);
 
                if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -734,7 +734,7 @@ static int everything_local(struct fetch_pack_args *args,
                const struct object_id *remote = &ref->old_oid;
                struct object *o;
 
-               o = lookup_object(the_repository, remote->hash);
+               o = lookup_object(the_repository, remote);
                if (!o || !(o->flags & COMPLETE)) {
                        retval = 0;
                        print_verbose(args, "want %s (%s)", oid_to_hex(remote),
@@ -1048,7 +1048,7 @@ static void add_wants(int no_dependents, const struct ref *wants, struct strbuf
                 * we cannot trust the object flags).
                 */
                if (!no_dependents &&
-                   ((o = lookup_object(the_repository, remote->hash)) != NULL) &&
+                   ((o = lookup_object(the_repository, remote)) != NULL) &&
                    (o->flags & COMPLETE)) {
                        continue;
                }
@@ -1275,7 +1275,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(the_repository, oid.hash))
+                       if (!lookup_object(the_repository, &oid))
                                die(_("object not found: %s"), reader->line);
                        /* make sure that it is parsed as shallow */
                        if (!parse_object(the_repository, &oid))
index 96a98e1e615968b20d84aac0ecf6098934e83851..0353f9f5143d7fff3a2b4b11d02375255258319b 100644 (file)
@@ -723,7 +723,7 @@ static void one_remote_object(const struct object_id *oid)
 {
        struct object *obj;
 
-       obj = lookup_object(the_repository, oid->hash);
+       obj = lookup_object(the_repository, oid);
        if (!obj)
                obj = parse_object(the_repository, oid);
 
index d5b1d8daaf7bf761cb145289d9c3999829d96fdd..34c1d0dc8f886c2c72f5b2992ea69f329ec6c918 100644 (file)
--- a/object.c
+++ b/object.c
@@ -85,7 +85,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(struct repository *r, const unsigned char *sha1)
+struct object *lookup_object(struct repository *r, const struct object_id *oid)
 {
        unsigned int i, first;
        struct object *obj;
@@ -93,9 +93,9 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)
        if (!r->parsed_objects->obj_hash)
                return NULL;
 
-       first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
+       first = i = hash_obj(oid->hash, r->parsed_objects->obj_hash_size);
        while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
-               if (hasheq(sha1, obj->oid.hash))
+               if (oideq(oid, &obj->oid))
                        break;
                i++;
                if (i == r->parsed_objects->obj_hash_size)
@@ -180,7 +180,7 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type
 
 struct object *lookup_unknown_object(const struct object_id *oid)
 {
-       struct object *obj = lookup_object(the_repository, oid->hash);
+       struct object *obj = lookup_object(the_repository, oid);
        if (!obj)
                obj = create_object(the_repository, oid->hash,
                                    alloc_object_node(the_repository));
@@ -256,7 +256,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
        void *buffer;
        struct object *obj;
 
-       obj = lookup_object(r, oid->hash);
+       obj = lookup_object(r, oid);
        if (obj && obj->parsed)
                return obj;
 
@@ -268,7 +268,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
                        return NULL;
                }
                parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
-               return lookup_object(r, oid->hash);
+               return lookup_object(r, oid);
        }
 
        buffer = repo_read_object_file(r, oid, &type, &size);
index 5e0ccfe0e40415d2e50f6ebed7b27f20bde885f5..47301186a47e544625726480611adde465737229 100644 (file)
--- a/object.h
+++ b/object.h
@@ -116,7 +116,7 @@ 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(struct repository *r, const unsigned char *sha1);
+struct object *lookup_object(struct repository *r, const struct object_id *oid);
 
 void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
 
index 0d00a91de4c848dff499edb7dbbfda45ffda05fb..8f50235b28edd43c3a4e122a1bcae4d1c1b3f99b 100644 (file)
@@ -109,7 +109,7 @@ static int add_recent_loose(const struct object_id *oid,
                            const char *path, void *data)
 {
        struct stat st;
-       struct object *obj = lookup_object(the_repository, oid->hash);
+       struct object *obj = lookup_object(the_repository, oid);
 
        if (obj && obj->flags & SEEN)
                return 0;
@@ -134,7 +134,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(the_repository, oid->hash);
+       struct object *obj = lookup_object(the_repository, oid);
 
        if (obj && obj->flags & SEEN)
                return 0;
diff --git a/tag.c b/tag.c
index 7445b8f6ea4d371bc76aa5dcc1c1448abef149a1..3ae00ba1ab9343cfd236887c4b8e308d499ce537 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -100,7 +100,7 @@ struct object *deref_tag_noverify(struct object *o)
 
 struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(r, oid->hash);
+       struct object *obj = lookup_object(r, oid);
        if (!obj)
                return create_object(r, oid->hash,
                                     alloc_tag_node(r));
diff --git a/tree.c b/tree.c
index f416afc57d784f8f63ba66ec8c7424ef1e4fcaa1..0ebb8c5b02f7c1e364c20554d1a47562d6c8e4b6 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -197,7 +197,7 @@ int read_tree(struct repository *r, struct tree *tree, int stage,
 
 struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(r, oid->hash);
+       struct object *obj = lookup_object(r, oid);
        if (!obj)
                return create_object(r, oid->hash,
                                     alloc_tree_node(r));
index ecc19641fe6790a221238edbe7c9b6c45e53ebe7..a0f170b5b5f10d7d4524ea871d8881c709b77d53 100644 (file)
@@ -534,7 +534,7 @@ static int get_reachable_list(struct object_array *src,
                if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n')
                        break;
 
-               o = lookup_object(the_repository, oid.hash);
+               o = lookup_object(the_repository, &oid);
                if (o && o->type == OBJ_COMMIT) {
                        o->flags &= ~TMP_MARK;
                }