Skip to content

Commit 17e6545

Browse files
bk2204gitster
authored andcommitted
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>
1 parent d61d87b commit 17e6545

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
240240
buf = read_sha1_file(oid->hash, &type, &size);
241241
if (!buf)
242242
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)
244244
die("sha1 mismatch in blob %s", oid_to_hex(oid));
245245
object = parse_object_buffer(oid, type, size, buf, &eaten);
246246
}

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
13771377
if (!base_obj->data)
13781378
continue;
13791379

1380-
if (check_sha1_signature(d->oid.hash, base_obj->data,
1380+
if (check_object_signature(&d->oid, base_obj->data,
13811381
base_obj->size, type_name(type)))
13821382
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
13831383
base_obj->obj = append_obj_to_pack(f, d->oid.hash,

builtin/mktag.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
2727
const unsigned char *repl = lookup_replace_object(oid->hash);
2828

2929
if (buffer) {
30+
struct object_id reploid;
31+
hashcpy(reploid.hash, repl);
32+
3033
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);
3235
free(buffer);
3336
}
3437
return ret;

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
12361236
extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
12371237
extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
12381238

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);
12401240

12411241
extern int finalize_object_file(const char *tmpfile, const char *filename);
12421242

object.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ struct object *parse_object(const struct object_id *oid)
255255
if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
256256
(!obj && has_object_file(oid) &&
257257
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) {
259262
error("sha1 mismatch %s", oid_to_hex(oid));
260263
return NULL;
261264
}
@@ -265,7 +268,10 @@ struct object *parse_object(const struct object_id *oid)
265268

266269
buffer = read_sha1_file(oid->hash, &type, &size);
267270
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) {
269275
free(buffer);
270276
error("sha1 mismatch %s", sha1_to_hex(repl));
271277
return NULL;

pack-check.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int verify_packfile(struct packed_git *p,
126126

127127
if (type == OBJ_BLOB && big_file_threshold <= size) {
128128
/*
129-
* Let check_sha1_signature() check it with
129+
* Let check_object_signature() check it with
130130
* the streaming interface; no point slurping
131131
* the data in-core only to discard.
132132
*/
@@ -141,7 +141,7 @@ static int verify_packfile(struct packed_git *p,
141141
err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
142142
oid_to_hex(entries[i].oid.oid), p->pack_name,
143143
(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)))
145145
err = error("packed %s from %s is corrupt",
146146
oid_to_hex(entries[i].oid.oid), p->pack_name);
147147
else if (fn) {

sha1_file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ void *xmmap(void *start, size_t length,
784784
* With "map" == NULL, try reading the object named with "sha1" using
785785
* the streaming interface and rehash it to do the same.
786786
*/
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)
789789
{
790790
struct object_id real_oid;
791791
enum object_type obj_type;
@@ -796,10 +796,10 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
796796

797797
if (map) {
798798
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;
800800
}
801801

802-
st = open_istream(sha1, &obj_type, &size, NULL);
802+
st = open_istream(oid->hash, &obj_type, &size, NULL);
803803
if (!st)
804804
return -1;
805805

@@ -823,7 +823,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
823823
}
824824
the_hash_algo->final_fn(real_oid.hash, &c);
825825
close_istream(st);
826-
return hashcmp(sha1, real_oid.hash) ? -1 : 0;
826+
return oidcmp(oid, &real_oid) ? -1 : 0;
827827
}
828828

829829
int git_open_cloexec(const char *name, int flags)
@@ -2217,7 +2217,7 @@ int read_loose_object(const char *path,
22172217
git_inflate_end(&stream);
22182218
goto out;
22192219
}
2220-
if (check_sha1_signature(expected_oid->hash, *contents,
2220+
if (check_object_signature(expected_oid, *contents,
22212221
*size, type_name(*type))) {
22222222
error("sha1 mismatch for %s (expected %s)", path,
22232223
oid_to_hex(expected_oid));

0 commit comments

Comments
 (0)