Skip to content

Commit 750bb32

Browse files
peffgitster
authored andcommitted
fast-export: store anonymized oids as hex strings
When fast-export stores anonymized oids, it does so as binary strings. And while the anonymous mapping storage is binary-clean (at least as of the previous commit), this will become awkward when we start exposing more of it to the user. In particular, if we allow a method for retaining token "foo", then users may want to specify a hex oid as such a token. Let's just switch to storing the hex strings. The difference in memory usage is negligible (especially considering how infrequently we'd generally store an oid compared to, say, path components). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b897bf5 commit 750bb32

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

builtin/fast-export.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,19 @@ static void *generate_fake_oid(const void *old, size_t *len)
387387
{
388388
static uint32_t counter = 1; /* avoid null oid */
389389
const unsigned hashsz = the_hash_algo->rawsz;
390-
unsigned char *out = xcalloc(hashsz, 1);
391-
put_be32(out + hashsz - 4, counter++);
392-
return out;
390+
struct object_id oid;
391+
char *hex = xmallocz(GIT_MAX_HEXSZ);
392+
393+
oidclr(&oid);
394+
put_be32(oid.hash + hashsz - 4, counter++);
395+
return oid_to_hex_r(hex, &oid);
393396
}
394397

395-
static const struct object_id *anonymize_oid(const struct object_id *oid)
398+
static const char *anonymize_oid(const char *oid_hex)
396399
{
397400
static struct hashmap objs;
398-
size_t len = the_hash_algo->rawsz;
399-
return anonymize_mem(&objs, generate_fake_oid, oid, &len);
401+
size_t len = strlen(oid_hex);
402+
return anonymize_mem(&objs, generate_fake_oid, oid_hex, &len);
400403
}
401404

402405
static void show_filemodify(struct diff_queue_struct *q,
@@ -455,9 +458,9 @@ static void show_filemodify(struct diff_queue_struct *q,
455458
*/
456459
if (no_data || S_ISGITLINK(spec->mode))
457460
printf("M %06o %s ", spec->mode,
458-
oid_to_hex(anonymize ?
459-
anonymize_oid(&spec->oid) :
460-
&spec->oid));
461+
anonymize ?
462+
anonymize_oid(oid_to_hex(&spec->oid)) :
463+
oid_to_hex(&spec->oid));
461464
else {
462465
struct object *object = lookup_object(the_repository,
463466
&spec->oid);
@@ -712,9 +715,10 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
712715
if (mark)
713716
printf(":%d\n", mark);
714717
else
715-
printf("%s\n", oid_to_hex(anonymize ?
716-
anonymize_oid(&obj->oid) :
717-
&obj->oid));
718+
printf("%s\n",
719+
anonymize ?
720+
anonymize_oid(oid_to_hex(&obj->oid)) :
721+
oid_to_hex(&obj->oid));
718722
i++;
719723
}
720724

0 commit comments

Comments
 (0)