From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Phillip Wood" <phillip.wood123@gmail.com>
Subject: [PATCH v2 2/5] mailmap: switch to opaque struct
Date: Sun, 3 Jan 2021 21:18:46 +0000 [thread overview]
Message-ID: <20210103211849.2691287-3-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20210103211849.2691287-1-sandals@crustytoothpaste.net>
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(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 6f7e32411a..d48dbbd005 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -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
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index cdce144f3b..ad155e9092 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -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,
diff --git a/builtin/commit.c b/builtin/commit.c
index 505fe60956..2d69847c49 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -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;
diff --git a/mailmap.c b/mailmap.c
index c9a538f4e2..d3287b409a 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -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;
}
diff --git a/mailmap.h b/mailmap.h
index ff57b05a15..4cdce3b064 100644
--- a/mailmap.h
+++ b/mailmap.h
@@ -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
diff --git a/pretty.c b/pretty.c
index 43a0039870..0dc2c98e4a 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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);
diff --git a/pretty.h b/pretty.h
index 7ce6c0b437..15735a4c51 100644
--- a/pretty.h
+++ b/pretty.h
@@ -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;
diff --git a/revision.c b/revision.c
index 9dff845bed..848f43d88b 100644
--- a/revision.c
+++ b/revision.c
@@ -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;
diff --git a/revision.h b/revision.h
index 086ff10280..06bc127e90 100644
--- a/revision.h
+++ b/revision.h
@@ -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;
diff --git a/shortlog.h b/shortlog.h
index 64be879b24..9ebf7bbb9c 100644
--- a/shortlog.h
+++ b/shortlog.h
@@ -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;
};
next prev parent reply other threads:[~2021-01-03 21:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-03 21:18 [PATCH v2 0/5] Hashed mailmap brian m. carlson
2021-01-03 21:18 ` [PATCH v2 1/5] mailmap: add a function to inspect the number of entries brian m. carlson
2021-01-04 15:14 ` Ævar Arnfjörð Bjarmason
2021-01-04 17:04 ` René Scharfe
2021-01-03 21:18 ` brian m. carlson [this message]
2021-01-04 15:17 ` [PATCH v2 2/5] mailmap: switch to opaque struct Ævar Arnfjörð Bjarmason
2021-01-03 21:18 ` [PATCH v2 3/5] t4203: add failing test for case-sensitive local-parts and names brian m. carlson
2021-01-03 21:18 ` [PATCH v2 4/5] mailmap: use case-sensitive comparisons for " brian m. carlson
2021-01-04 16:10 ` Ævar Arnfjörð Bjarmason
2021-01-06 0:46 ` Junio C Hamano
2021-01-12 14:08 ` Ævar Arnfjörð Bjarmason
2021-01-03 21:18 ` [PATCH v2 5/5] mailmap: support hashed entries in mailmaps brian m. carlson
2021-01-05 14:21 ` Ævar Arnfjörð Bjarmason
2021-01-06 0:24 ` brian m. carlson
2021-01-10 19:24 ` Ævar Arnfjörð Bjarmason
2021-01-10 21:26 ` brian m. carlson
2021-01-05 20:05 ` Junio C Hamano
2021-01-06 0:28 ` brian m. carlson
2021-01-06 1:50 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210103211849.2691287-3-sandals@crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).