1010#include "shortlog.h"
1111#include "parse-options.h"
1212#include "trailer.h"
13+ #include "strmap.h"
1314
1415static char const * const shortlog_usage [] = {
1516 N_ ("git shortlog [<options>] [<revision-range>] [[--] <path>...]" ),
@@ -169,60 +170,6 @@ static void read_from_stdin(struct shortlog *log)
169170 strbuf_release (& oneline );
170171}
171172
172- struct strset_item {
173- struct hashmap_entry ent ;
174- char value [FLEX_ARRAY ];
175- };
176-
177- struct strset {
178- struct hashmap map ;
179- };
180-
181- #define STRSET_INIT { { NULL } }
182-
183- static int strset_item_hashcmp (const void * hash_data ,
184- const struct hashmap_entry * entry ,
185- const struct hashmap_entry * entry_or_key ,
186- const void * keydata )
187- {
188- const struct strset_item * a , * b ;
189-
190- a = container_of (entry , const struct strset_item , ent );
191- if (keydata )
192- return strcmp (a -> value , keydata );
193-
194- b = container_of (entry_or_key , const struct strset_item , ent );
195- return strcmp (a -> value , b -> value );
196- }
197-
198- /*
199- * Adds "str" to the set if it was not already present; returns true if it was
200- * already there.
201- */
202- static int strset_check_and_add (struct strset * ss , const char * str )
203- {
204- unsigned int hash = strhash (str );
205- struct strset_item * item ;
206-
207- if (!ss -> map .table )
208- hashmap_init (& ss -> map , strset_item_hashcmp , NULL , 0 );
209-
210- if (hashmap_get_from_hash (& ss -> map , hash , str ))
211- return 1 ;
212-
213- FLEX_ALLOC_STR (item , value , str );
214- hashmap_entry_init (& item -> ent , hash );
215- hashmap_add (& ss -> map , & item -> ent );
216- return 0 ;
217- }
218-
219- static void strset_clear (struct strset * ss )
220- {
221- if (!ss -> map .table )
222- return ;
223- hashmap_clear_and_free (& ss -> map , struct strset_item , ent );
224- }
225-
226173static void insert_records_from_trailers (struct shortlog * log ,
227174 struct strset * dups ,
228175 struct commit * commit ,
@@ -253,7 +200,7 @@ static void insert_records_from_trailers(struct shortlog *log,
253200 if (!parse_ident (log , & ident , value ))
254201 value = ident .buf ;
255202
256- if (strset_check_and_add (dups , value ))
203+ if (! strset_add (dups , value ))
257204 continue ;
258205 insert_one_record (log , value , oneline );
259206 }
@@ -291,7 +238,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
291238 log -> email ? "%aN <%aE>" : "%aN" ,
292239 & ident , & ctx );
293240 if (!HAS_MULTI_BITS (log -> groups ) ||
294- ! strset_check_and_add (& dups , ident .buf ))
241+ strset_add (& dups , ident .buf ))
295242 insert_one_record (log , ident .buf , oneline_str );
296243 }
297244 if (log -> groups & SHORTLOG_GROUP_COMMITTER ) {
@@ -300,7 +247,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
300247 log -> email ? "%cN <%cE>" : "%cN" ,
301248 & ident , & ctx );
302249 if (!HAS_MULTI_BITS (log -> groups ) ||
303- ! strset_check_and_add (& dups , ident .buf ))
250+ strset_add (& dups , ident .buf ))
304251 insert_one_record (log , ident .buf , oneline_str );
305252 }
306253 if (log -> groups & SHORTLOG_GROUP_TRAILER ) {
0 commit comments