List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 2/2] Remove angle brackets from {author,committer}_email
Date: Thu, 25 Aug 2016 21:13:12 +0100	[thread overview]
Message-ID: <10b5afe02922e17fc821e5f808bf5803ce4b5137.1472155992.git.john@keeping.me.uk> (raw)
In-Reply-To: <7bf3e6c3af29ba8a2852434b4fd4654f2ea8cf42.1472155992.git.john@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>
---
 filter.c    | 10 +++++++++-
 parsing.c   |  6 +-----
 ui-atom.c   | 13 +------------
 ui-commit.c |  6 ++++--
 4 files changed, 15 insertions(+), 20 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 95958e0..061a596 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'>");
-- 
2.10.0.rc0.142.g1e9f63b



  reply	other threads:[~2016-08-25 20:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-24 18:28 [PATCH] Add support for git's mailmap smithj4
2016-08-24 19:23 ` john
2016-08-24 21:27   ` smithj4
2016-08-24 21:38     ` smithj4
2016-08-24 22:30     ` john
2016-08-25 19:22       ` smithj4
2016-08-25 20:12         ` john
2016-08-25 20:13           ` [PATCH 1/2] filter: introduce cgit_open_email_filter() wrapper john
2016-08-25 20:13             ` john [this message]
2016-08-26 20:11           ` [PATCH] Add support for git's mailmap smithj4

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10b5afe02922e17fc821e5f808bf5803ce4b5137.1472155992.git.john@keeping.me.uk \
    --to=cgit@lists.zx2c4.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.
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).