List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] Use split_ident_line() in parse_user()
@ 2014-12-17 12:19 cgit
  2014-12-24  1:57 ` Jason
  2014-12-24  7:50 ` [PATCH v2] " cgit
  0 siblings, 2 replies; 5+ messages in thread
From: cgit @ 2014-12-17 12:19 UTC (permalink / raw)


Use Git's built-in ident line splitting algorithm instead of
reimplementing it. This does not only simplify the code but also makes
sure that cgit is consistent with Git when it comes to author parsing.

Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
I would also like to get rid of the angle brackets and only add them
when displaying the information as HTML. That would also result in email
filters getting email addresses without angle brackets which I consider
to be a good thing but it breaks backwards compatibility. Any opinions
on this are welcome.

 parsing.c | 45 +++++++++++++++++----------------------------
 1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/parsing.c b/parsing.c
index 3dbd122..7d34d11 100644
--- a/parsing.c
+++ b/parsing.c
@@ -71,36 +71,25 @@ static char *substr(const char *head, const char *tail)
 
 static const char *parse_user(const char *t, char **name, char **email, unsigned long *date)
 {
-	const char *p = t;
-	int mode = 1;
+	const char *line_end = strchrnul(t, '\n');
+	struct ident_split ident;
+	unsigned email_len;
 
-	while (p && *p) {
-		if (mode == 1 && *p == '<') {
-			*name = substr(t, p - 1);
-			t = p;
-			mode++;
-		} else if (mode == 1 && *p == '\n') {
-			*name = substr(t, p);
-			p++;
-			break;
-		} else if (mode == 2 && *p == '>') {
-			*email = substr(t, p + 1);
-			t = p;
-			mode++;
-		} else if (mode == 2 && *p == '\n') {
-			*email = substr(t, p);
-			p++;
-			break;
-		} else if (mode == 3 && isdigit(*p)) {
-			*date = atol(p);
-			mode++;
-		} else if (*p == '\n') {
-			p++;
-			break;
-		}
-		p++;
+	if (!split_ident_line(&ident, t, line_end - t)) {
+		*name = substr(ident.name_begin, ident.name_end);
+
+		email_len = ident.mail_end - ident.mail_begin;
+		*email = xmalloc(strlen("<") + email_len + strlen(">\0"));
+		sprintf(*email, "<%.*s>", email_len, ident.mail_begin);
+
+		if (ident.date_begin)
+			*date = strtoul(ident.date_begin, NULL, 10);
 	}
-	return p;
+
+	if (*line_end)
+		return line_end + 1;
+	else
+		return line_end;
 }
 
 #ifdef NO_ICONV
-- 
2.1.3



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

* [PATCH] Use split_ident_line() in parse_user()
  2014-12-17 12:19 [PATCH] Use split_ident_line() in parse_user() cgit
@ 2014-12-24  1:57 ` Jason
  2014-12-24  7:49   ` cgit
  2014-12-24  7:50 ` [PATCH v2] " cgit
  1 sibling, 1 reply; 5+ messages in thread
From: Jason @ 2014-12-24  1:57 UTC (permalink / raw)


On Wed, Dec 17, 2014 at 5:19 AM, Lukas Fleischer <cgit at cryptocrack.de>
wrote:

> Use Git's built-in ident line splitting algorithm instead of
> reimplementing it. This does not only simplify the code but also makes
> sure that cgit is consistent with Git when it comes to author parsing.
>

Thank heavens!

> +               email_len = ident.mail_end - ident.mail_begin;
> +               *email = xmalloc(strlen("<") + email_len + strlen(">\0"));
> +               sprintf(*email, "<%.*s>", email_len, ident.mail_begin);
> +
>

strlen(">\0") -- isn't the null superfluous? Cleanup and resubmit?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20141223/a2e20204/attachment.html>


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

* [PATCH] Use split_ident_line() in parse_user()
  2014-12-24  1:57 ` Jason
@ 2014-12-24  7:49   ` cgit
  0 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2014-12-24  7:49 UTC (permalink / raw)


On Wed, 24 Dec 2014 at 02:57:45, Jason A. Donenfeld wrote:
> On Wed, Dec 17, 2014 at 5:19 AM, Lukas Fleischer <cgit at cryptocrack.de>
> wrote:
> 
> > Use Git's built-in ident line splitting algorithm instead of
> > reimplementing it. This does not only simplify the code but also makes
> > sure that cgit is consistent with Git when it comes to author parsing.
> >
> 
> Thank heavens!
> 
> > +               email_len = ident.mail_end - ident.mail_begin;
> > +               *email = xmalloc(strlen("<") + email_len + strlen(">\0"));
> > +               sprintf(*email, "<%.*s>", email_len, ident.mail_begin);
> > +
> >
> 
> strlen(">\0") -- isn't the null superfluous? Cleanup and resubmit?

I think this is even wrong because it means the buffer won't be large
enough to hold the terminating null character. Will resubmit.


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

* [PATCH v2] Use split_ident_line() in parse_user()
  2014-12-17 12:19 [PATCH] Use split_ident_line() in parse_user() cgit
  2014-12-24  1:57 ` Jason
@ 2014-12-24  7:50 ` cgit
  2014-12-24  8:38   ` Jason
  1 sibling, 1 reply; 5+ messages in thread
From: cgit @ 2014-12-24  7:50 UTC (permalink / raw)


Use Git's built-in ident line splitting algorithm instead of
reimplementing it. This does not only simplify the code but also makes
sure that cgit is consistent with Git when it comes to author parsing.

Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
 parsing.c | 45 +++++++++++++++++----------------------------
 1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/parsing.c b/parsing.c
index 3dbd122..53c29bb 100644
--- a/parsing.c
+++ b/parsing.c
@@ -71,36 +71,25 @@ static char *substr(const char *head, const char *tail)
 
 static const char *parse_user(const char *t, char **name, char **email, unsigned long *date)
 {
-	const char *p = t;
-	int mode = 1;
+	const char *line_end = strchrnul(t, '\n');
+	struct ident_split ident;
+	unsigned email_len;
 
-	while (p && *p) {
-		if (mode == 1 && *p == '<') {
-			*name = substr(t, p - 1);
-			t = p;
-			mode++;
-		} else if (mode == 1 && *p == '\n') {
-			*name = substr(t, p);
-			p++;
-			break;
-		} else if (mode == 2 && *p == '>') {
-			*email = substr(t, p + 1);
-			t = p;
-			mode++;
-		} else if (mode == 2 && *p == '\n') {
-			*email = substr(t, p);
-			p++;
-			break;
-		} else if (mode == 3 && isdigit(*p)) {
-			*date = atol(p);
-			mode++;
-		} else if (*p == '\n') {
-			p++;
-			break;
-		}
-		p++;
+	if (!split_ident_line(&ident, t, line_end - 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);
+
+		if (ident.date_begin)
+			*date = strtoul(ident.date_begin, NULL, 10);
 	}
-	return p;
+
+	if (*line_end)
+		return line_end + 1;
+	else
+		return line_end;
 }
 
 #ifdef NO_ICONV
-- 
2.2.1



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

* [PATCH v2] Use split_ident_line() in parse_user()
  2014-12-24  7:50 ` [PATCH v2] " cgit
@ 2014-12-24  8:38   ` Jason
  0 siblings, 0 replies; 5+ messages in thread
From: Jason @ 2014-12-24  8:38 UTC (permalink / raw)


Merged, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20141224/5501f736/attachment.html>


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

end of thread, other threads:[~2014-12-24  8:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-17 12:19 [PATCH] Use split_ident_line() in parse_user() cgit
2014-12-24  1:57 ` Jason
2014-12-24  7:49   ` cgit
2014-12-24  7:50 ` [PATCH v2] " cgit
2014-12-24  8:38   ` Jason

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).