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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 6, 2017 at 22:10 UTC
3e9309815da9aab4e13195b7c6a52c1f7161562a
3 files changed
+25
-22
builtin/index-pack.c
+14
-14
@@ -785,7 +785,7 @@ static int check_collison(struct object_entry *entry)
785
786
static void sha1_object(const void *data, struct object_entry *obj_entry,
787
unsigned long size, enum object_type type,
788
- const unsigned char *sha1)
788
+ const struct object_id *oid)
789
{
790
void *new_data = NULL;
791
int collision_test_needed = 0;
@@ -794,7 +794,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
794
795
if (startup_info->have_repository) {
796
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);
798
read_unlock();
799
}
800
@@ -809,31 +809,31 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
809
enum object_type has_type;
810
unsigned long has_size;
811
read_lock();
812
- has_type = sha1_object_info(sha1, &has_size);
812
+ has_type = sha1_object_info(oid->hash, &has_size);
813
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));
815
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);
818
read_unlock();
819
if (!data)
820
data = new_data = get_data_from_pack(obj_entry);
821
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));
823
if (size != has_size || type != has_type ||
824
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));
826
free(has_data);
827
}
828
829
if (strict) {
830
read_lock();
831
if (type == OBJ_BLOB) {
832
- struct blob *blob = lookup_blob(sha1);
832
+ struct blob *blob = lookup_blob(oid->hash);
833
if (blob)
834
blob->object.flags |= FLAG_CHECKED;
835
else
836
- die(_("invalid blob object %s"), sha1_to_hex(sha1));
836
+ die(_("invalid blob object %s"), oid_to_hex(oid));
837
} else {
838
struct object *obj;
839
int eaten;
@@ -845,7 +845,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
845
* we do not need to free the memory here, as the
846
* buf is deleted by the caller.
847
*/
848
- obj = parse_object_buffer(sha1, type, size, buf, &eaten);
848
+ obj = parse_object_buffer(oid->hash, type, size, buf, &eaten);
849
if (!obj)
850
die(_("invalid %s"), typename(type));
851
if (do_fsck_object &&
@@ -960,7 +960,7 @@ static void resolve_delta(struct object_entry *delta_obj,
960
typename(delta_obj->real_type),
961
delta_obj->idx.oid.hash);
962
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
963
- delta_obj->idx.oid.hash);
963
+ &delta_obj->idx.oid);
964
counter_lock();
965
nr_resolved_deltas++;
966
counter_unlock();
@@ -1149,7 +1149,7 @@ static void parse_pack_objects(unsigned char *sha1)
1149
nr_delays++;
1150
} else
1151
sha1_object(data, NULL, obj->size, obj->type,
1152
- obj->idx.oid.hash);
1152
+ &obj->idx.oid);
1153
free(data);
1154
display_progress(progress, i+1);
1155
}
@@ -1176,7 +1176,7 @@ static void parse_pack_objects(unsigned char *sha1)
1176
continue;
1177
obj->real_type = obj->type;
1178
sha1_object(NULL, obj, obj->size, obj->type,
1179
- obj->idx.oid.hash);
1179
+ &obj->idx.oid);
1180
nr_delays--;
1181
}
1182
if (nr_delays)
builtin/merge-tree.c
+5
-5
@@ -161,14 +161,14 @@ static int both_empty(struct name_entry *a, struct name_entry *b)
161
return !(a->oid || b->oid);
162
}
163
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)
165
{
166
struct merge_list *res = xcalloc(1, sizeof(*res));
167
168
res->stage = stage;
169
res->path = path;
170
res->mode = mode;
171
- res->blob = lookup_blob(sha1);
171
+ res->blob = lookup_blob(oid->hash);
172
return res;
173
}
174
@@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
188
return;
189
190
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);
193
194
final->link = orig;
195
@@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
239
path = entry->path;
240
else
241
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);
243
link->link = entry;
244
return link;
245
}
object.c
+6
-3
@@ -190,7 +190,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
190
191
obj = NULL;
192
if (type == OBJ_BLOB) {
193
- struct blob *blob = lookup_blob(sha1);
193
+ struct blob *blob = lookup_blob(oid.hash);
194
if (blob) {
195
if (parse_blob_buffer(blob, buffer, size))
196
return NULL;
@@ -251,8 +251,11 @@ struct object *parse_object(const unsigned char *sha1)
251
const unsigned char *repl = lookup_replace_object(sha1);
252
void *buffer;
253
struct object *obj;
254
+ struct object_id oid;
255
+
256
+ hashcpy(oid.hash, sha1);
257
255
- obj = lookup_object(sha1);
258
+ obj = lookup_object(oid.hash);
259
if (obj && obj->parsed)
260
return obj;
261
@@ -263,7 +266,7 @@ struct object *parse_object(const unsigned char *sha1)
266
error("sha1 mismatch %s", sha1_to_hex(repl));
267
return NULL;
268
}
266
- parse_blob_buffer(lookup_blob(sha1), NULL, 0);
269
+ parse_blob_buffer(lookup_blob(oid.hash), NULL, 0);
270
return lookup_object(sha1);
271
}
272