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>
Jeff King committed
Jun 20, 2019 at 03:41 UTC
d0229abd93e1115d935b0e55067e29bcc9815ce8
16 files changed
+30
-31
blob.c
+1
-1
@@ -7,7 +7,7 @@ const char *blob_type = "blob";
7
8
struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
9
{
10
- struct object *obj = lookup_object(r, oid->hash);
10
+ struct object *obj = lookup_object(r, oid);
11
if (!obj)
12
return create_object(r, oid->hash,
13
alloc_blob_node(r));
builtin/fast-export.c
+2
-2
@@ -275,7 +275,7 @@ static void export_blob(const struct object_id *oid)
275
if (is_null_oid(oid))
276
return;
277
278
- object = lookup_object(the_repository, oid->hash);
278
+ object = lookup_object(the_repository, oid);
279
if (object && object->flags & SHOWN)
280
return;
281
@@ -453,7 +453,7 @@ static void show_filemodify(struct diff_queue_struct *q,
453
&spec->oid));
454
else {
455
struct object *object = lookup_object(the_repository,
456
- spec->oid.hash);
456
+ &spec->oid);
457
printf("M %06o :%d ", spec->mode,
458
get_object_mark(object));
459
}
builtin/fsck.c
+3
-3
@@ -238,7 +238,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
238
static void mark_unreachable_referents(const struct object_id *oid)
239
{
240
struct fsck_options options = FSCK_OPTIONS_DEFAULT;
241
- struct object *obj = lookup_object(the_repository, oid->hash);
241
+ struct object *obj = lookup_object(the_repository, oid);
242
243
if (!obj || !(obj->flags & HAS_OBJ))
244
return; /* not part of our original set */
@@ -497,7 +497,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
497
struct object *obj;
498
499
if (!is_null_oid(oid)) {
500
- obj = lookup_object(the_repository, oid->hash);
500
+ obj = lookup_object(the_repository, oid);
501
if (obj && (obj->flags & HAS_OBJ)) {
502
if (timestamp && name_objects)
503
add_decoration(fsck_walk_options.object_names,
@@ -879,7 +879,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
879
struct object_id oid;
880
if (!get_oid(arg, &oid)) {
881
struct object *obj = lookup_object(the_repository,
882
- oid.hash);
882
+ &oid);
883
884
if (!obj || !(obj->flags & HAS_OBJ)) {
885
if (is_promisor_object(&oid))
builtin/name-rev.c
+1
-2
@@ -378,8 +378,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
378
*(p+1) = 0;
379
if (!get_oid(p - (hexsz - 1), &oid)) {
380
struct object *o =
381
- lookup_object(the_repository,
382
- oid.hash);
381
+ lookup_object(the_repository, &oid);
382
if (o)
383
name = get_rev_name(o, &buf);
384
}
builtin/prune.c
+1
-1
@@ -53,7 +53,7 @@ static int is_object_reachable(const struct object_id *oid,
53
54
perform_reachability_traversal(revs);
55
56
- obj = lookup_object(the_repository, oid->hash);
56
+ obj = lookup_object(the_repository, oid);
57
return obj && (obj->flags & SEEN);
58
}
59
builtin/unpack-objects.c
+1
-1
@@ -332,7 +332,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
332
{
333
struct object *obj;
334
struct obj_buffer *obj_buffer;
335
- obj = lookup_object(the_repository, base->hash);
335
+ obj = lookup_object(the_repository, base);
336
if (!obj)
337
return 0;
338
obj_buffer = lookup_object_buffer(obj);
commit.c
+1
-1
@@ -57,7 +57,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
57
58
struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
59
{
60
- struct object *obj = lookup_object(r, oid->hash);
60
+ struct object *obj = lookup_object(r, oid);
61
if (!obj)
62
return create_object(r, oid->hash,
63
alloc_commit_node(r));
delta-islands.c
+1
-1
@@ -296,7 +296,7 @@ void resolve_tree_islands(struct repository *r,
296
if (S_ISGITLINK(entry.mode))
297
continue;
298
299
- obj = lookup_object(r, entry.oid.hash);
299
+ obj = lookup_object(r, &entry.oid);
300
if (!obj)
301
continue;
302
fetch-pack.c
+6
-6
@@ -286,7 +286,7 @@ static int find_common(struct fetch_negotiator *negotiator,
286
* we cannot trust the object flags).
287
*/
288
if (!args->no_dependents &&
289
- ((o = lookup_object(the_repository, remote->hash)) != NULL) &&
289
+ ((o = lookup_object(the_repository, remote)) != NULL) &&
290
(o->flags & COMPLETE)) {
291
continue;
292
}
@@ -364,7 +364,7 @@ static int find_common(struct fetch_negotiator *negotiator,
364
if (skip_prefix(reader.line, "unshallow ", &arg)) {
365
if (get_oid_hex(arg, &oid))
366
die(_("invalid unshallow line: %s"), reader.line);
367
- if (!lookup_object(the_repository, oid.hash))
367
+ if (!lookup_object(the_repository, &oid))
368
die(_("object not found: %s"), reader.line);
369
/* make sure that it is parsed as shallow */
370
if (!parse_object(the_repository, &oid))
@@ -707,7 +707,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
707
for (ref = *refs; ref; ref = ref->next) {
708
struct object *o = deref_tag(the_repository,
709
lookup_object(the_repository,
710
- ref->old_oid.hash),
710
+ &ref->old_oid),
711
NULL, 0);
712
713
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -734,7 +734,7 @@ static int everything_local(struct fetch_pack_args *args,
734
const struct object_id *remote = &ref->old_oid;
735
struct object *o;
736
737
- o = lookup_object(the_repository, remote->hash);
737
+ o = lookup_object(the_repository, remote);
738
if (!o || !(o->flags & COMPLETE)) {
739
retval = 0;
740
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
1048
* we cannot trust the object flags).
1049
*/
1050
if (!no_dependents &&
1051
- ((o = lookup_object(the_repository, remote->hash)) != NULL) &&
1051
+ ((o = lookup_object(the_repository, remote)) != NULL) &&
1052
(o->flags & COMPLETE)) {
1053
continue;
1054
}
@@ -1275,7 +1275,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
1275
if (skip_prefix(reader->line, "unshallow ", &arg)) {
1276
if (get_oid_hex(arg, &oid))
1277
die(_("invalid unshallow line: %s"), reader->line);
1278
- if (!lookup_object(the_repository, oid.hash))
1278
+ if (!lookup_object(the_repository, &oid))
1279
die(_("object not found: %s"), reader->line);
1280
/* make sure that it is parsed as shallow */
1281
if (!parse_object(the_repository, &oid))
http-push.c
+1
-1
@@ -723,7 +723,7 @@ static void one_remote_object(const struct object_id *oid)
723
{
724
struct object *obj;
725
726
- obj = lookup_object(the_repository, oid->hash);
726
+ obj = lookup_object(the_repository, oid);
727
if (!obj)
728
obj = parse_object(the_repository, oid);
729
object.c
+6
-6
@@ -85,7 +85,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
85
* Look up the record for the given sha1 in the hash map stored in
86
* obj_hash. Return NULL if it was not found.
87
*/
88
-struct object *lookup_object(struct repository *r, const unsigned char *sha1)
88
+struct object *lookup_object(struct repository *r, const struct object_id *oid)
89
{
90
unsigned int i, first;
91
struct object *obj;
@@ -93,9 +93,9 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)
93
if (!r->parsed_objects->obj_hash)
94
return NULL;
95
96
- first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
96
+ first = i = hash_obj(oid->hash, r->parsed_objects->obj_hash_size);
97
while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
98
- if (hasheq(sha1, obj->oid.hash))
98
+ if (oideq(oid, &obj->oid))
99
break;
100
i++;
101
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
180
181
struct object *lookup_unknown_object(const struct object_id *oid)
182
{
183
- struct object *obj = lookup_object(the_repository, oid->hash);
183
+ struct object *obj = lookup_object(the_repository, oid);
184
if (!obj)
185
obj = create_object(the_repository, oid->hash,
186
alloc_object_node(the_repository));
@@ -256,7 +256,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
256
void *buffer;
257
struct object *obj;
258
259
- obj = lookup_object(r, oid->hash);
259
+ obj = lookup_object(r, oid);
260
if (obj && obj->parsed)
261
return obj;
262
@@ -268,7 +268,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
268
return NULL;
269
}
270
parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
271
- return lookup_object(r, oid->hash);
271
+ return lookup_object(r, oid);
272
}
273
274
buffer = repo_read_object_file(r, oid, &type, &size);
object.h
+1
-1
@@ -116,7 +116,7 @@ struct object *get_indexed_object(unsigned int);
116
* half-initialised objects, the caller is expected to initialize them
117
* by calling parse_object() on them.
118
*/
119
-struct object *lookup_object(struct repository *r, const unsigned char *sha1);
119
+struct object *lookup_object(struct repository *r, const struct object_id *oid);
120
121
void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
122
reachable.c
+2
-2
@@ -109,7 +109,7 @@ static int add_recent_loose(const struct object_id *oid,
109
const char *path, void *data)
110
{
111
struct stat st;
112
- struct object *obj = lookup_object(the_repository, oid->hash);
112
+ struct object *obj = lookup_object(the_repository, oid);
113
114
if (obj && obj->flags & SEEN)
115
return 0;
@@ -134,7 +134,7 @@ static int add_recent_packed(const struct object_id *oid,
134
struct packed_git *p, uint32_t pos,
135
void *data)
136
{
137
- struct object *obj = lookup_object(the_repository, oid->hash);
137
+ struct object *obj = lookup_object(the_repository, oid);
138
139
if (obj && obj->flags & SEEN)
140
return 0;
tag.c
+1
-1
@@ -100,7 +100,7 @@ struct object *deref_tag_noverify(struct object *o)
100
101
struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
102
{
103
- struct object *obj = lookup_object(r, oid->hash);
103
+ struct object *obj = lookup_object(r, oid);
104
if (!obj)
105
return create_object(r, oid->hash,
106
alloc_tag_node(r));
tree.c
+1
-1
@@ -197,7 +197,7 @@ int read_tree(struct repository *r, struct tree *tree, int stage,
197
198
struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
199
{
200
- struct object *obj = lookup_object(r, oid->hash);
200
+ struct object *obj = lookup_object(r, oid);
201
if (!obj)
202
return create_object(r, oid->hash,
203
alloc_tree_node(r));
upload-pack.c
+1
-1
@@ -534,7 +534,7 @@ static int get_reachable_list(struct object_array *src,
534
if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n')
535
break;
536
537
- o = lookup_object(the_repository, oid.hash);
537
+ o = lookup_object(the_repository, &oid);
538
if (o && o->type == OBJ_COMMIT) {
539
o->flags &= ~TMP_MARK;
540
}