revert: refactor code to find commit subject in find_commit_subject() · wolfpython/git@11af2aa · GitHub
Skip to content

Commit 11af2aa

Browse files
chriscoolgitster
authored andcommitted
revert: refactor code to find commit subject in find_commit_subject()
Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2c048a3 commit 11af2aa

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

builtin/revert.c

Lines changed: 2 additions & 12 deletions

commit.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ int parse_commit(struct commit *item)
315315
return ret;
316316
}
317317

318+
int find_commit_subject(const char *commit_buffer, const char **subject)
319+
{
320+
const char *eol;
321+
const char *p = commit_buffer;
322+
323+
while (*p && (*p != '\n' || p[1] != '\n'))
324+
p++;
325+
if (*p) {
326+
p += 2;
327+
for (eol = p; *eol && *eol != '\n'; eol++)
328+
; /* do nothing */
329+
} else
330+
eol = p;
331+
332+
*subject = p;
333+
334+
return eol - p;
335+
}
336+
318337
struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
319338
{
320339
struct commit_list *new_list = xmalloc(sizeof(struct commit_list));

commit.h

Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)