145
* the same anonymized string with another. The actual generation
146
* is farmed out to the generate function.
147
*/
148
-static const void *anonymize_mem(struct hashmap *map,
149
- void *(*generate)(const void *, size_t *),
150
- const void *orig, size_t *len)
148
+static const char *anonymize_str(struct hashmap *map,
149
+ char *(*generate)(const char *, size_t),
150
+ const char *orig, size_t len)
151
{
152
struct anonymized_entry key, *ret;
153
154
if (!map->cmpfn)
155
hashmap_init(map, anonymized_entry_cmp, NULL, 0);
156
157
- hashmap_entry_init(&key.hash, memhash(orig, *len));
157
+ hashmap_entry_init(&key.hash, memhash(orig, len));
158
key.orig = orig;
159
- key.orig_len = *len;
159
+ key.orig_len = len;
160
ret = hashmap_get_entry(map, &key, hash, NULL);
161
162
if (!ret) {
163
ret = xmalloc(sizeof(*ret));
164
hashmap_entry_init(&ret->hash, key.hash.hash);
165
- ret->orig = xmemdupz(orig, *len);
166
- ret->orig_len = *len;
165
+ ret->orig = xmemdupz(orig, len);
166
+ ret->orig_len = len;
167
ret->anon = generate(orig, len);
168
- ret->anon_len = *len;
168
+ ret->anon_len = strlen(ret->anon);
169
hashmap_put(map, &ret->hash);
170
}
171
172
- *len = ret->anon_len;
172
return ret->anon;
173
}
174
180
*/
181
static void anonymize_path(struct strbuf *out, const char *path,
182
struct hashmap *map,
184
- void *(*generate)(const void *, size_t *))
183
+ char *(*generate)(const char *, size_t))
184
{
185
while (*path) {
186
const char *end_of_component = strchrnul(path, '/');
187
size_t len = end_of_component - path;
189
- const char *c = anonymize_mem(map, generate, path, &len);
190
- strbuf_add(out, c, len);
188
+ const char *c = anonymize_str(map, generate, path, len);
189
+ strbuf_addstr(out, c);
190
path = end_of_component;
191
if (*path)
192
strbuf_addch(out, *path++);
360
printf("%s", path);
361
}
362
364
-static void *anonymize_path_component(const void *path, size_t *len)
363
+static char *anonymize_path_component(const char *path, size_t len)
364
{
365
static int counter;
366
struct strbuf out = STRBUF_INIT;
367
strbuf_addf(&out, "path%d", counter++);
369
- return strbuf_detach(&out, len);
368
+ return strbuf_detach(&out, NULL);
369
}
370
371
static void print_path(const char *path)
382
}
383
}
384
386
-static void *generate_fake_oid(const void *old, size_t *len)
385
+static char *generate_fake_oid(const char *old, size_t len)
386
{
387
static uint32_t counter = 1; /* avoid null oid */
388
const unsigned hashsz = the_hash_algo->rawsz;
398
{
399
static struct hashmap objs;
400
size_t len = strlen(oid_hex);
402
- return anonymize_mem(&objs, generate_fake_oid, oid_hex, &len);
401
+ return anonymize_str(&objs, generate_fake_oid, oid_hex, len);
402
}
403
404
static void show_filemodify(struct diff_queue_struct *q,
495
return bol;
496
}
497
499
-static void *anonymize_ref_component(const void *old, size_t *len)
498
+static char *anonymize_ref_component(const char *old, size_t len)
499
{
500
static int counter;
501
struct strbuf out = STRBUF_INIT;
502
strbuf_addf(&out, "ref%d", counter++);
504
- return strbuf_detach(&out, len);
503
+ return strbuf_detach(&out, NULL);
504
}
505
506
static const char *anonymize_refname(const char *refname)
549
}
550
551
static struct hashmap idents;
553
-static void *anonymize_ident(const void *old, size_t *len)
552
+static char *anonymize_ident(const char *old, size_t len)
553
{
554
static int counter;
555
struct strbuf out = STRBUF_INIT;
556
strbuf_addf(&out, "User %d <user%d@example.com>", counter, counter);
557
counter++;
559
- return strbuf_detach(&out, len);
558
+ return strbuf_detach(&out, NULL);
559
}
560
561
/*
590
size_t len;
591
592
len = split.mail_end - split.name_begin;
594
- ident = anonymize_mem(&idents, anonymize_ident,
595
- split.name_begin, &len);
596
- strbuf_add(out, ident, len);
593
+ ident = anonymize_str(&idents, anonymize_ident,
594
+ split.name_begin, len);
595
+ strbuf_addstr(out, ident);
596
strbuf_addch(out, ' ');
597
strbuf_add(out, split.date_begin, split.tz_end - split.date_begin);
598
} else {
732
show_progress();
733
}
734
736
-static void *anonymize_tag(const void *old, size_t *len)
735
+static char *anonymize_tag(const char *old, size_t len)
736
{
737
static int counter;
738
struct strbuf out = STRBUF_INIT;
739
strbuf_addf(&out, "tag message %d", counter++);
741
- return strbuf_detach(&out, len);
740
+ return strbuf_detach(&out, NULL);
741
}
742
743
static void handle_tail(struct object_array *commits, struct rev_info *revs,
807
name = anonymize_refname(name);
808
if (message) {
809
static struct hashmap tags;
811
- message = anonymize_mem(&tags, anonymize_tag,
812
- message, &message_size);
810
+ message = anonymize_str(&tags, anonymize_tag,
811
+ message, message_size);
812
}
813
}
814