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>
这个提交包含在:
父节点
2159414a39
当前提交
6f9e8a9659
45
parsing.c
45
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)
|
static const char *parse_user(const char *t, char **name, char **email, unsigned long *date)
|
||||||
{
|
{
|
||||||
const char *p = t;
|
const char *line_end = strchrnul(t, '\n');
|
||||||
int mode = 1;
|
struct ident_split ident;
|
||||||
|
unsigned email_len;
|
||||||
|
|
||||||
while (p && *p) {
|
if (!split_ident_line(&ident, t, line_end - t)) {
|
||||||
if (mode == 1 && *p == '<') {
|
*name = substr(ident.name_begin, ident.name_end);
|
||||||
*name = substr(t, p - 1);
|
|
||||||
t = p;
|
email_len = ident.mail_end - ident.mail_begin;
|
||||||
mode++;
|
*email = xmalloc(strlen("<") + email_len + strlen(">") + 1);
|
||||||
} else if (mode == 1 && *p == '\n') {
|
sprintf(*email, "<%.*s>", email_len, ident.mail_begin);
|
||||||
*name = substr(t, p);
|
|
||||||
p++;
|
if (ident.date_begin)
|
||||||
break;
|
*date = strtoul(ident.date_begin, NULL, 10);
|
||||||
} 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++;
|
|
||||||
}
|
}
|
||||||
return p;
|
|
||||||
|
if (*line_end)
|
||||||
|
return line_end + 1;
|
||||||
|
else
|
||||||
|
return line_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NO_ICONV
|
#ifdef NO_ICONV
|
||||||
|
正在加载...
x
在新工单中引用
屏蔽一个用户