shortlog: use strset from strmap.h
Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Nov 11, 2020 at 20:02 UTC
449a900969d0f060d054e5a13084bed318da3a31
1 file changed
+4
-57
builtin/shortlog.c
+4
-57
@@ -10,6 +10,7 @@
10
#include "shortlog.h"
11
#include "parse-options.h"
12
#include "trailer.h"
13
+#include "strmap.h"
14
15
static char const * const shortlog_usage[] = {
16
N_("git shortlog [<options>] [<revision-range>] [[--] <path>...]"),
@@ -169,60 +170,6 @@ static void read_from_stdin(struct shortlog *log)
170
strbuf_release(&oneline);
171
}
172
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
-
173
static void insert_records_from_trailers(struct shortlog *log,
174
struct strset *dups,
175
struct commit *commit,
@@ -253,7 +200,7 @@ static void insert_records_from_trailers(struct shortlog *log,
200
if (!parse_ident(log, &ident, value))
201
value = ident.buf;
202
256
- if (strset_check_and_add(dups, value))
203
+ if (!strset_add(dups, value))
204
continue;
205
insert_one_record(log, value, oneline);
206
}
@@ -291,7 +238,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
238
log->email ? "%aN <%aE>" : "%aN",
239
&ident, &ctx);
240
if (!HAS_MULTI_BITS(log->groups) ||
294
- !strset_check_and_add(&dups, ident.buf))
241
+ strset_add(&dups, ident.buf))
242
insert_one_record(log, ident.buf, oneline_str);
243
}
244
if (log->groups & SHORTLOG_GROUP_COMMITTER) {
@@ -300,7 +247,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
247
log->email ? "%cN <%cE>" : "%cN",
248
&ident, &ctx);
249
if (!HAS_MULTI_BITS(log->groups) ||
303
- !strset_check_and_add(&dups, ident.buf))
250
+ strset_add(&dups, ident.buf))
251
insert_one_record(log, ident.buf, oneline_str);
252
}
253
if (log->groups & SHORTLOG_GROUP_TRAILER) {