sha1_file: convert check_sha1_signature to struct object_id
Convert this function to take a pointer to struct object_id and rename it check_object_signature. Introduce temporaries to convert the return values of lookup_replace_object and lookup_replace_object_extended into struct object_id. The temporaries are needed because in order to convert lookup_replace_object, open_istream needs to be converted, and open_istream needs check_sha1_signature to be converted, causing a loop of dependencies. The temporaries will be removed in a future patch. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 12, 2018 at 02:27 UTC
17e65451e305b7501fddec35125bf5d39a4cdcac
7 files changed
+23
-14
builtin/fast-export.c
+1
-1
@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
240
buf = read_sha1_file(oid->hash, &type, &size);
241
if (!buf)
242
die ("Could not read blob %s", oid_to_hex(oid));
243
- if (check_sha1_signature(oid->hash, buf, size, type_name(type)) < 0)
243
+ if (check_object_signature(oid, buf, size, type_name(type)) < 0)
244
die("sha1 mismatch in blob %s", oid_to_hex(oid));
245
object = parse_object_buffer(oid, type, size, buf, &eaten);
246
}
builtin/index-pack.c
+1
-1
@@ -1377,7 +1377,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
1377
if (!base_obj->data)
1378
continue;
1379
1380
- if (check_sha1_signature(d->oid.hash, base_obj->data,
1380
+ if (check_object_signature(&d->oid, base_obj->data,
1381
base_obj->size, type_name(type)))
1382
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
1383
base_obj->obj = append_obj_to_pack(f, d->oid.hash,
builtin/mktag.c
+4
-1
@@ -27,8 +27,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
27
const unsigned char *repl = lookup_replace_object(oid->hash);
28
29
if (buffer) {
30
+ struct object_id reploid;
31
+ hashcpy(reploid.hash, repl);
32
+
33
if (type == type_from_string(expected_type))
31
- ret = check_sha1_signature(repl, buffer, size, expected_type);
34
+ ret = check_object_signature(&reploid, buffer, size, expected_type);
35
free(buffer);
36
}
37
return ret;
cache.h
+1
-1
@@ -1236,7 +1236,7 @@ extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
1236
extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
1237
extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
1238
1239
-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
1239
+extern int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type);
1240
1241
extern int finalize_object_file(const char *tmpfile, const char *filename);
1242
object.c
+8
-2
@@ -255,7 +255,10 @@ struct object *parse_object(const struct object_id *oid)
255
if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
256
(!obj && has_object_file(oid) &&
257
sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
258
- if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
258
+ struct object_id reploid;
259
+ hashcpy(reploid.hash, repl);
260
+
261
+ if (check_object_signature(&reploid, NULL, 0, NULL) < 0) {
262
error("sha1 mismatch %s", oid_to_hex(oid));
263
return NULL;
264
}
@@ -265,7 +268,10 @@ struct object *parse_object(const struct object_id *oid)
268
269
buffer = read_sha1_file(oid->hash, &type, &size);
270
if (buffer) {
268
- if (check_sha1_signature(repl, buffer, size, type_name(type)) < 0) {
271
+ struct object_id reploid;
272
+ hashcpy(reploid.hash, repl);
273
+
274
+ if (check_object_signature(&reploid, buffer, size, type_name(type)) < 0) {
275
free(buffer);
276
error("sha1 mismatch %s", sha1_to_hex(repl));
277
return NULL;
pack-check.c
+2
-2
@@ -126,7 +126,7 @@ static int verify_packfile(struct packed_git *p,
126
127
if (type == OBJ_BLOB && big_file_threshold <= size) {
128
/*
129
- * Let check_sha1_signature() check it with
129
+ * Let check_object_signature() check it with
130
* the streaming interface; no point slurping
131
* the data in-core only to discard.
132
*/
@@ -141,7 +141,7 @@ static int verify_packfile(struct packed_git *p,
141
err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
142
oid_to_hex(entries[i].oid.oid), p->pack_name,
143
(uintmax_t)entries[i].offset);
144
- else if (check_sha1_signature(entries[i].oid.hash, data, size, type_name(type)))
144
+ else if (check_object_signature(entries[i].oid.oid, data, size, type_name(type)))
145
err = error("packed %s from %s is corrupt",
146
oid_to_hex(entries[i].oid.oid), p->pack_name);
147
else if (fn) {
sha1_file.c
+6
-6
@@ -784,8 +784,8 @@ void *xmmap(void *start, size_t length,
784
* With "map" == NULL, try reading the object named with "sha1" using
785
* the streaming interface and rehash it to do the same.
786
*/
787
-int check_sha1_signature(const unsigned char *sha1, void *map,
788
- unsigned long size, const char *type)
787
+int check_object_signature(const struct object_id *oid, void *map,
788
+ unsigned long size, const char *type)
789
{
790
struct object_id real_oid;
791
enum object_type obj_type;
@@ -796,10 +796,10 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
796
797
if (map) {
798
hash_object_file(map, size, type, &real_oid);
799
- return hashcmp(sha1, real_oid.hash) ? -1 : 0;
799
+ return oidcmp(oid, &real_oid) ? -1 : 0;
800
}
801
802
- st = open_istream(sha1, &obj_type, &size, NULL);
802
+ st = open_istream(oid->hash, &obj_type, &size, NULL);
803
if (!st)
804
return -1;
805
@@ -823,7 +823,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
823
}
824
the_hash_algo->final_fn(real_oid.hash, &c);
825
close_istream(st);
826
- return hashcmp(sha1, real_oid.hash) ? -1 : 0;
826
+ return oidcmp(oid, &real_oid) ? -1 : 0;
827
}
828
829
int git_open_cloexec(const char *name, int flags)
@@ -2217,7 +2217,7 @@ int read_loose_object(const char *path,
2217
git_inflate_end(&stream);
2218
goto out;
2219
}
2220
- if (check_sha1_signature(expected_oid->hash, *contents,
2220
+ if (check_object_signature(expected_oid, *contents,
2221
*size, type_name(*type))) {
2222
error("sha1 mismatch for %s (expected %s)", path,
2223
oid_to_hex(expected_oid));