Skip to content

Commit 710714a

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e431956 commit 710714a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
790790
strbuf_stripspace(&sb, 0);
791791

792792
if (signoff)
793-
append_signoff(&sb, ignore_non_trailer(&sb), 0);
793+
append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0);
794794

795795
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
796796
die_errno(_("could not write commit template"));

commit.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
16491649
}
16501650

16511651
/*
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
16531653
* order to find where to put a new Signed-off-by: line. Ignored are
16541654
* trailing comment lines and blank lines, and also the traditional
16551655
* "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
16591659
* Returns the number of bytes from the tail to ignore, to be fed as
16601660
* the second parameter to append_signoff().
16611661
*/
1662-
int ignore_non_trailer(struct strbuf *sb)
1662+
int ignore_non_trailer(const char *buf, size_t len)
16631663
{
16641664
int boc = 0;
16651665
int bol = 0;
16661666
int in_old_conflicts_block = 0;
16671667

1668-
while (bol < sb->len) {
1669-
char *next_line;
1668+
while (bol < len) {
1669+
const char *next_line = memchr(buf + bol, '\n', len - bol);
16701670

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;
16731673
else
16741674
next_line++;
16751675

1676-
if (sb->buf[bol] == comment_line_char || sb->buf[bol] == '\n') {
1676+
if (buf[bol] == comment_line_char || buf[bol] == '\n') {
16771677
/* is this the first of the run of comments? */
16781678
if (!boc)
16791679
boc = bol;
16801680
/* otherwise, it is just continuing */
1681-
} else if (starts_with(sb->buf + bol, "Conflicts:\n")) {
1681+
} else if (starts_with(buf + bol, "Conflicts:\n")) {
16821682
in_old_conflicts_block = 1;
16831683
if (!boc)
16841684
boc = bol;
1685-
} else if (in_old_conflicts_block && sb->buf[bol] == '\t') {
1685+
} else if (in_old_conflicts_block && buf[bol] == '\t') {
16861686
; /* a pathname in the conflicts block */
16871687
} else if (boc) {
16881688
/* the previous was not trailing comment */
16891689
boc = 0;
16901690
in_old_conflicts_block = 0;
16911691
}
1692-
bol = next_line - sb->buf;
1692+
bol = next_line - buf;
16931693
}
1694-
return boc ? sb->len - boc : 0;
1694+
return boc ? len - boc : 0;
16951695
}

commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ extern const char *find_commit_header(const char *msg, const char *key,
355355
size_t *out_len);
356356

357357
/* 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);
359359

360360
typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra,
361361
void *cb_data);

trailer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ static int find_trailer_end(struct strbuf **lines, int patch_start)
842842

843843
for (i = 0; i < patch_start; i++)
844844
strbuf_addbuf(&sb, lines[i]);
845-
ignore_bytes = ignore_non_trailer(&sb);
845+
ignore_bytes = ignore_non_trailer(sb.buf, sb.len);
846846
strbuf_release(&sb);
847847
for (i = patch_start - 1; i >= 0 && ignore_bytes > 0; i--)
848848
ignore_bytes -= lines[i]->len;

0 commit comments

Comments
 (0)