commit.c: use skip_prefix() instead of starts_with()
In record_author_date() & parse_gpg_output(), the callers of starts_with() not just want to know if the string starts with the prefix, but also can benefit from knowing the string that follows the prefix. By using skip_prefix(), we can do both at the same time. Helped-by: Max Horn <max@quendi.de> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
5f95c9f850
commit
147972b1a6
14
commit.c
14
commit.c
|
@ -548,7 +548,7 @@ define_commit_slab(author_date_slab, unsigned long);
|
||||||
static void record_author_date(struct author_date_slab *author_date,
|
static void record_author_date(struct author_date_slab *author_date,
|
||||||
struct commit *commit)
|
struct commit *commit)
|
||||||
{
|
{
|
||||||
const char *buf, *line_end;
|
const char *buf, *line_end, *ident_line;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
struct ident_split ident;
|
struct ident_split ident;
|
||||||
char *date_end;
|
char *date_end;
|
||||||
|
@ -566,14 +566,14 @@ static void record_author_date(struct author_date_slab *author_date,
|
||||||
buf;
|
buf;
|
||||||
buf = line_end + 1) {
|
buf = line_end + 1) {
|
||||||
line_end = strchrnul(buf, '\n');
|
line_end = strchrnul(buf, '\n');
|
||||||
if (!starts_with(buf, "author ")) {
|
ident_line = skip_prefix(buf, "author ");
|
||||||
|
if (!ident_line) {
|
||||||
if (!line_end[0] || line_end[1] == '\n')
|
if (!line_end[0] || line_end[1] == '\n')
|
||||||
return; /* end of header */
|
return; /* end of header */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (split_ident_line(&ident,
|
if (split_ident_line(&ident,
|
||||||
buf + strlen("author "),
|
ident_line, line_end - ident_line) ||
|
||||||
line_end - (buf + strlen("author "))) ||
|
|
||||||
!ident.date_begin || !ident.date_end)
|
!ident.date_begin || !ident.date_end)
|
||||||
goto fail_exit; /* malformed "author" line */
|
goto fail_exit; /* malformed "author" line */
|
||||||
break;
|
break;
|
||||||
|
@ -1193,10 +1193,8 @@ static void parse_gpg_output(struct signature_check *sigc)
|
||||||
for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
|
for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
|
||||||
const char *found, *next;
|
const char *found, *next;
|
||||||
|
|
||||||
if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
|
found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1);
|
||||||
/* At the very beginning of the buffer */
|
if (!found) {
|
||||||
found = buf + strlen(sigcheck_gpg_status[i].check + 1);
|
|
||||||
} else {
|
|
||||||
found = strstr(buf, sigcheck_gpg_status[i].check);
|
found = strstr(buf, sigcheck_gpg_status[i].check);
|
||||||
if (!found)
|
if (!found)
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue