Skip to content

Commit ad98a58

Browse files
chriscoolgitster
authored andcommitted
blame: use find_commit_subject() instead of custom code
Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49b7120 commit ad98a58

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

builtin/blame.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,8 @@ static void get_commit_info(struct commit *commit,
13711371
int detailed)
13721372
{
13731373
int len;
1374-
char *tmp, *endp, *reencoded, *message;
1374+
const char *subject;
1375+
char *reencoded, *message;
13751376
static char author_name[1024];
13761377
static char author_mail[1024];
13771378
static char committer_name[1024];
@@ -1413,22 +1414,13 @@ static void get_commit_info(struct commit *commit,
14131414
&ret->committer_time, &ret->committer_tz);
14141415

14151416
ret->summary = summary_buf;
1416-
tmp = strstr(message, "\n\n");
1417-
if (!tmp) {
1418-
error_out:
1417+
len = find_commit_subject(message, &subject);
1418+
if (len && len < sizeof(summary_buf)) {
1419+
memcpy(summary_buf, subject, len);
1420+
summary_buf[len] = 0;
1421+
} else {
14191422
sprintf(summary_buf, "(%s)", sha1_to_hex(commit->object.sha1));
1420-
free(reencoded);
1421-
return;
14221423
}
1423-
tmp += 2;
1424-
endp = strchr(tmp, '\n');
1425-
if (!endp)
1426-
endp = tmp + strlen(tmp);
1427-
len = endp - tmp;
1428-
if (len >= sizeof(summary_buf) || len == 0)
1429-
goto error_out;
1430-
memcpy(summary_buf, tmp, len);
1431-
summary_buf[len] = 0;
14321424
free(reencoded);
14331425
}
14341426

0 commit comments

Comments
 (0)