@@ -110,7 +110,7 @@ static struct decoration idnums;
110
110
static uint32_t last_idnum ;
111
111
struct anonymized_entry {
112
112
struct hashmap_entry hash ;
113
- const char * anon ;
113
+ char * anon ;
114
114
const char orig [FLEX_ARRAY ];
115
115
};
116
116
@@ -139,43 +139,56 @@ static int anonymized_entry_cmp(const void *cmp_data UNUSED,
139
139
return strcmp (a -> orig , b -> orig );
140
140
}
141
141
142
+ static struct anonymized_entry * add_anonymized_entry (struct hashmap * map ,
143
+ unsigned hash ,
144
+ const char * orig , size_t len ,
145
+ char * anon )
146
+ {
147
+ struct anonymized_entry * ret , * old ;
148
+
149
+ if (!map -> cmpfn )
150
+ hashmap_init (map , anonymized_entry_cmp , NULL , 0 );
151
+
152
+ FLEX_ALLOC_MEM (ret , orig , orig , len );
153
+ hashmap_entry_init (& ret -> hash , hash );
154
+ ret -> anon = anon ;
155
+ old = hashmap_put_entry (map , ret , hash );
156
+
157
+ if (old ) {
158
+ free (old -> anon );
159
+ free (old );
160
+ }
161
+
162
+ return ret ;
163
+ }
164
+
142
165
/*
143
166
* Basically keep a cache of X->Y so that we can repeatedly replace
144
167
* the same anonymized string with another. The actual generation
145
168
* is farmed out to the generate function.
146
169
*/
147
170
static const char * anonymize_str (struct hashmap * map ,
148
- char * (* generate )(void * ),
149
- const char * orig , size_t len ,
150
- void * data )
171
+ char * (* generate )(void ),
172
+ const char * orig , size_t len )
151
173
{
152
174
struct anonymized_entry_key key ;
153
175
struct anonymized_entry * ret ;
154
176
155
- if (!map -> cmpfn )
156
- hashmap_init (map , anonymized_entry_cmp , NULL , 0 );
157
-
158
177
hashmap_entry_init (& key .hash , memhash (orig , len ));
159
178
key .orig = orig ;
160
179
key .orig_len = len ;
161
180
162
181
/* First check if it's a token the user configured manually... */
163
- if (anonymized_seeds .cmpfn )
164
- ret = hashmap_get_entry (& anonymized_seeds , & key , hash , & key );
165
- else
166
- ret = NULL ;
182
+ ret = hashmap_get_entry (& anonymized_seeds , & key , hash , & key );
167
183
168
184
/* ...otherwise check if we've already seen it in this context... */
169
185
if (!ret )
170
186
ret = hashmap_get_entry (map , & key , hash , & key );
171
187
172
188
/* ...and finally generate a new mapping if necessary */
173
- if (!ret ) {
174
- FLEX_ALLOC_MEM (ret , orig , orig , len );
175
- hashmap_entry_init (& ret -> hash , key .hash .hash );
176
- ret -> anon = generate (data );
177
- hashmap_put (map , & ret -> hash );
178
- }
189
+ if (!ret )
190
+ ret = add_anonymized_entry (map , key .hash .hash ,
191
+ orig , len , generate ());
179
192
180
193
return ret -> anon ;
181
194
}
@@ -188,12 +201,12 @@ static const char *anonymize_str(struct hashmap *map,
188
201
*/
189
202
static void anonymize_path (struct strbuf * out , const char * path ,
190
203
struct hashmap * map ,
191
- char * (* generate )(void * ))
204
+ char * (* generate )(void ))
192
205
{
193
206
while (* path ) {
194
207
const char * end_of_component = strchrnul (path , '/' );
195
208
size_t len = end_of_component - path ;
196
- const char * c = anonymize_str (map , generate , path , len , NULL );
209
+ const char * c = anonymize_str (map , generate , path , len );
197
210
strbuf_addstr (out , c );
198
211
path = end_of_component ;
199
212
if (* path )
@@ -368,7 +381,7 @@ static void print_path_1(const char *path)
368
381
printf ("%s" , path );
369
382
}
370
383
371
- static char * anonymize_path_component (void * data )
384
+ static char * anonymize_path_component (void )
372
385
{
373
386
static int counter ;
374
387
struct strbuf out = STRBUF_INIT ;
@@ -390,7 +403,7 @@ static void print_path(const char *path)
390
403
}
391
404
}
392
405
393
- static char * generate_fake_oid (void * data )
406
+ static char * generate_fake_oid (void )
394
407
{
395
408
static uint32_t counter = 1 ; /* avoid null oid */
396
409
const unsigned hashsz = the_hash_algo -> rawsz ;
@@ -406,7 +419,7 @@ static const char *anonymize_oid(const char *oid_hex)
406
419
{
407
420
static struct hashmap objs ;
408
421
size_t len = strlen (oid_hex );
409
- return anonymize_str (& objs , generate_fake_oid , oid_hex , len , NULL );
422
+ return anonymize_str (& objs , generate_fake_oid , oid_hex , len );
410
423
}
411
424
412
425
static void show_filemodify (struct diff_queue_struct * q ,
@@ -503,7 +516,7 @@ static const char *find_encoding(const char *begin, const char *end)
503
516
return bol ;
504
517
}
505
518
506
- static char * anonymize_ref_component (void * data )
519
+ static char * anonymize_ref_component (void )
507
520
{
508
521
static int counter ;
509
522
struct strbuf out = STRBUF_INIT ;
@@ -543,13 +556,13 @@ static const char *anonymize_refname(const char *refname)
543
556
* We do not even bother to cache commit messages, as they are unlikely
544
557
* to be repeated verbatim, and it is not that interesting when they are.
545
558
*/
546
- static char * anonymize_commit_message (const char * old )
559
+ static char * anonymize_commit_message (void )
547
560
{
548
561
static int counter ;
549
562
return xstrfmt ("subject %d\n\nbody\n" , counter ++ );
550
563
}
551
564
552
- static char * anonymize_ident (void * data )
565
+ static char * anonymize_ident (void )
553
566
{
554
567
static int counter ;
555
568
struct strbuf out = STRBUF_INIT ;
@@ -592,7 +605,7 @@ static void anonymize_ident_line(const char **beg, const char **end)
592
605
593
606
len = split .mail_end - split .name_begin ;
594
607
ident = anonymize_str (& idents , anonymize_ident ,
595
- split .name_begin , len , NULL );
608
+ split .name_begin , len );
596
609
strbuf_addstr (out , ident );
597
610
strbuf_addch (out , ' ' );
598
611
strbuf_add (out , split .date_begin , split .tz_end - split .date_begin );
@@ -670,7 +683,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
670
683
671
684
mark_next_object (& commit -> object );
672
685
if (anonymize ) {
673
- reencoded = anonymize_commit_message (message );
686
+ reencoded = anonymize_commit_message ();
674
687
} else if (encoding ) {
675
688
switch (reencode_mode ) {
676
689
case REENCODE_YES :
@@ -733,7 +746,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
733
746
show_progress ();
734
747
}
735
748
736
- static char * anonymize_tag (void * data )
749
+ static char * anonymize_tag (void )
737
750
{
738
751
static int counter ;
739
752
struct strbuf out = STRBUF_INIT ;
@@ -795,7 +808,7 @@ static void handle_tag(const char *name, struct tag *tag)
795
808
if (message ) {
796
809
static struct hashmap tags ;
797
810
message = anonymize_str (& tags , anonymize_tag ,
798
- message , message_size , NULL );
811
+ message , message_size );
799
812
message_size = strlen (message );
800
813
}
801
814
}
@@ -1126,11 +1139,6 @@ static void handle_deletes(void)
1126
1139
}
1127
1140
}
1128
1141
1129
- static char * anonymize_seed (void * data )
1130
- {
1131
- return xstrdup (data );
1132
- }
1133
-
1134
1142
static int parse_opt_anonymize_map (const struct option * opt ,
1135
1143
const char * arg , int unset )
1136
1144
{
@@ -1152,7 +1160,8 @@ static int parse_opt_anonymize_map(const struct option *opt,
1152
1160
if (!keylen || !* value )
1153
1161
return error (_ ("--anonymize-map token cannot be empty" ));
1154
1162
1155
- anonymize_str (map , anonymize_seed , arg , keylen , (void * )value );
1163
+ add_anonymized_entry (map , memhash (arg , keylen ), arg , keylen ,
1164
+ xstrdup (value ));
1156
1165
1157
1166
return 0 ;
1158
1167
}
0 commit comments