commit: make ignore_non_trailer take buf/len

Make ignore_non_trailer take a buf/len pair instead of struct strbuf.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Tan
2016-11-02 10:29:17 -07:00
committed by Junio C Hamano
parent e4319562bc
commit 710714aaa8
4 changed files with 14 additions and 14 deletions

View File

@ -790,7 +790,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
strbuf_stripspace(&sb, 0); strbuf_stripspace(&sb, 0);
if (signoff) if (signoff)
append_signoff(&sb, ignore_non_trailer(&sb), 0); append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0);
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len) if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
die_errno(_("could not write commit template")); die_errno(_("could not write commit template"));

View File

@ -1649,7 +1649,7 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
} }
/* /*
* Inspect sb and determine the true "end" of the log message, in * Inspect the given string and determine the true "end" of the log message, in
* order to find where to put a new Signed-off-by: line. Ignored are * order to find where to put a new Signed-off-by: line. Ignored are
* trailing comment lines and blank lines, and also the traditional * trailing comment lines and blank lines, and also the traditional
* "Conflicts:" block that is not commented out, so that we can use * "Conflicts:" block that is not commented out, so that we can use
@ -1659,37 +1659,37 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
* Returns the number of bytes from the tail to ignore, to be fed as * Returns the number of bytes from the tail to ignore, to be fed as
* the second parameter to append_signoff(). * the second parameter to append_signoff().
*/ */
int ignore_non_trailer(struct strbuf *sb) int ignore_non_trailer(const char *buf, size_t len)
{ {
int boc = 0; int boc = 0;
int bol = 0; int bol = 0;
int in_old_conflicts_block = 0; int in_old_conflicts_block = 0;
while (bol < sb->len) { while (bol < len) {
char *next_line; const char *next_line = memchr(buf + bol, '\n', len - bol);
if (!(next_line = memchr(sb->buf + bol, '\n', sb->len - bol))) if (!next_line)
next_line = sb->buf + sb->len; next_line = buf + len;
else else
next_line++; next_line++;
if (sb->buf[bol] == comment_line_char || sb->buf[bol] == '\n') { if (buf[bol] == comment_line_char || buf[bol] == '\n') {
/* is this the first of the run of comments? */ /* is this the first of the run of comments? */
if (!boc) if (!boc)
boc = bol; boc = bol;
/* otherwise, it is just continuing */ /* otherwise, it is just continuing */
} else if (starts_with(sb->buf + bol, "Conflicts:\n")) { } else if (starts_with(buf + bol, "Conflicts:\n")) {
in_old_conflicts_block = 1; in_old_conflicts_block = 1;
if (!boc) if (!boc)
boc = bol; boc = bol;
} else if (in_old_conflicts_block && sb->buf[bol] == '\t') { } else if (in_old_conflicts_block && buf[bol] == '\t') {
; /* a pathname in the conflicts block */ ; /* a pathname in the conflicts block */
} else if (boc) { } else if (boc) {
/* the previous was not trailing comment */ /* the previous was not trailing comment */
boc = 0; boc = 0;
in_old_conflicts_block = 0; in_old_conflicts_block = 0;
} }
bol = next_line - sb->buf; bol = next_line - buf;
} }
return boc ? sb->len - boc : 0; return boc ? len - boc : 0;
} }

View File

@ -355,7 +355,7 @@ extern const char *find_commit_header(const char *msg, const char *key,
size_t *out_len); size_t *out_len);
/* Find the end of the log message, the right place for a new trailer. */ /* Find the end of the log message, the right place for a new trailer. */
extern int ignore_non_trailer(struct strbuf *sb); extern int ignore_non_trailer(const char *buf, size_t len);
typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra, typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra,
void *cb_data); void *cb_data);

View File

@ -842,7 +842,7 @@ static int find_trailer_end(struct strbuf **lines, int patch_start)
for (i = 0; i < patch_start; i++) for (i = 0; i < patch_start; i++)
strbuf_addbuf(&sb, lines[i]); strbuf_addbuf(&sb, lines[i]);
ignore_bytes = ignore_non_trailer(&sb); ignore_bytes = ignore_non_trailer(sb.buf, sb.len);
strbuf_release(&sb); strbuf_release(&sb);
for (i = patch_start - 1; i >= 0 && ignore_bytes > 0; i--) for (i = patch_start - 1; i >= 0 && ignore_bytes > 0; i--)
ignore_bytes -= lines[i]->len; ignore_bytes -= lines[i]->len;