fast-export: drop data parameter from anonymous generators

The anonymization code has a specific generator callback for each type of data (e.g., one for paths, one for oids, and so on). These all take a "data" parameter, but none of them use it for anything. Which is not surprising, as the point is to generate a new name independent of any input, and each function keeps its own static counter. We added the extra pointer in d5bf91fde44 (fast-export: add a "data" callback parameter to anonymize_str(), 2020-06-23) to handle --anonymize-map parsing, but that turned out to be awkward itself, and was recently dropped. So let's get rid of this "data" parameter that nobody is using, both from the generators and from anonymize_str() which plumbed it through. This simplifies the code, and makes -Wunused-parameter happier. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 22, 2023 at 13:42 UTC 65c756fff080e4798bbd1e3fa37263ed16c2d136
1 file changed +13 -14
builtin/fast-export.c
+13 -14
@@ -168,9 +168,8 @@ static struct anonymized_entry *add_anonymized_entry(struct hashmap *map,
168 * is farmed out to the generate function.
169 */
170 static const char *anonymize_str(struct hashmap *map,
171 - char *(*generate)(void *),
172 - const char *orig, size_t len,
173 - void *data)
171 + char *(*generate)(void),
172 + const char *orig, size_t len)
173 {
174 struct anonymized_entry_key key;
175 struct anonymized_entry *ret;
@@ -189,7 +188,7 @@ static const char *anonymize_str(struct hashmap *map,
188 /* ...and finally generate a new mapping if necessary */
189 if (!ret)
190 ret = add_anonymized_entry(map, key.hash.hash,
192 - orig, len, generate(data));
191 + orig, len, generate());
192
193 return ret->anon;
194 }
@@ -202,12 +201,12 @@ static const char *anonymize_str(struct hashmap *map,
201 */
202 static void anonymize_path(struct strbuf *out, const char *path,
203 struct hashmap *map,
205 - char *(*generate)(void *))
204 + char *(*generate)(void))
205 {
206 while (*path) {
207 const char *end_of_component = strchrnul(path, '/');
208 size_t len = end_of_component - path;
210 - const char *c = anonymize_str(map, generate, path, len, NULL);
209 + const char *c = anonymize_str(map, generate, path, len);
210 strbuf_addstr(out, c);
211 path = end_of_component;
212 if (*path)
@@ -382,7 +381,7 @@ static void print_path_1(const char *path)
381 printf("%s", path);
382 }
383
385 -static char *anonymize_path_component(void *data)
384 +static char *anonymize_path_component(void)
385 {
386 static int counter;
387 struct strbuf out = STRBUF_INIT;
@@ -404,7 +403,7 @@ static void print_path(const char *path)
403 }
404 }
405
407 -static char *generate_fake_oid(void *data)
406 +static char *generate_fake_oid(void)
407 {
408 static uint32_t counter = 1; /* avoid null oid */
409 const unsigned hashsz = the_hash_algo->rawsz;
@@ -420,7 +419,7 @@ static const char *anonymize_oid(const char *oid_hex)
419 {
420 static struct hashmap objs;
421 size_t len = strlen(oid_hex);
423 - return anonymize_str(&objs, generate_fake_oid, oid_hex, len, NULL);
422 + return anonymize_str(&objs, generate_fake_oid, oid_hex, len);
423 }
424
425 static void show_filemodify(struct diff_queue_struct *q,
@@ -517,7 +516,7 @@ static const char *find_encoding(const char *begin, const char *end)
516 return bol;
517 }
518
520 -static char *anonymize_ref_component(void *data)
519 +static char *anonymize_ref_component(void)
520 {
521 static int counter;
522 struct strbuf out = STRBUF_INIT;
@@ -563,7 +562,7 @@ static char *anonymize_commit_message(const char *old)
562 return xstrfmt("subject %d\n\nbody\n", counter++);
563 }
564
566 -static char *anonymize_ident(void *data)
565 +static char *anonymize_ident(void)
566 {
567 static int counter;
568 struct strbuf out = STRBUF_INIT;
@@ -606,7 +605,7 @@ static void anonymize_ident_line(const char **beg, const char **end)
605
606 len = split.mail_end - split.name_begin;
607 ident = anonymize_str(&idents, anonymize_ident,
609 - split.name_begin, len, NULL);
608 + split.name_begin, len);
609 strbuf_addstr(out, ident);
610 strbuf_addch(out, ' ');
611 strbuf_add(out, split.date_begin, split.tz_end - split.date_begin);
@@ -747,7 +746,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
746 show_progress();
747 }
748
750 -static char *anonymize_tag(void *data)
749 +static char *anonymize_tag(void)
750 {
751 static int counter;
752 struct strbuf out = STRBUF_INIT;
@@ -809,7 +808,7 @@ static void handle_tag(const char *name, struct tag *tag)
808 if (message) {
809 static struct hashmap tags;
810 message = anonymize_str(&tags, anonymize_tag,
812 - message, message_size, NULL);
811 + message, message_size);
812 message_size = strlen(message);
813 }
814 }