List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 0/3] Add support for git's mailmap.
@ 2017-02-25 16:12 smithj4
  2017-02-25 16:12 ` [PATCH 1/3] filter: introduce cgit_open_email_filter() wrapper smithj4
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: smithj4 @ 2017-02-25 16:12 UTC (permalink / raw)


Sorry, I was using imap-send and used attachments to keep my
thunderbird mail client from line-wrapping the patches.

Jason A. Smith (1):
  Add support for git's mailmap.

John Keeping (2):
  filter: introduce cgit_open_email_filter() wrapper
  Remove angle brackets from {author,committer}_email

 cgit.h      |  5 +++++
 filter.c    | 13 +++++++++++++
 parsing.c   | 27 ++++++++++++++++++++++-----
 ui-atom.c   | 31 ++++++++++++++-----------------
 ui-commit.c | 28 ++++++++++++++++++++--------
 ui-log.c    | 11 +++++++++--
 ui-refs.c   | 32 ++++++++++++++++++++++++++------
 ui-stats.c  | 13 ++++++++++---
 ui-tag.c    | 17 ++++++++++++-----
 9 files changed, 131 insertions(+), 46 deletions(-)

-- 
2.9.3



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] filter: introduce cgit_open_email_filter() wrapper
  2017-02-25 16:12 [PATCH 0/3] Add support for git's mailmap smithj4
@ 2017-02-25 16:12 ` smithj4
  2017-02-25 16:12 ` [PATCH 2/3] Remove angle brackets from {author,committer}_email smithj4
  2017-02-25 16:12 ` [PATCH 3/3] Add support for git's mailmap smithj4
  2 siblings, 0 replies; 10+ messages in thread
From: smithj4 @ 2017-02-25 16:12 UTC (permalink / raw)


From: John Keeping <john at keeping.me.uk>

We provide email addresses to the email filter surrounded by angle
brackets, but we will soon remove these in our internal representation.
Introduce a wrapper so that we only have to add them in one place.

Signed-off-by: John Keeping <john at keeping.me.uk>
Signed-off-by: Jason A. Smith <smithj4 at bnl.gov>
---
 cgit.h      | 2 ++
 filter.c    | 5 +++++
 ui-commit.c | 4 ++--
 ui-log.c    | 2 +-
 ui-refs.c   | 6 +++---
 ui-tag.c    | 2 +-
 6 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/cgit.h b/cgit.h
index fbc6c6a..204e59e 100644
--- a/cgit.h
+++ b/cgit.h
@@ -382,6 +382,8 @@ extern struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filterty
 extern void cgit_cleanup_filters(void);
 extern void cgit_init_filters(void);
 
+extern void cgit_open_email_filter(const char *email, const char *origin);
+
 extern void cgit_prepare_repo_env(struct cgit_repo * repo);
 
 extern int readfile(const char *path, char **buf, size_t *size);
diff --git a/filter.c b/filter.c
index 949c931..88098ba 100644
--- a/filter.c
+++ b/filter.c
@@ -454,3 +454,8 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 
 	die("Invalid filter type: %.*s", (int) len, cmd);
 }
+
+void cgit_open_email_filter(const char *email, const char *origin)
+{
+	cgit_open_filter(ctx.repo->email_filter, email, origin);
+}
diff --git a/ui-commit.c b/ui-commit.c
index db69d54..04f0411 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -47,7 +47,7 @@ void cgit_print_commit(char *hex, const char *prefix)
 	cgit_print_diff_ctrls();
 	html("<table summary='commit info' class='commit-info'>\n");
 	html("<tr><th>author</th><td>");
-	cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
+	cgit_open_email_filter(info->author_email, "commit");
 	html_txt(info->author);
 	if (!ctx.cfg.noplainemail) {
 		html(" ");
@@ -59,7 +59,7 @@ void cgit_print_commit(char *hex, const char *prefix)
 				cgit_date_mode(DATE_ISO8601)));
 	html("</td></tr>\n");
 	html("<tr><th>committer</th><td>");
-	cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
+	cgit_open_email_filter(info->committer_email, "commit");
 	html_txt(info->committer);
 	if (!ctx.cfg.noplainemail) {
 		html(" ");
diff --git a/ui-log.c b/ui-log.c
index 3220fd9..b78f56f 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -238,7 +238,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
 			 oid_to_hex(&commit->object.oid), ctx.qry.vpath);
 	show_commit_decorations(commit);
 	html("</td><td>");
-	cgit_open_filter(ctx.repo->email_filter, info->author_email, "log");
+	cgit_open_email_filter(info->author_email, "log");
 	html_txt(info->author);
 	cgit_close_filter(ctx.repo->email_filter);
 
diff --git a/ui-refs.c b/ui-refs.c
index 75f2789..0c4eef9 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -69,7 +69,7 @@ static int print_branch(struct refinfo *ref)
 	if (ref->object->type == OBJ_COMMIT) {
 		cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL);
 		html("</td><td>");
-		cgit_open_filter(ctx.repo->email_filter, info->author_email, "refs");
+		cgit_open_email_filter(info->author_email, "refs");
 		html_txt(info->author);
 		cgit_close_filter(ctx.repo->email_filter);
 		html("</td><td colspan='2'>");
@@ -143,12 +143,12 @@ static int print_tag(struct refinfo *ref)
 	html("</td><td>");
 	if (info) {
 		if (info->tagger) {
-			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "refs");
+			cgit_open_email_filter(info->tagger_email, "refs");
 			html_txt(info->tagger);
 			cgit_close_filter(ctx.repo->email_filter);
 		}
 	} else if (ref->object->type == OBJ_COMMIT) {
-		cgit_open_filter(ctx.repo->email_filter, ref->commit->author_email, "refs");
+		cgit_open_email_filter(ref->commit->author_email, "refs");
 		html_txt(ref->commit->author);
 		cgit_close_filter(ctx.repo->email_filter);
 	}
diff --git a/ui-tag.c b/ui-tag.c
index afd7d61..d1e5db9 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -83,7 +83,7 @@ void cgit_print_tag(char *revname)
 		}
 		if (info->tagger) {
 			html("<tr><td>tagged by</td><td>");
-			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
+			cgit_open_email_filter(info->tagger_email, "tag");
 			html_txt(info->tagger);
 			if (info->tagger_email && !ctx.cfg.noplainemail) {
 				html(" ");
-- 
2.9.3



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/3] Remove angle brackets from {author,committer}_email
  2017-02-25 16:12 [PATCH 0/3] Add support for git's mailmap smithj4
  2017-02-25 16:12 ` [PATCH 1/3] filter: introduce cgit_open_email_filter() wrapper smithj4
@ 2017-02-25 16:12 ` smithj4
  2017-02-25 16:12 ` [PATCH 3/3] Add support for git's mailmap smithj4
  2 siblings, 0 replies; 10+ messages in thread
From: smithj4 @ 2017-02-25 16:12 UTC (permalink / raw)


From: John Keeping <john at keeping.me.uk>

This matches the internal representation in libgit.a, so it will make it
much easier to use Git's mailmap code.

The change in ui-atom.c isn't strictly necessary since the code copes
with email addresses both with and without angle brackets, but it's a
nice simplification since we know that the email address will always be
provided in the correct form.

Signed-off-by: John Keeping <john at keeping.me.uk>
Signed-off-by: Jason A. Smith <smithj4 at bnl.gov>
---
 filter.c    | 10 +++++++++-
 parsing.c   |  6 +-----
 ui-atom.c   | 13 +------------
 ui-commit.c |  6 ++++--
 ui-tag.c    |  3 ++-
 5 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/filter.c b/filter.c
index 88098ba..ba9000a 100644
--- a/filter.c
+++ b/filter.c
@@ -457,5 +457,13 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 
 void cgit_open_email_filter(const char *email, const char *origin)
 {
-	cgit_open_filter(ctx.repo->email_filter, email, origin);
+	struct strbuf sb = STRBUF_INIT;
+
+	/* Don't bother allocating any memory if we don't have a filter. */
+	if (!ctx.repo->email_filter)
+		return;
+
+	strbuf_addf(&sb, "<%s>", email);
+	cgit_open_filter(ctx.repo->email_filter, sb.buf, origin);
+	strbuf_release(&sb);
 }
diff --git a/parsing.c b/parsing.c
index 9dacb16..352338d 100644
--- a/parsing.c
+++ b/parsing.c
@@ -72,14 +72,10 @@ static char *substr(const char *head, const char *tail)
 static void parse_user(const char *t, char **name, char **email, unsigned long *date, int *tz)
 {
 	struct ident_split ident;
-	unsigned email_len;
 
 	if (!split_ident_line(&ident, t, strchrnul(t, '\n') - t)) {
 		*name = substr(ident.name_begin, ident.name_end);
-
-		email_len = ident.mail_end - ident.mail_begin;
-		*email = xmalloc(strlen("<") + email_len + strlen(">") + 1);
-		sprintf(*email, "<%.*s>", email_len, ident.mail_begin);
+		*email = substr(ident.mail_begin, ident.mail_end);
 
 		if (ident.date_begin)
 			*date = strtoul(ident.date_begin, NULL, 10);
diff --git a/ui-atom.c b/ui-atom.c
index 41838d3..7c17d6a 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -15,7 +15,6 @@ static void add_entry(struct commit *commit, const char *host)
 {
 	char delim = '&';
 	char *hex;
-	char *mail, *t, *t2;
 	struct commitinfo *info;
 
 	info = cgit_parse_commit(commit);
@@ -35,19 +34,9 @@ static void add_entry(struct commit *commit, const char *host)
 		html("</name>\n");
 	}
 	if (info->author_email && !ctx.cfg.noplainemail) {
-		mail = xstrdup(info->author_email);
-		t = strchr(mail, '<');
-		if (t)
-			t++;
-		else
-			t = mail;
-		t2 = strchr(t, '>');
-		if (t2)
-			*t2 = '\0';
 		html("<email>");
-		html_txt(t);
+		html_txt(info->author_email);
 		html("</email>\n");
-		free(mail);
 	}
 	html("</author>\n");
 	html("<published>");
diff --git a/ui-commit.c b/ui-commit.c
index 04f0411..dccb5f3 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -50,8 +50,9 @@ void cgit_print_commit(char *hex, const char *prefix)
 	cgit_open_email_filter(info->author_email, "commit");
 	html_txt(info->author);
 	if (!ctx.cfg.noplainemail) {
-		html(" ");
+		html(" &lt;");
 		html_txt(info->author_email);
+		html("&gt;");
 	}
 	cgit_close_filter(ctx.repo->email_filter);
 	html("</td><td class='right'>");
@@ -62,8 +63,9 @@ void cgit_print_commit(char *hex, const char *prefix)
 	cgit_open_email_filter(info->committer_email, "commit");
 	html_txt(info->committer);
 	if (!ctx.cfg.noplainemail) {
-		html(" ");
+		html(" &lt;");
 		html_txt(info->committer_email);
+		html("&gt;");
 	}
 	cgit_close_filter(ctx.repo->email_filter);
 	html("</td><td class='right'>");
diff --git a/ui-tag.c b/ui-tag.c
index d1e5db9..ad7854e 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -86,8 +86,9 @@ void cgit_print_tag(char *revname)
 			cgit_open_email_filter(info->tagger_email, "tag");
 			html_txt(info->tagger);
 			if (info->tagger_email && !ctx.cfg.noplainemail) {
-				html(" ");
+				html(" &lt;");
 				html_txt(info->tagger_email);
+				html("&gt;");
 			}
 			cgit_close_filter(ctx.repo->email_filter);
 			html("</td></tr>\n");
-- 
2.9.3



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3] Add support for git's mailmap.
  2017-02-25 16:12 [PATCH 0/3] Add support for git's mailmap smithj4
  2017-02-25 16:12 ` [PATCH 1/3] filter: introduce cgit_open_email_filter() wrapper smithj4
  2017-02-25 16:12 ` [PATCH 2/3] Remove angle brackets from {author,committer}_email smithj4
@ 2017-02-25 16:12 ` smithj4
  2 siblings, 0 replies; 10+ messages in thread
From: smithj4 @ 2017-02-25 16:12 UTC (permalink / raw)


If a mailmap file is present in the repo, it will be used to coalesce
commits by the same person, just like git does. When no mailmap file is
found then it functions as before.

Signed-off-by: Jason A. Smith <smithj4 at bnl.gov>
---
 cgit.h      |  3 +++
 parsing.c   | 21 +++++++++++++++++++++
 ui-atom.c   | 20 ++++++++++++++------
 ui-commit.c | 22 ++++++++++++++++------
 ui-log.c    | 11 +++++++++--
 ui-refs.c   | 32 ++++++++++++++++++++++++++------
 ui-stats.c  | 13 ++++++++++---
 ui-tag.c    | 14 ++++++++++----
 8 files changed, 109 insertions(+), 27 deletions(-)

diff --git a/cgit.h b/cgit.h
index 204e59e..e4e070f 100644
--- a/cgit.h
+++ b/cgit.h
@@ -24,6 +24,7 @@
 #include <utf8.h>
 #include <notes.h>
 #include <graph.h>
+#include <mailmap.h>
 
 /* Add isgraph(x) to Git's sane ctype support (see git-compat-util.h) */
 #undef isgraph
@@ -369,6 +370,8 @@ extern char *fmtalloc(const char *format,...);
 extern struct commitinfo *cgit_parse_commit(struct commit *commit);
 extern struct taginfo *cgit_parse_tag(struct tag *tag);
 extern void cgit_parse_url(const char *url);
+extern int cgit_read_mailmap(struct string_list *map);
+extern int cgit_map_user(struct string_list *map, const char **email, const char **name);
 
 extern const char *cgit_repobasename(const char *reponame);
 
diff --git a/parsing.c b/parsing.c
index 352338d..c9619a0 100644
--- a/parsing.c
+++ b/parsing.c
@@ -84,6 +84,27 @@ static void parse_user(const char *t, char **name, char **email, unsigned long *
 	}
 }
 
+int cgit_read_mailmap(struct string_list *map)
+{
+	int ret;
+
+	ret = read_mailmap(map, NULL);
+	if (ret)
+		fprintf(stderr, "Error reading mailmap: read_mailmap() returned: %d\n", ret);
+	return ret;
+}
+
+int cgit_map_user(struct string_list *map, const char **email, const char **name)
+{
+	size_t emaillen, namelen;
+	int ret;
+
+	emaillen = strlen(*email);
+	namelen = strlen(*name);
+	ret = map_user(map, email, &emaillen, name, &namelen);
+	return ret;
+}
+
 #ifdef NO_ICONV
 #define reencode(a, b, c)
 #else
diff --git a/ui-atom.c b/ui-atom.c
index 7c17d6a..9d541ba 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -11,13 +11,18 @@
 #include "html.h"
 #include "ui-shared.h"
 
-static void add_entry(struct commit *commit, const char *host)
+static void add_entry(struct commit *commit, const char *host,
+		      struct string_list *mailmap)
 {
 	char delim = '&';
 	char *hex;
 	struct commitinfo *info;
+	const char *author, *author_email;
 
 	info = cgit_parse_commit(commit);
+	author = info->author;
+	author_email = info->author_email;
+	cgit_map_user(mailmap, &author_email, &author);
 	hex = oid_to_hex(&commit->object.oid);
 	html("<entry>\n");
 	html("<title>");
@@ -28,14 +33,14 @@ static void add_entry(struct commit *commit, const char *host)
                     date_mode_from_type(DATE_ISO8601_STRICT)));
 	html("</updated>\n");
 	html("<author>\n");
-	if (info->author) {
+	if (author) {
 		html("<name>");
-		html_txt(info->author);
+		html_txt(author);
 		html("</name>\n");
 	}
-	if (info->author_email && !ctx.cfg.noplainemail) {
+	if (author_email && !ctx.cfg.noplainemail) {
 		html("<email>");
-		html_txt(info->author_email);
+		html_txt(author_email);
 		html("</email>\n");
 	}
 	html("</author>\n");
@@ -78,6 +83,7 @@ void cgit_print_atom(char *tip, char *path, int max_count)
 	const char *argv[] = {NULL, tip, NULL, NULL, NULL};
 	struct commit *commit;
 	struct rev_info rev;
+	struct string_list mailmap = STRING_LIST_INIT_NODUP;
 	int argc = 2;
 
 	if (ctx.qry.show_all)
@@ -97,6 +103,8 @@ void cgit_print_atom(char *tip, char *path, int max_count)
 	rev.show_root_diff = 0;
 	rev.max_count = max_count;
 	setup_revisions(argc, argv, &rev, NULL);
+	cgit_read_mailmap(&mailmap);
+	rev.mailmap = &mailmap;
 	prepare_revision_walk(&rev);
 
 	host = cgit_hosturl();
@@ -128,7 +136,7 @@ void cgit_print_atom(char *tip, char *path, int max_count)
 		free(repourl);
 	}
 	while ((commit = get_revision(&rev)) != NULL) {
-		add_entry(commit, host);
+		add_entry(commit, host, &mailmap);
 		free_commit_buffer(commit);
 		free_commit_list(commit->parents);
 		commit->parents = NULL;
diff --git a/ui-commit.c b/ui-commit.c
index dccb5f3..491d800 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -18,8 +18,11 @@ void cgit_print_commit(char *hex, const char *prefix)
 	struct commit *commit, *parent;
 	struct commitinfo *info, *parent_info;
 	struct commit_list *p;
+	struct string_list mailmap = STRING_LIST_INIT_NODUP;
 	struct strbuf notes = STRBUF_INIT;
 	struct object_id oid;
+	const char *author, *author_email;
+	const char *committer, *committer_email;
 	char *tmp, *tmp2;
 	int parents = 0;
 
@@ -38,6 +41,13 @@ void cgit_print_commit(char *hex, const char *prefix)
 		return;
 	}
 	info = cgit_parse_commit(commit);
+	cgit_read_mailmap(&mailmap);
+	author = info->author;
+	author_email = info->author_email;
+	cgit_map_user(&mailmap, &author_email, &author);
+	committer = info->committer;
+	committer_email = info->committer_email;
+	cgit_map_user(&mailmap, &committer_email, &committer);
 
 	format_display_notes(oid.hash, &notes, PAGE_ENCODING, 0);
 
@@ -47,11 +57,11 @@ void cgit_print_commit(char *hex, const char *prefix)
 	cgit_print_diff_ctrls();
 	html("<table summary='commit info' class='commit-info'>\n");
 	html("<tr><th>author</th><td>");
-	cgit_open_email_filter(info->author_email, "commit");
-	html_txt(info->author);
+	cgit_open_email_filter(author_email, "commit");
+	html_txt(author);
 	if (!ctx.cfg.noplainemail) {
 		html(" &lt;");
-		html_txt(info->author_email);
+		html_txt(author_email);
 		html("&gt;");
 	}
 	cgit_close_filter(ctx.repo->email_filter);
@@ -60,11 +70,11 @@ void cgit_print_commit(char *hex, const char *prefix)
 				cgit_date_mode(DATE_ISO8601)));
 	html("</td></tr>\n");
 	html("<tr><th>committer</th><td>");
-	cgit_open_email_filter(info->committer_email, "commit");
-	html_txt(info->committer);
+	cgit_open_email_filter(committer_email, "commit");
+	html_txt(committer);
 	if (!ctx.cfg.noplainemail) {
 		html(" &lt;");
-		html_txt(info->committer_email);
+		html_txt(committer_email);
 		html("&gt;");
 	}
 	cgit_close_filter(ctx.repo->email_filter);
diff --git a/ui-log.c b/ui-log.c
index b78f56f..21a3497 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -171,6 +171,7 @@ static int show_commit(struct commit *commit, struct rev_info *revs)
 static void print_commit(struct commit *commit, struct rev_info *revs)
 {
 	struct commitinfo *info;
+	const char *author, *author_email;
 	int columns = revs->graph ? 4 : 3;
 	struct strbuf graphbuf = STRBUF_INIT;
 	struct strbuf msgbuf = STRBUF_INIT;
@@ -238,8 +239,11 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
 			 oid_to_hex(&commit->object.oid), ctx.qry.vpath);
 	show_commit_decorations(commit);
 	html("</td><td>");
-	cgit_open_email_filter(info->author_email, "log");
-	html_txt(info->author);
+	author = info->author;
+	author_email = info->author_email;
+	cgit_map_user(revs->mailmap, &author_email, &author);
+	cgit_open_email_filter(author_email, "log");
+	html_txt(author);
 	cgit_close_filter(ctx.repo->email_filter);
 
 	if (revs->graph) {
@@ -361,6 +365,7 @@ static char *next_token(char **src)
 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
 		    char *path, int pager, int commit_graph, int commit_sort)
 {
+	struct string_list mailmap = STRING_LIST_INIT_NODUP;
 	struct rev_info rev;
 	struct commit *commit;
 	struct argv_array rev_argv = ARGV_ARRAY_INIT;
@@ -444,6 +449,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
 		DIFF_XDL_SET(&rev.diffopt, IGNORE_WHITESPACE);
 
 	compile_grep_patterns(&rev.grep_filter);
+	cgit_read_mailmap(&mailmap);
+	rev.mailmap = &mailmap;
 	prepare_revision_walk(&rev);
 
 	if (pager) {
diff --git a/ui-refs.c b/ui-refs.c
index 0c4eef9..f645d7d 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -11,6 +11,8 @@
 #include "html.h"
 #include "ui-shared.h"
 
+static struct string_list mailmap = STRING_LIST_INIT_DUP;
+
 static inline int cmp_age(int age1, int age2)
 {
 	/* age1 and age2 are assumed to be non-negative */
@@ -57,6 +59,7 @@ static int cmp_tag_age(const void *a, const void *b)
 static int print_branch(struct refinfo *ref)
 {
 	struct commitinfo *info = ref->commit;
+	const char *author, *author_email;
 	char *name = (char *)ref->refname;
 
 	if (!info)
@@ -67,10 +70,13 @@ static int print_branch(struct refinfo *ref)
 	html("</td><td>");
 
 	if (ref->object->type == OBJ_COMMIT) {
+		author = info->author;
+		author_email = info->author_email;
+		cgit_map_user(&mailmap, &author_email, &author);
 		cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL);
 		html("</td><td>");
-		cgit_open_email_filter(info->author_email, "refs");
-		html_txt(info->author);
+		cgit_open_email_filter(author_email, "refs");
+		html_txt(author);
 		cgit_close_filter(ctx.repo->email_filter);
 		html("</td><td colspan='2'>");
 		cgit_print_age(info->committer_date, info->committer_tz, -1);
@@ -122,6 +128,8 @@ static int print_tag(struct refinfo *ref)
 {
 	struct tag *tag = NULL;
 	struct taginfo *info = NULL;
+	const char *tagger, *tagger_email;
+	const char *author, *author_email;
 	char *name = (char *)ref->refname;
 	struct object *obj = ref->object;
 
@@ -143,13 +151,19 @@ static int print_tag(struct refinfo *ref)
 	html("</td><td>");
 	if (info) {
 		if (info->tagger) {
-			cgit_open_email_filter(info->tagger_email, "refs");
-			html_txt(info->tagger);
+			tagger = info->tagger;
+			tagger_email = info->tagger_email;
+			cgit_map_user(&mailmap, &tagger_email, &tagger);
+			cgit_open_email_filter(tagger_email, "refs");
+			html_txt(tagger);
 			cgit_close_filter(ctx.repo->email_filter);
 		}
 	} else if (ref->object->type == OBJ_COMMIT) {
-		cgit_open_email_filter(ref->commit->author_email, "refs");
-		html_txt(ref->commit->author);
+		author = ref->commit->author;
+		author_email = ref->commit->author_email;
+		cgit_map_user(&mailmap, &author_email, &author);
+		cgit_open_email_filter(author_email, "refs");
+		html_txt(author);
 		cgit_close_filter(ctx.repo->email_filter);
 	}
 	html("</td><td colspan='2'>");
@@ -194,6 +208,9 @@ void cgit_print_branches(int maxcount)
 	if (ctx.repo->branch_sort == 0)
 		qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
 
+	if (!mailmap.items) {
+		cgit_read_mailmap(&mailmap);
+	}
 	for (i = 0; i < maxcount; i++)
 		print_branch(list.refs[i]);
 
@@ -219,6 +236,9 @@ void cgit_print_tags(int maxcount)
 	else if (maxcount > list.count)
 		maxcount = list.count;
 	print_tag_header();
+	if (!mailmap.items) {
+		cgit_read_mailmap(&mailmap);
+	}
 	for (i = 0; i < maxcount; i++)
 		print_tag(list.refs[i]);
 
diff --git a/ui-stats.c b/ui-stats.c
index 7acd358..12eedee 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -159,9 +159,10 @@ const char *cgit_find_stats_periodname(int idx)
 }
 
 static void add_commit(struct string_list *authors, struct commit *commit,
-	const struct cgit_period *period)
+	const struct cgit_period *period, struct string_list *mailmap)
 {
 	struct commitinfo *info;
+	const char *author_name, *author_email;
 	struct string_list_item *author, *item;
 	struct authorstat *authorstat;
 	struct string_list *items;
@@ -171,7 +172,10 @@ static void add_commit(struct string_list *authors, struct commit *commit,
 	uintptr_t *counter;
 
 	info = cgit_parse_commit(commit);
-	tmp = xstrdup(info->author);
+	author_name = info->author;
+	author_email = info->author_email;
+	cgit_map_user(mailmap, &author_email, &author_name);
+	tmp = xstrdup(author_name);
 	author = string_list_insert(authors, tmp);
 	if (!author->util)
 		author->util = xcalloc(1, sizeof(struct authorstat));
@@ -209,6 +213,7 @@ static int cmp_total_commits(const void *a1, const void *a2)
 static struct string_list collect_stats(const struct cgit_period *period)
 {
 	struct string_list authors;
+	struct string_list mailmap = STRING_LIST_INIT_NODUP;
 	struct rev_info rev;
 	struct commit *commit;
 	const char *argv[] = {NULL, ctx.qry.head, NULL, NULL, NULL, NULL};
@@ -237,10 +242,12 @@ static struct string_list collect_stats(const struct cgit_period *period)
 	rev.verbose_header = 1;
 	rev.show_root_diff = 0;
 	setup_revisions(argc, argv, &rev, NULL);
+	cgit_read_mailmap(&mailmap);
+	rev.mailmap = &mailmap;
 	prepare_revision_walk(&rev);
 	memset(&authors, 0, sizeof(authors));
 	while ((commit = get_revision(&rev)) != NULL) {
-		add_commit(&authors, commit, period);
+		add_commit(&authors, commit, period, &mailmap);
 		free_commit_buffer(commit);
 		free_commit_list(commit->parents);
 		commit->parents = NULL;
diff --git a/ui-tag.c b/ui-tag.c
index ad7854e..cccfc53 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -44,6 +44,8 @@ void cgit_print_tag(char *revname)
 	struct strbuf fullref = STRBUF_INIT;
 	struct object_id oid;
 	struct object *obj;
+	struct string_list mailmap = STRING_LIST_INIT_NODUP;
+	const char *tagger, *tagger_email;
 
 	if (!revname)
 		revname = ctx.qry.head;
@@ -82,12 +84,16 @@ void cgit_print_tag(char *revname)
 			html("</td></tr>\n");
 		}
 		if (info->tagger) {
+			cgit_read_mailmap(&mailmap);
+			tagger = info->tagger;
+			tagger_email = info->tagger_email;
+			cgit_map_user(&mailmap, &tagger_email, &tagger);
 			html("<tr><td>tagged by</td><td>");
-			cgit_open_email_filter(info->tagger_email, "tag");
-			html_txt(info->tagger);
-			if (info->tagger_email && !ctx.cfg.noplainemail) {
+			cgit_open_email_filter(tagger_email, "tag");
+			html_txt(tagger);
+			if (tagger_email && !ctx.cfg.noplainemail) {
 				html(" &lt;");
-				html_txt(info->tagger_email);
+				html_txt(tagger_email);
 				html("&gt;");
 			}
 			cgit_close_filter(ctx.repo->email_filter);
-- 
2.9.3



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/3] Add support for git's mailmap.
  2017-11-02 20:48     ` smithj4
  2017-11-02 22:54       ` i
@ 2017-11-05 12:25       ` john
  1 sibling, 0 replies; 10+ messages in thread
From: john @ 2017-11-05 12:25 UTC (permalink / raw)


On Thu, Nov 02, 2017 at 04:48:08PM -0400, Jason A. Smith wrote:
> I always thought that by going through the trouble of collecting the 
> duplicate email addresses and creating the .mailmap file that you wanted 
> this coalescing behavior.
> 
> Personally, I don't really want to have to remember everyone's old email 
> address and variation of their name that they might have used several 
> years ago to push a commit. I don't really care what email & name they 
> used a long time ago, I am more interested in just knowing who made the 
> commit, which is why the .mailmap coalesces all of their old identities 
> into their current one for display.
> 
> If people don't need or want this coalescing behavior and want to see 
> each individual identity then they don't need to make the .mailmap file 
> to begin with.

Consider someone working on an open source project who changes employer;
in this case .mailmap allows email to be directed to an address at the
new employer rather than at the previous employer, especially for
auto-generated CC lists from something like Linux's get_maintainer.pl
script.

However, when looking at historic commits, it may be very interesting
that a particular change was committed by someone with an email address
at a cerain company.  Blindly applying .mailmap rules loses that
information (admittedly, in the case of the kernel, DCO rules mean the
relevant information also lives in the S-o-b but that doesn't apply
everywhere).

On the other hand, it might be that some early commits by a developer in
a project use the default "user@(none)" fallback address and .mailmap is
used to change that to a genuine email address.  In that case applying
.mailmap in all cases is desirable.

I don't think we can take a global decision on which behaviour is
correct for all projects, so IMHO there must be a configuration switch
to allow projects to decide what is right for them.

> On 10/28/2017 07:36 AM, John Keeping wrote:
> > On Tue, Oct 24, 2017 at 10:55:21AM -0400, Jason A. Smith wrote:
> >> Seeing a lot of recent activity I checked the upstream and see that the
> >> patch I first submitted over a year ago has still not been merged. I
> >> already had to rebase it once several months ago to fix conflicts, I
> >> don't want to have to do that again. Is there something wrong with this
> >> patch? Please let me know so I can fix it.
> > 
> > I've taken another look at this patch and one thing that stands out is
> > that we end up inserting code to map users in a lot of different places.
> > I haven't audited the code, but after the final patch, is there anywhere
> > that calls cgit_parse_commit() and doesn't go on to map the users?
> > (Even if not all callers do map the user, can we push cgit_map_user()
> > into cgit_parse_commit() and use a flag parameter to enable it?)
> > 
> > But I think that points to a deeper philosophical question of whether we
> > should be mapping the user in all cases (and I suspect this is why the
> > patch has sat on the list for so long - there are arguments in both
> > directions).
> > 
> > As I understand it, mailmap was originally introduced so that
> > git-shortlog would coalesce commits from the same author but with
> > different email addresses.  When using the git command, mailmap is
> > enabled by default for git-shortlog and git-blame but not for git-log,
> > git-show, and other commands that print commits.
> > 
> > Extending this to CGit, it seems that there's a clear argument for
> > enabling mailmap in ui-stats and possibly the new ui-blame, but when we
> > print a commit in ui-commit or ui-log is it always correct to apply the
> > mailmap or should we show the commit headers as-is?
> > 
> > It would be interesting to know what others on the list think about
> > this.  If there isn't a consensus then we may want a new config option
> > to allow this to be enabled according to the preferences of individual
> > sites.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/3] Add support for git's mailmap.
  2017-11-02 20:48     ` smithj4
@ 2017-11-02 22:54       ` i
  2017-11-05 12:25       ` john
  1 sibling, 0 replies; 10+ messages in thread
From: i @ 2017-11-02 22:54 UTC (permalink / raw)


Ack and for edge cases a config entry ignore_mailmap = True

On 02.11.2017 21:48, Jason A. Smith wrote:
> If people don't need or want this coalescing behavior and want to see
> each individual identity then they don't need to make the .mailmap file
> to begin with.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20171102/9cccb9fa/attachment.asc>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/3] Add support for git's mailmap.
  2017-10-28 11:36   ` john
@ 2017-11-02 20:48     ` smithj4
  2017-11-02 22:54       ` i
  2017-11-05 12:25       ` john
  0 siblings, 2 replies; 10+ messages in thread
From: smithj4 @ 2017-11-02 20:48 UTC (permalink / raw)


Hi John,

I always thought that by going through the trouble of collecting the 
duplicate email addresses and creating the .mailmap file that you wanted 
this coalescing behavior.

Personally, I don't really want to have to remember everyone's old email 
address and variation of their name that they might have used several 
years ago to push a commit. I don't really care what email & name they 
used a long time ago, I am more interested in just knowing who made the 
commit, which is why the .mailmap coalesces all of their old identities 
into their current one for display.

If people don't need or want this coalescing behavior and want to see 
each individual identity then they don't need to make the .mailmap file 
to begin with.

Just my opinion on .mailmap.

~Jason


On 10/28/2017 07:36 AM, John Keeping wrote:
> On Tue, Oct 24, 2017 at 10:55:21AM -0400, Jason A. Smith wrote:
>> Seeing a lot of recent activity I checked the upstream and see that the
>> patch I first submitted over a year ago has still not been merged. I
>> already had to rebase it once several months ago to fix conflicts, I
>> don't want to have to do that again. Is there something wrong with this
>> patch? Please let me know so I can fix it.
> 
> I've taken another look at this patch and one thing that stands out is
> that we end up inserting code to map users in a lot of different places.
> I haven't audited the code, but after the final patch, is there anywhere
> that calls cgit_parse_commit() and doesn't go on to map the users?
> (Even if not all callers do map the user, can we push cgit_map_user()
> into cgit_parse_commit() and use a flag parameter to enable it?)
> 
> But I think that points to a deeper philosophical question of whether we
> should be mapping the user in all cases (and I suspect this is why the
> patch has sat on the list for so long - there are arguments in both
> directions).
> 
> As I understand it, mailmap was originally introduced so that
> git-shortlog would coalesce commits from the same author but with
> different email addresses.  When using the git command, mailmap is
> enabled by default for git-shortlog and git-blame but not for git-log,
> git-show, and other commands that print commits.
> 
> Extending this to CGit, it seems that there's a clear argument for
> enabling mailmap in ui-stats and possibly the new ui-blame, but when we
> print a commit in ui-commit or ui-log is it always correct to apply the
> mailmap or should we show the commit headers as-is?
> 
> It would be interesting to know what others on the list think about
> this.  If there isn't a consensus then we may want a new config option
> to allow this to be enabled according to the preferences of individual
> sites.
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/3] Add support for git's mailmap.
  2017-10-24 14:55 ` smithj4
@ 2017-10-28 11:36   ` john
  2017-11-02 20:48     ` smithj4
  0 siblings, 1 reply; 10+ messages in thread
From: john @ 2017-10-28 11:36 UTC (permalink / raw)


On Tue, Oct 24, 2017 at 10:55:21AM -0400, Jason A. Smith wrote:
> Seeing a lot of recent activity I checked the upstream and see that the 
> patch I first submitted over a year ago has still not been merged. I 
> already had to rebase it once several months ago to fix conflicts, I 
> don't want to have to do that again. Is there something wrong with this 
> patch? Please let me know so I can fix it.

I've taken another look at this patch and one thing that stands out is
that we end up inserting code to map users in a lot of different places.
I haven't audited the code, but after the final patch, is there anywhere
that calls cgit_parse_commit() and doesn't go on to map the users?
(Even if not all callers do map the user, can we push cgit_map_user()
into cgit_parse_commit() and use a flag parameter to enable it?)

But I think that points to a deeper philosophical question of whether we
should be mapping the user in all cases (and I suspect this is why the
patch has sat on the list for so long - there are arguments in both
directions).

As I understand it, mailmap was originally introduced so that
git-shortlog would coalesce commits from the same author but with
different email addresses.  When using the git command, mailmap is
enabled by default for git-shortlog and git-blame but not for git-log,
git-show, and other commands that print commits.

Extending this to CGit, it seems that there's a clear argument for
enabling mailmap in ui-stats and possibly the new ui-blame, but when we
print a commit in ui-commit or ui-log is it always correct to apply the
mailmap or should we show the commit headers as-is?

It would be interesting to know what others on the list think about
this.  If there isn't a consensus then we may want a new config option
to allow this to be enabled according to the preferences of individual
sites.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/3] Add support for git's mailmap.
  2017-02-24 16:18 [PATCH 0/3] " smithj4
@ 2017-10-24 14:55 ` smithj4
  2017-10-28 11:36   ` john
  0 siblings, 1 reply; 10+ messages in thread
From: smithj4 @ 2017-10-24 14:55 UTC (permalink / raw)


Seeing a lot of recent activity I checked the upstream and see that the 
patch I first submitted over a year ago has still not been merged. I 
already had to rebase it once several months ago to fix conflicts, I 
don't want to have to do that again. Is there something wrong with this 
patch? Please let me know so I can fix it.

Thanks,
~Jason


On 02/24/2017 11:18 AM, Jason A. Smith wrote:
> 
> Rebased patch to resolve some minor conflicts with the master branch.
> 
> Jason A. Smith (1):
>  ? Add support for git's mailmap.
> 
> John Keeping (2):
>  ? filter: introduce cgit_open_email_filter() wrapper
>  ? Remove angle brackets from {author,committer}_email
> 
>  ?cgit.h????? |? 5 +++++
>  ?filter.c??? | 13 +++++++++++++
>  ?parsing.c?? | 27 ++++++++++++++++++++++-----
>  ?ui-atom.c?? | 31 ++++++++++++++-----------------
>  ?ui-commit.c | 28 ++++++++++++++++++++--------
>  ?ui-log.c??? | 11 +++++++++--
>  ?ui-refs.c?? | 32 ++++++++++++++++++++++++++------
>  ?ui-stats.c? | 13 ++++++++++---
>  ?ui-tag.c??? | 17 ++++++++++++-----
>  ?9 files changed, 131 insertions(+), 46 deletions(-)
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 0/3] Add support for git's mailmap.
@ 2017-02-24 16:18 smithj4
  2017-10-24 14:55 ` smithj4
  0 siblings, 1 reply; 10+ messages in thread
From: smithj4 @ 2017-02-24 16:18 UTC (permalink / raw)



Rebased patch to resolve some minor conflicts with the master branch.

Jason A. Smith (1):
   Add support for git's mailmap.

John Keeping (2):
   filter: introduce cgit_open_email_filter() wrapper
   Remove angle brackets from {author,committer}_email

  cgit.h      |  5 +++++
  filter.c    | 13 +++++++++++++
  parsing.c   | 27 ++++++++++++++++++++++-----
  ui-atom.c   | 31 ++++++++++++++-----------------
  ui-commit.c | 28 ++++++++++++++++++++--------
  ui-log.c    | 11 +++++++++--
  ui-refs.c   | 32 ++++++++++++++++++++++++++------
  ui-stats.c  | 13 ++++++++++---
  ui-tag.c    | 17 ++++++++++++-----
  9 files changed, 131 insertions(+), 46 deletions(-)



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-11-05 12:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-25 16:12 [PATCH 0/3] Add support for git's mailmap smithj4
2017-02-25 16:12 ` [PATCH 1/3] filter: introduce cgit_open_email_filter() wrapper smithj4
2017-02-25 16:12 ` [PATCH 2/3] Remove angle brackets from {author,committer}_email smithj4
2017-02-25 16:12 ` [PATCH 3/3] Add support for git's mailmap smithj4
  -- strict thread matches above, loose matches on Subject: below --
2017-02-24 16:18 [PATCH 0/3] " smithj4
2017-10-24 14:55 ` smithj4
2017-10-28 11:36   ` john
2017-11-02 20:48     ` smithj4
2017-11-02 22:54       ` i
2017-11-05 12:25       ` john

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 NNTP newsgroup(s).