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>

Jonathan Tan committed Nov 2, 2016 at 10:29 UTC 710714aaa822acbad14f1b7100fa2776d2bc8ce6
4 files changed +14 -14
builtin/commit.c
+1 -1
@@ -790,7 +790,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
790 strbuf_stripspace(&sb, 0);
791
792 if (signoff)
793 - append_signoff(&sb, ignore_non_trailer(&sb), 0);
793 + append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0);
794
795 if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
796 die_errno(_("could not write commit template"));
commit.c
+11 -11
@@ -1649,7 +1649,7 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
1649 }
1650
1651 /*
1652 - * Inspect sb and determine the true "end" of the log message, in
1652 + * Inspect the given string and determine the true "end" of the log message, in
1653 * order to find where to put a new Signed-off-by: line. Ignored are
1654 * trailing comment lines and blank lines, and also the traditional
1655 * "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
1659 * Returns the number of bytes from the tail to ignore, to be fed as
1660 * the second parameter to append_signoff().
1661 */
1662 -int ignore_non_trailer(struct strbuf *sb)
1662 +int ignore_non_trailer(const char *buf, size_t len)
1663 {
1664 int boc = 0;
1665 int bol = 0;
1666 int in_old_conflicts_block = 0;
1667
1668 - while (bol < sb->len) {
1669 - char *next_line;
1668 + while (bol < len) {
1669 + const char *next_line = memchr(buf + bol, '\n', len - bol);
1670
1671 - if (!(next_line = memchr(sb->buf + bol, '\n', sb->len - bol)))
1672 - next_line = sb->buf + sb->len;
1671 + if (!next_line)
1672 + next_line = buf + len;
1673 else
1674 next_line++;
1675
1676 - if (sb->buf[bol] == comment_line_char || sb->buf[bol] == '\n') {
1676 + if (buf[bol] == comment_line_char || buf[bol] == '\n') {
1677 /* is this the first of the run of comments? */
1678 if (!boc)
1679 boc = bol;
1680 /* otherwise, it is just continuing */
1681 - } else if (starts_with(sb->buf + bol, "Conflicts:\n")) {
1681 + } else if (starts_with(buf + bol, "Conflicts:\n")) {
1682 in_old_conflicts_block = 1;
1683 if (!boc)
1684 boc = bol;
1685 - } else if (in_old_conflicts_block && sb->buf[bol] == '\t') {
1685 + } else if (in_old_conflicts_block && buf[bol] == '\t') {
1686 ; /* a pathname in the conflicts block */
1687 } else if (boc) {
1688 /* the previous was not trailing comment */
1689 boc = 0;
1690 in_old_conflicts_block = 0;
1691 }
1692 - bol = next_line - sb->buf;
1692 + bol = next_line - buf;
1693 }
1694 - return boc ? sb->len - boc : 0;
1694 + return boc ? len - boc : 0;
1695 }
commit.h
+1 -1
@@ -355,7 +355,7 @@ extern const char *find_commit_header(const char *msg, const char *key,
355 size_t *out_len);
356
357 /* Find the end of the log message, the right place for a new trailer. */
358 -extern int ignore_non_trailer(struct strbuf *sb);
358 +extern int ignore_non_trailer(const char *buf, size_t len);
359
360 typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra,
361 void *cb_data);
trailer.c
+1 -1
@@ -842,7 +842,7 @@ static int find_trailer_end(struct strbuf **lines, int patch_start)
842
843 for (i = 0; i < patch_start; i++)
844 strbuf_addbuf(&sb, lines[i]);
845 - ignore_bytes = ignore_non_trailer(&sb);
845 + ignore_bytes = ignore_non_trailer(sb.buf, sb.len);
846 strbuf_release(&sb);
847 for (i = patch_start - 1; i >= 0 && ignore_bytes > 0; i--)
848 ignore_bytes -= lines[i]->len;