Skip to content

Commit 600559b

Browse files
peffgitster
authored andcommitted
find multi-byte comment chars in NUL-terminated strings
Several parts of the code need to identify lines that begin with the comment character, and do so with a simple byte equality check. As part of the transition to handling multi-byte characters, we need to match all of the bytes. For cases where we are looking in a NUL-terminated string, we can just use starts_with(), which checks all of the characters in comment_line_str. Note that we can drop the "line.len" check in wt-status.c's read_rebase_todolist(). The starts_with() function handles the case of an empty haystack buffer (it will always return false for a non-empty prefix). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f99e1d9 commit 600559b

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

add-patch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
11391139
for (i = 0; i < s->buf.len; ) {
11401140
size_t next = find_next_line(&s->buf, i);
11411141

1142-
if (s->buf.buf[i] != comment_line_char)
1142+
if (!starts_with(s->buf.buf + i, comment_line_str))
11431143
strbuf_add(&s->plain, s->buf.buf + i, next - i);
11441144
i = next;
11451145
}

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@ static int update_squash_messages(struct repository *r,
20032003
return error(_("could not read '%s'"),
20042004
rebase_path_squash_msg());
20052005

2006-
eol = buf.buf[0] != comment_line_char ?
2006+
eol = !starts_with(buf.buf, comment_line_str) ?
20072007
buf.buf : strchrnul(buf.buf, '\n');
20082008

20092009
strbuf_addf(&header, "%s ", comment_line_str);

trailer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ static void parse_trailers(struct trailer_info *info,
10131013
for (i = 0; i < info->trailer_nr; i++) {
10141014
int separator_pos;
10151015
char *trailer = info->trailers[i];
1016-
if (trailer[0] == comment_line_char)
1016+
if (starts_with(trailer, comment_line_str))
10171017
continue;
10181018
separator_pos = find_separator(trailer, separators);
10191019
if (separator_pos >= 1) {

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
13821382
git_path("%s", fname));
13831383
}
13841384
while (!strbuf_getline_lf(&line, f)) {
1385-
if (line.len && line.buf[0] == comment_line_char)
1385+
if (starts_with(line.buf, comment_line_str))
13861386
continue;
13871387
strbuf_trim(&line);
13881388
if (!line.len)

0 commit comments

Comments
 (0)