Skip to content

Commit 843b9e6

Browse files
newrengitster
authored andcommitted
fast-export: convert sha1 to oid
Rename anonymize_sha1() to anonymize_oid(() and change its signature, and switch from sha1_to_hex() to oid_to_hex() and from GIT_SHA1_RAWSZ to the_hash_algo->rawsz. Also change a comment and a die string to mention oid instead of sha1. Signed-off-by: Elijah Newren <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d166e6a commit 843b9e6

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

builtin/fast-export.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static void export_blob(const struct object_id *oid)
243243
if (!buf)
244244
die("could not read blob %s", oid_to_hex(oid));
245245
if (check_object_signature(oid, buf, size, type_name(type)) < 0)
246-
die("sha1 mismatch in blob %s", oid_to_hex(oid));
246+
die("oid mismatch in blob %s", oid_to_hex(oid));
247247
object = parse_object_buffer(the_repository, oid, type,
248248
size, buf, &eaten);
249249
}
@@ -330,17 +330,18 @@ static void print_path(const char *path)
330330

331331
static void *generate_fake_oid(const void *old, size_t *len)
332332
{
333-
static uint32_t counter = 1; /* avoid null sha1 */
334-
unsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1);
335-
put_be32(out + GIT_SHA1_RAWSZ - 4, counter++);
333+
static uint32_t counter = 1; /* avoid null oid */
334+
const unsigned hashsz = the_hash_algo->rawsz;
335+
unsigned char *out = xcalloc(hashsz, 1);
336+
put_be32(out + hashsz - 4, counter++);
336337
return out;
337338
}
338339

339-
static const unsigned char *anonymize_sha1(const struct object_id *oid)
340+
static const struct object_id *anonymize_oid(const struct object_id *oid)
340341
{
341-
static struct hashmap sha1s;
342-
size_t len = GIT_SHA1_RAWSZ;
343-
return anonymize_mem(&sha1s, generate_fake_oid, oid, &len);
342+
static struct hashmap objs;
343+
size_t len = the_hash_algo->rawsz;
344+
return anonymize_mem(&objs, generate_fake_oid, oid, &len);
344345
}
345346

346347
static void show_filemodify(struct diff_queue_struct *q,
@@ -399,9 +400,9 @@ static void show_filemodify(struct diff_queue_struct *q,
399400
*/
400401
if (no_data || S_ISGITLINK(spec->mode))
401402
printf("M %06o %s ", spec->mode,
402-
sha1_to_hex(anonymize ?
403-
anonymize_sha1(&spec->oid) :
404-
spec->oid.hash));
403+
oid_to_hex(anonymize ?
404+
anonymize_oid(&spec->oid) :
405+
&spec->oid));
405406
else {
406407
struct object *object = lookup_object(the_repository,
407408
spec->oid.hash);
@@ -988,7 +989,7 @@ static void handle_deletes(void)
988989
continue;
989990

990991
printf("reset %s\nfrom %s\n\n",
991-
refspec->dst, sha1_to_hex(null_sha1));
992+
refspec->dst, oid_to_hex(&null_oid));
992993
}
993994
}
994995

0 commit comments

Comments
 (0)