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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 23, 2020 at 11:24 UTC
750bb32589ea157bfe522a66f814a0124c97c41b
1 file changed
+16
-12
builtin/fast-export.c
+16
-12
@@ -387,16 +387,19 @@ static void *generate_fake_oid(const void *old, size_t *len)
387
{
388
static uint32_t counter = 1; /* avoid null oid */
389
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);
396
}
397
395
-static const struct object_id *anonymize_oid(const struct object_id *oid)
398
+static const char *anonymize_oid(const char *oid_hex)
399
{
400
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);
403
}
404
405
static void show_filemodify(struct diff_queue_struct *q,
@@ -455,9 +458,9 @@ static void show_filemodify(struct diff_queue_struct *q,
458
*/
459
if (no_data || S_ISGITLINK(spec->mode))
460
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));
464
else {
465
struct object *object = lookup_object(the_repository,
466
&spec->oid);
@@ -712,9 +715,10 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
715
if (mark)
716
printf(":%d\n", mark);
717
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));
722
i++;
723
}
724