Skip to content

Commit d5bf91f

Browse files
peffgitster
authored andcommitted
fast-export: add a "data" callback parameter to anonymize_str()
The anonymize_str() function takes a generator callback, but there's no way to pass extra context to it. Let's add the usual "void *data" parameter to the generator interface and pass it along. This is mildly annoying for existing callers, all of which pass NULL, but is necessary to avoid extra globals in some cases we'll add in a subsequent patch. While we're touching each of these callbacks, we can further observe that none of them use the existing orig/len parameters at all. This makes sense, since the point is for their output to have no discernable basis in the original (my original version had some notion that we might use a one-way function to obfuscate the names, but it was never implemented). So let's drop those extra parameters. If a caller really wants to do something with them, it can pass a struct through the new data parameter. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6416a86 commit d5bf91f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

builtin/fast-export.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ static int anonymized_entry_cmp(const void *unused_cmp_data,
155155
* is farmed out to the generate function.
156156
*/
157157
static const char *anonymize_str(struct hashmap *map,
158-
char *(*generate)(const char *, size_t),
159-
const char *orig, size_t len)
158+
char *(*generate)(void *),
159+
const char *orig, size_t len,
160+
void *data)
160161
{
161162
struct anonymized_entry_key key;
162163
struct anonymized_entry *ret;
@@ -172,7 +173,7 @@ static const char *anonymize_str(struct hashmap *map,
172173
if (!ret) {
173174
FLEX_ALLOC_MEM(ret, orig, orig, len);
174175
hashmap_entry_init(&ret->hash, key.hash.hash);
175-
ret->anon = generate(orig, len);
176+
ret->anon = generate(data);
176177
hashmap_put(map, &ret->hash);
177178
}
178179

@@ -187,12 +188,12 @@ static const char *anonymize_str(struct hashmap *map,
187188
*/
188189
static void anonymize_path(struct strbuf *out, const char *path,
189190
struct hashmap *map,
190-
char *(*generate)(const char *, size_t))
191+
char *(*generate)(void *))
191192
{
192193
while (*path) {
193194
const char *end_of_component = strchrnul(path, '/');
194195
size_t len = end_of_component - path;
195-
const char *c = anonymize_str(map, generate, path, len);
196+
const char *c = anonymize_str(map, generate, path, len, NULL);
196197
strbuf_addstr(out, c);
197198
path = end_of_component;
198199
if (*path)
@@ -367,7 +368,7 @@ static void print_path_1(const char *path)
367368
printf("%s", path);
368369
}
369370

370-
static char *anonymize_path_component(const char *path, size_t len)
371+
static char *anonymize_path_component(void *data)
371372
{
372373
static int counter;
373374
struct strbuf out = STRBUF_INIT;
@@ -389,7 +390,7 @@ static void print_path(const char *path)
389390
}
390391
}
391392

392-
static char *generate_fake_oid(const char *old, size_t len)
393+
static char *generate_fake_oid(void *data)
393394
{
394395
static uint32_t counter = 1; /* avoid null oid */
395396
const unsigned hashsz = the_hash_algo->rawsz;
@@ -405,7 +406,7 @@ static const char *anonymize_oid(const char *oid_hex)
405406
{
406407
static struct hashmap objs;
407408
size_t len = strlen(oid_hex);
408-
return anonymize_str(&objs, generate_fake_oid, oid_hex, len);
409+
return anonymize_str(&objs, generate_fake_oid, oid_hex, len, NULL);
409410
}
410411

411412
static void show_filemodify(struct diff_queue_struct *q,
@@ -502,7 +503,7 @@ static const char *find_encoding(const char *begin, const char *end)
502503
return bol;
503504
}
504505

505-
static char *anonymize_ref_component(const char *old, size_t len)
506+
static char *anonymize_ref_component(void *data)
506507
{
507508
static int counter;
508509
struct strbuf out = STRBUF_INIT;
@@ -555,7 +556,7 @@ static char *anonymize_commit_message(const char *old)
555556
return xstrfmt("subject %d\n\nbody\n", counter++);
556557
}
557558

558-
static char *anonymize_ident(const char *old, size_t len)
559+
static char *anonymize_ident(void *data)
559560
{
560561
static int counter;
561562
struct strbuf out = STRBUF_INIT;
@@ -598,7 +599,7 @@ static void anonymize_ident_line(const char **beg, const char **end)
598599

599600
len = split.mail_end - split.name_begin;
600601
ident = anonymize_str(&idents, anonymize_ident,
601-
split.name_begin, len);
602+
split.name_begin, len, NULL);
602603
strbuf_addstr(out, ident);
603604
strbuf_addch(out, ' ');
604605
strbuf_add(out, split.date_begin, split.tz_end - split.date_begin);
@@ -739,7 +740,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
739740
show_progress();
740741
}
741742

742-
static char *anonymize_tag(const char *old, size_t len)
743+
static char *anonymize_tag(void *data)
743744
{
744745
static int counter;
745746
struct strbuf out = STRBUF_INIT;
@@ -815,7 +816,7 @@ static void handle_tag(const char *name, struct tag *tag)
815816
if (message) {
816817
static struct hashmap tags;
817818
message = anonymize_str(&tags, anonymize_tag,
818-
message, message_size);
819+
message, message_size, NULL);
819820
}
820821
}
821822

0 commit comments

Comments
 (0)