shortlog: use strset from strmap.h

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pull/933/head
Elijah Newren 2 years ago committed by Junio C Hamano
parent b19315d8ab
commit 449a900969
  1. 61
      builtin/shortlog.c

@ -10,6 +10,7 @@
#include "shortlog.h"
#include "parse-options.h"
#include "trailer.h"
#include "strmap.h"
static char const * const shortlog_usage[] = {
N_("git shortlog [<options>] [<revision-range>] [[--] <path>...]"),
@ -169,60 +170,6 @@ static void read_from_stdin(struct shortlog *log)
strbuf_release(&oneline);
}
struct strset_item {
struct hashmap_entry ent;
char value[FLEX_ARRAY];
};
struct strset {
struct hashmap map;
};
#define STRSET_INIT { { NULL } }
static int strset_item_hashcmp(const void *hash_data,
const struct hashmap_entry *entry,
const struct hashmap_entry *entry_or_key,
const void *keydata)
{
const struct strset_item *a, *b;
a = container_of(entry, const struct strset_item, ent);
if (keydata)
return strcmp(a->value, keydata);
b = container_of(entry_or_key, const struct strset_item, ent);
return strcmp(a->value, b->value);
}
/*
* Adds "str" to the set if it was not already present; returns true if it was
* already there.
*/
static int strset_check_and_add(struct strset *ss, const char *str)
{
unsigned int hash = strhash(str);
struct strset_item *item;
if (!ss->map.table)
hashmap_init(&ss->map, strset_item_hashcmp, NULL, 0);
if (hashmap_get_from_hash(&ss->map, hash, str))
return 1;
FLEX_ALLOC_STR(item, value, str);
hashmap_entry_init(&item->ent, hash);
hashmap_add(&ss->map, &item->ent);
return 0;
}
static void strset_clear(struct strset *ss)
{
if (!ss->map.table)
return;
hashmap_clear_and_free(&ss->map, struct strset_item, ent);
}
static void insert_records_from_trailers(struct shortlog *log,
struct strset *dups,
struct commit *commit,
@ -253,7 +200,7 @@ static void insert_records_from_trailers(struct shortlog *log,
if (!parse_ident(log, &ident, value))
value = ident.buf;
if (strset_check_and_add(dups, value))
if (!strset_add(dups, value))
continue;
insert_one_record(log, value, oneline);
}
@ -291,7 +238,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
log->email ? "%aN <%aE>" : "%aN",
&ident, &ctx);
if (!HAS_MULTI_BITS(log->groups) ||
!strset_check_and_add(&dups, ident.buf))
strset_add(&dups, ident.buf))
insert_one_record(log, ident.buf, oneline_str);
}
if (log->groups & SHORTLOG_GROUP_COMMITTER) {
@ -300,7 +247,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
log->email ? "%cN <%cE>" : "%cN",
&ident, &ctx);
if (!HAS_MULTI_BITS(log->groups) ||
!strset_check_and_add(&dups, ident.buf))
strset_add(&dups, ident.buf))
insert_one_record(log, ident.buf, oneline_str);
}
if (log->groups & SHORTLOG_GROUP_TRAILER) {

Loading…
Cancel
Save