From d0229abd93e1115d935b0e55067e29bcc9815ce8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 20 Jun 2019 03:41:14 -0400 Subject: object: convert lookup_object() to use object_id 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 Signed-off-by: Junio C Hamano diff --git a/blob.c b/blob.c index 342bdbb..b9c7180 100644 --- 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)); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index c22cef3..f541f55 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -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)); } diff --git a/builtin/fsck.c b/builtin/fsck.c index e422c82..18403a9 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -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)) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 16df434..c785fe1 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -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); } diff --git a/builtin/prune.c b/builtin/prune.c index 97613ec..2b76872 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -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); } diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 8047880..a87a4bf 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -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); diff --git a/commit.c b/commit.c index 8fa1883..f47c75a 100644 --- 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)); diff --git a/delta-islands.c b/delta-islands.c index 2186bd0..5f3ab91 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -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; diff --git a/fetch-pack.c b/fetch-pack.c index 1c10f54..07bc48a 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -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)) diff --git a/http-push.c b/http-push.c index 96a98e1..0353f9f 100644 --- a/http-push.c +++ b/http-push.c @@ -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); diff --git a/object.c b/object.c index d5b1d8d..34c1d0d 100644 --- 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); diff --git a/object.h b/object.h index 5e0ccfe..4730118 100644 --- 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); diff --git a/reachable.c b/reachable.c index 0d00a91..8f50235 100644 --- a/reachable.c +++ b/reachable.c @@ -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 7445b8f..3ae00ba 100644 --- 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 f416afc..0ebb8c5 100644 --- 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)); diff --git a/upload-pack.c b/upload-pack.c index ecc1964..a0f170b 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -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; } -- cgit v0.10.2-6-g49f6