aboutsummaryrefslogtreecommitdiffstats
path: root/parsing.c
diff options
context:
space:
mode:
authorLukas Fleischer2014-12-24 08:50:11 +0100
committerJason A. Donenfeld2014-12-24 01:38:28 -0700
commit6f9e8a9659996281248c9002497148d489003bce (patch)
treeb295659449e6a29aff4b27eaf067006bbdbe4530 /parsing.c
parent2159414a3945f059a7e52a4900ffcd1ca665e102 (diff)
downloadcgit-6f9e8a9659996281248c9002497148d489003bce.tar.gz
cgit-6f9e8a9659996281248c9002497148d489003bce.tar.bz2
cgit-6f9e8a9659996281248c9002497148d489003bce.zip
Use split_ident_line() in parse_user()
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@cryptocrack.de>
Diffstat (limited to 'parsing.c')
-rw-r--r--parsing.c45
1 files 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)
71 71
72static const char *parse_user(const char *t, char **name, char **email, unsigned long *date) 72static const char *parse_user(const char *t, char **name, char **email, unsigned long *date)
73{ 73{
74 const char *p = t; 74 const char *line_end = strchrnul(t, '\n');
75 int mode = 1; 75 struct ident_split ident;
76 unsigned email_len;
76 77
77 while (p && *p) { 78 if (!split_ident_line(&ident, t, line_end - t)) {
78 if (mode == 1 && *p == '<') { 79 *name = substr(ident.name_begin, ident.name_end);
79 *name = substr(t, p - 1); 80
80 t = p; 81 email_len = ident.mail_end - ident.mail_begin;
81 mode++; 82 *email = xmalloc(strlen("<") + email_len + strlen(">") + 1);
82 } else if (mode == 1 && *p == '\n') { 83 sprintf(*email, "<%.*s>", email_len, ident.mail_begin);
83 *name = substr(t, p); 84
84 p++; 85 if (ident.date_begin)
85 break; 86 *date = strtoul(ident.date_begin, NULL, 10);
86 } else if (mode == 2 && *p == '>') {
87 *email = substr(t, p + 1);
88 t = p;
89 mode++;
90 } else if (mode == 2 && *p == '\n') {
91 *email = substr(t, p);
92 p++;
93 break;
94 } else if (mode == 3 && isdigit(*p)) {
95 *date = atol(p);
96 mode++;
97 } else if (*p == '\n') {
98 p++;
99 break;
100 }
101 p++;
102 } 87 }
103 return p; 88
89 if (*line_end)
90 return line_end + 1;
91 else
92 return line_end;
104} 93}
105 94
106#ifdef NO_ICONV 95#ifdef NO_ICONV