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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jeff King 2019-06-20 03:41:14 -04:00 committed by Junio C Hamano
parent 0ebbcf70e6
commit d0229abd93
16 changed files with 30 additions and 31 deletions

2
blob.c
View File

@ -7,7 +7,7 @@ const char *blob_type = "blob";


struct blob *lookup_blob(struct repository *r, const struct object_id *oid) 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) if (!obj)
return create_object(r, oid->hash, return create_object(r, oid->hash,
alloc_blob_node(r)); alloc_blob_node(r));

View File

@ -275,7 +275,7 @@ static void export_blob(const struct object_id *oid)
if (is_null_oid(oid)) if (is_null_oid(oid))
return; return;


object = lookup_object(the_repository, oid->hash); object = lookup_object(the_repository, oid);
if (object && object->flags & SHOWN) if (object && object->flags & SHOWN)
return; return;


@ -453,7 +453,7 @@ static void show_filemodify(struct diff_queue_struct *q,
&spec->oid)); &spec->oid));
else { else {
struct object *object = lookup_object(the_repository, struct object *object = lookup_object(the_repository,
spec->oid.hash); &spec->oid);
printf("M %06o :%d ", spec->mode, printf("M %06o :%d ", spec->mode,
get_object_mark(object)); get_object_mark(object));
} }

View 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) static void mark_unreachable_referents(const struct object_id *oid)
{ {
struct fsck_options options = FSCK_OPTIONS_DEFAULT; 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)) if (!obj || !(obj->flags & HAS_OBJ))
return; /* not part of our original set */ 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; struct object *obj;


if (!is_null_oid(oid)) { 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 (obj && (obj->flags & HAS_OBJ)) {
if (timestamp && name_objects) if (timestamp && name_objects)
add_decoration(fsck_walk_options.object_names, 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; struct object_id oid;
if (!get_oid(arg, &oid)) { if (!get_oid(arg, &oid)) {
struct object *obj = lookup_object(the_repository, struct object *obj = lookup_object(the_repository,
oid.hash); &oid);


if (!obj || !(obj->flags & HAS_OBJ)) { if (!obj || !(obj->flags & HAS_OBJ)) {
if (is_promisor_object(&oid)) if (is_promisor_object(&oid))

View File

@ -378,8 +378,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
*(p+1) = 0; *(p+1) = 0;
if (!get_oid(p - (hexsz - 1), &oid)) { if (!get_oid(p - (hexsz - 1), &oid)) {
struct object *o = struct object *o =
lookup_object(the_repository, lookup_object(the_repository, &oid);
oid.hash);
if (o) if (o)
name = get_rev_name(o, &buf); name = get_rev_name(o, &buf);
} }

View File

@ -53,7 +53,7 @@ static int is_object_reachable(const struct object_id *oid,


perform_reachability_traversal(revs); perform_reachability_traversal(revs);


obj = lookup_object(the_repository, oid->hash); obj = lookup_object(the_repository, oid);
return obj && (obj->flags & SEEN); return obj && (obj->flags & SEEN);
} }



View File

@ -332,7 +332,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
{ {
struct object *obj; struct object *obj;
struct obj_buffer *obj_buffer; struct obj_buffer *obj_buffer;
obj = lookup_object(the_repository, base->hash); obj = lookup_object(the_repository, base);
if (!obj) if (!obj)
return 0; return 0;
obj_buffer = lookup_object_buffer(obj); obj_buffer = lookup_object_buffer(obj);

View File

@ -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 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) if (!obj)
return create_object(r, oid->hash, return create_object(r, oid->hash,
alloc_commit_node(r)); alloc_commit_node(r));

View File

@ -296,7 +296,7 @@ void resolve_tree_islands(struct repository *r,
if (S_ISGITLINK(entry.mode)) if (S_ISGITLINK(entry.mode))
continue; continue;


obj = lookup_object(r, entry.oid.hash); obj = lookup_object(r, &entry.oid);
if (!obj) if (!obj)
continue; continue;



View File

@ -286,7 +286,7 @@ static int find_common(struct fetch_negotiator *negotiator,
* we cannot trust the object flags). * we cannot trust the object flags).
*/ */
if (!args->no_dependents && if (!args->no_dependents &&
((o = lookup_object(the_repository, remote->hash)) != NULL) && ((o = lookup_object(the_repository, remote)) != NULL) &&
(o->flags & COMPLETE)) { (o->flags & COMPLETE)) {
continue; continue;
} }
@ -364,7 +364,7 @@ static int find_common(struct fetch_negotiator *negotiator,
if (skip_prefix(reader.line, "unshallow ", &arg)) { if (skip_prefix(reader.line, "unshallow ", &arg)) {
if (get_oid_hex(arg, &oid)) if (get_oid_hex(arg, &oid))
die(_("invalid unshallow line: %s"), reader.line); 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); die(_("object not found: %s"), reader.line);
/* make sure that it is parsed as shallow */ /* make sure that it is parsed as shallow */
if (!parse_object(the_repository, &oid)) 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) { for (ref = *refs; ref; ref = ref->next) {
struct object *o = deref_tag(the_repository, struct object *o = deref_tag(the_repository,
lookup_object(the_repository, lookup_object(the_repository,
ref->old_oid.hash), &ref->old_oid),
NULL, 0); NULL, 0);


if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE)) 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; const struct object_id *remote = &ref->old_oid;
struct object *o; struct object *o;


o = lookup_object(the_repository, remote->hash); o = lookup_object(the_repository, remote);
if (!o || !(o->flags & COMPLETE)) { if (!o || !(o->flags & COMPLETE)) {
retval = 0; retval = 0;
print_verbose(args, "want %s (%s)", oid_to_hex(remote), 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). * we cannot trust the object flags).
*/ */
if (!no_dependents && if (!no_dependents &&
((o = lookup_object(the_repository, remote->hash)) != NULL) && ((o = lookup_object(the_repository, remote)) != NULL) &&
(o->flags & COMPLETE)) { (o->flags & COMPLETE)) {
continue; continue;
} }
@ -1275,7 +1275,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
if (skip_prefix(reader->line, "unshallow ", &arg)) { if (skip_prefix(reader->line, "unshallow ", &arg)) {
if (get_oid_hex(arg, &oid)) if (get_oid_hex(arg, &oid))
die(_("invalid unshallow line: %s"), reader->line); 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); die(_("object not found: %s"), reader->line);
/* make sure that it is parsed as shallow */ /* make sure that it is parsed as shallow */
if (!parse_object(the_repository, &oid)) if (!parse_object(the_repository, &oid))

View File

@ -723,7 +723,7 @@ static void one_remote_object(const struct object_id *oid)
{ {
struct object *obj; struct object *obj;


obj = lookup_object(the_repository, oid->hash); obj = lookup_object(the_repository, oid);
if (!obj) if (!obj)
obj = parse_object(the_repository, oid); obj = parse_object(the_repository, oid);



View File

@ -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 * Look up the record for the given sha1 in the hash map stored in
* obj_hash. Return NULL if it was not found. * 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; unsigned int i, first;
struct object *obj; struct object *obj;
@ -93,9 +93,9 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)
if (!r->parsed_objects->obj_hash) if (!r->parsed_objects->obj_hash)
return NULL; 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) { while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
if (hasheq(sha1, obj->oid.hash)) if (oideq(oid, &obj->oid))
break; break;
i++; i++;
if (i == r->parsed_objects->obj_hash_size) 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 *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) if (!obj)
obj = create_object(the_repository, oid->hash, obj = create_object(the_repository, oid->hash,
alloc_object_node(the_repository)); alloc_object_node(the_repository));
@ -256,7 +256,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
void *buffer; void *buffer;
struct object *obj; struct object *obj;


obj = lookup_object(r, oid->hash); obj = lookup_object(r, oid);
if (obj && obj->parsed) if (obj && obj->parsed)
return obj; return obj;


@ -268,7 +268,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
return NULL; return NULL;
} }
parse_blob_buffer(lookup_blob(r, oid), NULL, 0); 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); buffer = repo_read_object_file(r, oid, &type, &size);

View File

@ -116,7 +116,7 @@ struct object *get_indexed_object(unsigned int);
* half-initialised objects, the caller is expected to initialize them * half-initialised objects, the caller is expected to initialize them
* by calling parse_object() on 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); void *create_object(struct repository *r, const unsigned char *sha1, void *obj);



View File

@ -109,7 +109,7 @@ static int add_recent_loose(const struct object_id *oid,
const char *path, void *data) const char *path, void *data)
{ {
struct stat st; 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) if (obj && obj->flags & SEEN)
return 0; return 0;
@ -134,7 +134,7 @@ static int add_recent_packed(const struct object_id *oid,
struct packed_git *p, uint32_t pos, struct packed_git *p, uint32_t pos,
void *data) void *data)
{ {
struct object *obj = lookup_object(the_repository, oid->hash); struct object *obj = lookup_object(the_repository, oid);


if (obj && obj->flags & SEEN) if (obj && obj->flags & SEEN)
return 0; return 0;

2
tag.c
View File

@ -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 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) if (!obj)
return create_object(r, oid->hash, return create_object(r, oid->hash,
alloc_tag_node(r)); alloc_tag_node(r));

2
tree.c
View File

@ -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 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) if (!obj)
return create_object(r, oid->hash, return create_object(r, oid->hash,
alloc_tree_node(r)); alloc_tree_node(r));

View File

@ -534,7 +534,7 @@ static int get_reachable_list(struct object_array *src,
if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n') if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n')
break; break;


o = lookup_object(the_repository, oid.hash); o = lookup_object(the_repository, &oid);
if (o && o->type == OBJ_COMMIT) { if (o && o->type == OBJ_COMMIT) {
o->flags &= ~TMP_MARK; o->flags &= ~TMP_MARK;
} }