aboutsummaryrefslogtreecommitdiffstats
path: root/parsing.c
diff options
context:
space:
mode:
authorLukas Fleischer <cgit@cryptocrack.de>2014-12-24 08:50:11 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2014-12-24 09:38:28 +0100
commit6f9e8a9659996281248c9002497148d489003bce (patch)
treeb295659449e6a29aff4b27eaf067006bbdbe4530 /parsing.c
parent2159414a3945f059a7e52a4900ffcd1ca665e102 (diff)
downloadcgit-6f9e8a9659996281248c9002497148d489003bce.tar.gz
cgit-6f9e8a9659996281248c9002497148d489003bce.tar.xz
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)
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