@@ -60,7 +60,7 @@ static int mark_ignored_lines;
static struct date_mode blame_date_mode = { DATE_ISO8601 };
static size_t blame_date_width;
-static struct string_list mailmap = STRING_LIST_INIT_NODUP;
+static struct mailmap mailmap;
#ifndef DEBUG_BLAME
#define DEBUG_BLAME 0
@@ -15,7 +15,7 @@ static const struct option check_mailmap_options[] = {
OPT_END()
};
-static void check_mailmap(struct string_list *mailmap, const char *contact)
+static void check_mailmap(struct mailmap *mailmap, const char *contact)
{
const char *name, *mail;
size_t namelen, maillen;
@@ -39,7 +39,7 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)
int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
{
int i;
- struct string_list mailmap = STRING_LIST_INIT_NODUP;
+ struct mailmap mailmap;
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, check_mailmap_options,
@@ -1027,7 +1027,7 @@ static const char *find_author_by_nickname(const char *name)
struct rev_info revs;
struct commit *commit;
struct strbuf buf = STRBUF_INIT;
- struct string_list mailmap = STRING_LIST_INIT_NODUP;
+ struct mailmap mailmap;
const char *av[20];
int ac = 0;
@@ -237,11 +237,14 @@ static int read_mailmap_blob(struct string_list *map,
return 0;
}
-int read_mailmap(struct string_list *map, char **repo_abbrev)
+int read_mailmap(struct mailmap *mailmap, char **repo_abbrev)
{
int err = 0;
+ struct string_list *map;
+
+ map = mailmap->mailmap = malloc(sizeof(*mailmap->mailmap));
+ string_list_init(map, 1);
- map->strdup_strings = 1;
map->cmp = namemap_cmp;
if (!git_mailmap_blob && is_bare_repository())
@@ -254,11 +257,14 @@ int read_mailmap(struct string_list *map, char **repo_abbrev)
return err;
}
-void clear_mailmap(struct string_list *map)
+void clear_mailmap(struct mailmap *mailmap)
{
+ struct string_list *map = mailmap->mailmap;
debug_mm("mailmap: clearing %d entries...\n", map->nr);
map->strdup_strings = 1;
string_list_clear_func(map, free_mailmap_entry);
+ string_list_clear(map, 1);
+ free(map);
debug_mm("mailmap: cleared\n");
}
@@ -313,7 +319,7 @@ static struct string_list_item *lookup_prefix(struct string_list *map,
return NULL;
}
-int map_user(struct string_list *map,
+int map_user(struct mailmap *map,
const char **email, size_t *emaillen,
const char **name, size_t *namelen)
{
@@ -324,7 +330,7 @@ int map_user(struct string_list *map,
(int)*namelen, debug_str(*name),
(int)*emaillen, debug_str(*email));
- item = lookup_prefix(map, *email, *emaillen);
+ item = lookup_prefix(map->mailmap, *email, *emaillen);
if (item != NULL) {
me = (struct mailmap_entry *)item->util;
if (me->namemap.nr) {
@@ -362,7 +368,7 @@ int map_user(struct string_list *map,
return 0;
}
-int mailmap_entries(struct string_list *map)
+int mailmap_entries(struct mailmap *map)
{
- return map->nr;
+ return map->mailmap->nr;
}
@@ -1,13 +1,17 @@
#ifndef MAILMAP_H
#define MAILMAP_H
-struct string_list;
+#include "string-list.h"
-int read_mailmap(struct string_list *map, char **repo_abbrev);
-void clear_mailmap(struct string_list *map);
-int mailmap_entries(struct string_list *map);
+struct mailmap {
+ struct string_list *mailmap;
+};
-int map_user(struct string_list *map,
+int read_mailmap(struct mailmap *map, char **repo_abbrev);
+void clear_mailmap(struct mailmap *map);
+int mailmap_entries(struct mailmap *map);
+
+int map_user(struct mailmap *map,
const char **email, size_t *emaillen, const char **name, size_t *namelen);
#endif
@@ -676,7 +676,7 @@ const char *repo_logmsg_reencode(struct repository *r,
static int mailmap_name(const char **email, size_t *email_len,
const char **name, size_t *name_len)
{
- static struct string_list *mail_map;
+ static struct mailmap *mail_map;
if (!mail_map) {
mail_map = xcalloc(1, sizeof(*mail_map));
read_mailmap(mail_map, NULL);
@@ -40,7 +40,7 @@ struct pretty_print_context {
struct reflog_walk_info *reflog_info;
struct rev_info *rev;
const char *output_encoding;
- struct string_list *mailmap;
+ struct mailmap *mailmap;
int color;
struct ident_split *from_ident;
unsigned encode_email_headers:1;
@@ -3659,7 +3659,7 @@ int rewrite_parents(struct rev_info *revs, struct commit *commit,
return 0;
}
-static int commit_rewrite_person(struct strbuf *buf, const char *what, struct string_list *mailmap)
+static int commit_rewrite_person(struct strbuf *buf, const char *what, struct mailmap *mailmap)
{
char *person, *endp;
size_t len, namelen, maillen;
@@ -7,6 +7,7 @@
#include "notes.h"
#include "pretty.h"
#include "diff.h"
+#include "mailmap.h"
#include "commit-slab-decl.h"
/**
@@ -241,7 +242,7 @@ struct rev_info {
int patch_name_max;
int no_inline;
int show_log_size;
- struct string_list *mailmap;
+ struct mailmap *mailmap;
/* Filter by commit log message */
struct grep_opt grep_filter;
@@ -2,6 +2,7 @@
#define SHORTLOG_H
#include "string-list.h"
+#include "mailmap.h"
struct commit;
@@ -25,7 +26,7 @@ struct shortlog {
char *common_repo_prefix;
int email;
- struct string_list mailmap;
+ struct mailmap mailmap;
FILE *file;
};
Currently a mailmap is a simple sorted string list. However, we'll soon want to add additional data to our mailmap, and in order to do so effectively, we'll need a struct of our own. To do that, let's create a struct mailmap and use that everywhere we're creating a mailmap. Note that we no longer explicitly initialize our mailmaps, since read_mailmap will do that for us. We also don't need to explicitly set the flag to strdup strings, since we've passed that argument when we initialize the string list. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> --- builtin/blame.c | 2 +- builtin/check-mailmap.c | 4 ++-- builtin/commit.c | 2 +- mailmap.c | 20 +++++++++++++------- mailmap.h | 14 +++++++++----- pretty.c | 2 +- pretty.h | 2 +- revision.c | 2 +- revision.h | 3 ++- shortlog.h | 3 ++- 10 files changed, 33 insertions(+), 21 deletions(-)