Skip to content

Commit 3e93098

Browse files
bk2204gitster
authored andcommitted
Convert remaining callers of lookup_blob to object_id
All but a few callers of lookup_blob have been converted to struct object_id. Introduce a temporary, which will be removed later, into parse_object to ease the transition, and convert the remaining callers so that we can update lookup_blob to take struct object_id *. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 834bc47 commit 3e93098

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

builtin/index-pack.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ static int check_collison(struct object_entry *entry)
785785

786786
static void sha1_object(const void *data, struct object_entry *obj_entry,
787787
unsigned long size, enum object_type type,
788-
const unsigned char *sha1)
788+
const struct object_id *oid)
789789
{
790790
void *new_data = NULL;
791791
int collision_test_needed = 0;
@@ -794,7 +794,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
794794

795795
if (startup_info->have_repository) {
796796
read_lock();
797-
collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK);
797+
collision_test_needed = has_sha1_file_with_flags(oid->hash, HAS_SHA1_QUICK);
798798
read_unlock();
799799
}
800800

@@ -809,31 +809,31 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
809809
enum object_type has_type;
810810
unsigned long has_size;
811811
read_lock();
812-
has_type = sha1_object_info(sha1, &has_size);
812+
has_type = sha1_object_info(oid->hash, &has_size);
813813
if (has_type < 0)
814-
die(_("cannot read existing object info %s"), sha1_to_hex(sha1));
814+
die(_("cannot read existing object info %s"), oid_to_hex(oid));
815815
if (has_type != type || has_size != size)
816-
die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1));
817-
has_data = read_sha1_file(sha1, &has_type, &has_size);
816+
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
817+
has_data = read_sha1_file(oid->hash, &has_type, &has_size);
818818
read_unlock();
819819
if (!data)
820820
data = new_data = get_data_from_pack(obj_entry);
821821
if (!has_data)
822-
die(_("cannot read existing object %s"), sha1_to_hex(sha1));
822+
die(_("cannot read existing object %s"), oid_to_hex(oid));
823823
if (size != has_size || type != has_type ||
824824
memcmp(data, has_data, size) != 0)
825-
die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1));
825+
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
826826
free(has_data);
827827
}
828828

829829
if (strict) {
830830
read_lock();
831831
if (type == OBJ_BLOB) {
832-
struct blob *blob = lookup_blob(sha1);
832+
struct blob *blob = lookup_blob(oid->hash);
833833
if (blob)
834834
blob->object.flags |= FLAG_CHECKED;
835835
else
836-
die(_("invalid blob object %s"), sha1_to_hex(sha1));
836+
die(_("invalid blob object %s"), oid_to_hex(oid));
837837
} else {
838838
struct object *obj;
839839
int eaten;
@@ -845,7 +845,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
845845
* we do not need to free the memory here, as the
846846
* buf is deleted by the caller.
847847
*/
848-
obj = parse_object_buffer(sha1, type, size, buf, &eaten);
848+
obj = parse_object_buffer(oid->hash, type, size, buf, &eaten);
849849
if (!obj)
850850
die(_("invalid %s"), typename(type));
851851
if (do_fsck_object &&
@@ -960,7 +960,7 @@ static void resolve_delta(struct object_entry *delta_obj,
960960
typename(delta_obj->real_type),
961961
delta_obj->idx.oid.hash);
962962
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
963-
delta_obj->idx.oid.hash);
963+
&delta_obj->idx.oid);
964964
counter_lock();
965965
nr_resolved_deltas++;
966966
counter_unlock();
@@ -1149,7 +1149,7 @@ static void parse_pack_objects(unsigned char *sha1)
11491149
nr_delays++;
11501150
} else
11511151
sha1_object(data, NULL, obj->size, obj->type,
1152-
obj->idx.oid.hash);
1152+
&obj->idx.oid);
11531153
free(data);
11541154
display_progress(progress, i+1);
11551155
}
@@ -1176,7 +1176,7 @@ static void parse_pack_objects(unsigned char *sha1)
11761176
continue;
11771177
obj->real_type = obj->type;
11781178
sha1_object(NULL, obj, obj->size, obj->type,
1179-
obj->idx.oid.hash);
1179+
&obj->idx.oid);
11801180
nr_delays--;
11811181
}
11821182
if (nr_delays)

builtin/merge-tree.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ static int both_empty(struct name_entry *a, struct name_entry *b)
161161
return !(a->oid || b->oid);
162162
}
163163

164-
static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
164+
static struct merge_list *create_entry(unsigned stage, unsigned mode, const struct object_id *oid, const char *path)
165165
{
166166
struct merge_list *res = xcalloc(1, sizeof(*res));
167167

168168
res->stage = stage;
169169
res->path = path;
170170
res->mode = mode;
171-
res->blob = lookup_blob(sha1);
171+
res->blob = lookup_blob(oid->hash);
172172
return res;
173173
}
174174

@@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
188188
return;
189189

190190
path = traverse_path(info, result);
191-
orig = create_entry(2, ours->mode, ours->oid->hash, path);
192-
final = create_entry(0, result->mode, result->oid->hash, path);
191+
orig = create_entry(2, ours->mode, ours->oid, path);
192+
final = create_entry(0, result->mode, result->oid, path);
193193

194194
final->link = orig;
195195

@@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
239239
path = entry->path;
240240
else
241241
path = traverse_path(info, n);
242-
link = create_entry(stage, n->mode, n->oid->hash, path);
242+
link = create_entry(stage, n->mode, n->oid, path);
243243
link->link = entry;
244244
return link;
245245
}

object.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
190190

191191
obj = NULL;
192192
if (type == OBJ_BLOB) {
193-
struct blob *blob = lookup_blob(sha1);
193+
struct blob *blob = lookup_blob(oid.hash);
194194
if (blob) {
195195
if (parse_blob_buffer(blob, buffer, size))
196196
return NULL;
@@ -251,8 +251,11 @@ struct object *parse_object(const unsigned char *sha1)
251251
const unsigned char *repl = lookup_replace_object(sha1);
252252
void *buffer;
253253
struct object *obj;
254+
struct object_id oid;
255+
256+
hashcpy(oid.hash, sha1);
254257

255-
obj = lookup_object(sha1);
258+
obj = lookup_object(oid.hash);
256259
if (obj && obj->parsed)
257260
return obj;
258261

@@ -263,7 +266,7 @@ struct object *parse_object(const unsigned char *sha1)
263266
error("sha1 mismatch %s", sha1_to_hex(repl));
264267
return NULL;
265268
}
266-
parse_blob_buffer(lookup_blob(sha1), NULL, 0);
269+
parse_blob_buffer(lookup_blob(oid.hash), NULL, 0);
267270
return lookup_object(sha1);
268271
}
269272

0 commit comments

Comments
 (0)