Skip to content

Commit

Permalink
fast-export: store anonymized oids as hex strings
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Jun 24, 2020
1 parent b897bf5 commit 750bb32
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions builtin/fast-export.c
Expand Up @@ -387,16 +387,19 @@ static void *generate_fake_oid(const void *old, size_t *len)
{
static uint32_t counter = 1; /* avoid null oid */
const unsigned hashsz = the_hash_algo->rawsz;
unsigned char *out = xcalloc(hashsz, 1);
put_be32(out + hashsz - 4, counter++);
return out;
struct object_id oid;
char *hex = xmallocz(GIT_MAX_HEXSZ);

oidclr(&oid);
put_be32(oid.hash + hashsz - 4, counter++);
return oid_to_hex_r(hex, &oid);
}

static const struct object_id *anonymize_oid(const struct object_id *oid)
static const char *anonymize_oid(const char *oid_hex)
{
static struct hashmap objs;
size_t len = the_hash_algo->rawsz;
return anonymize_mem(&objs, generate_fake_oid, oid, &len);
size_t len = strlen(oid_hex);
return anonymize_mem(&objs, generate_fake_oid, oid_hex, &len);
}

static void show_filemodify(struct diff_queue_struct *q,
Expand Down Expand Up @@ -455,9 +458,9 @@ static void show_filemodify(struct diff_queue_struct *q,
*/
if (no_data || S_ISGITLINK(spec->mode))
printf("M %06o %s ", spec->mode,
oid_to_hex(anonymize ?
anonymize_oid(&spec->oid) :
&spec->oid));
anonymize ?
anonymize_oid(oid_to_hex(&spec->oid)) :
oid_to_hex(&spec->oid));
else {
struct object *object = lookup_object(the_repository,
&spec->oid);
Expand Down Expand Up @@ -712,9 +715,10 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
if (mark)
printf(":%d\n", mark);
else
printf("%s\n", oid_to_hex(anonymize ?
anonymize_oid(&obj->oid) :
&obj->oid));
printf("%s\n",
anonymize ?
anonymize_oid(oid_to_hex(&obj->oid)) :
oid_to_hex(&obj->oid));
i++;
}

Expand Down

0 comments on commit 750bb32

Please sign in to comment.