Skip to content

Commit 2982b65

Browse files
peffgitster
authored andcommitted
strbuf: accept a comment string for strbuf_stripspace()
As part of our transition to multi-byte comment characters, let's take a NUL-terminated string pointer for strbuf_stripspace(), rather than a single character. We can continue to support its feature of ignoring comments by accepting a NULL pointer (as opposed to the current behavior of a NUL byte). All of the callers have to be adjusted, but they can all just pass comment_line_str (or NULL). Inside the function we detect comments by comparing the first byte of a line to the comment character. We'll adjust that to use starts_with(), which will match multiple bytes (though for now, of course, we still only allow a single byte, so it's academic). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72a7d5d commit 2982b65

File tree

13 files changed

+20
-20
lines changed

13 files changed

+20
-20
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ static int parse_mail(struct am_state *state, const char *mail)
12861286

12871287
strbuf_addstr(&msg, "\n\n");
12881288
strbuf_addbuf(&msg, &mi.log_message);
1289-
strbuf_stripspace(&msg, '\0');
1289+
strbuf_stripspace(&msg, NULL);
12901290

12911291
assert(!state->author_name);
12921292
state->author_name = strbuf_detach(&author_name, NULL);

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ static int edit_branch_description(const char *branch_name)
678678
strbuf_release(&buf);
679679
return -1;
680680
}
681-
strbuf_stripspace(&buf, comment_line_char);
681+
strbuf_stripspace(&buf, comment_line_str);
682682

683683
strbuf_addf(&name, "branch.%s.description", branch_name);
684684
if (buf.len || exists)

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
890890
s->hints = 0;
891891

892892
if (clean_message_contents)
893-
strbuf_stripspace(&sb, '\0');
893+
strbuf_stripspace(&sb, NULL);
894894

895895
if (signoff)
896896
append_signoff(&sb, ignored_log_message_bytes(sb.buf, sb.len), 0);

builtin/notes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
223223
die(_("please supply the note contents using either -m or -F option"));
224224
}
225225
if (d->stripspace)
226-
strbuf_stripspace(&d->buf, comment_line_char);
226+
strbuf_stripspace(&d->buf, comment_line_str);
227227
}
228228
}
229229

@@ -264,7 +264,7 @@ static void concat_messages(struct note_data *d)
264264
if ((d->stripspace == UNSPECIFIED &&
265265
d->messages[i]->stripspace == STRIPSPACE) ||
266266
d->stripspace == STRIPSPACE)
267-
strbuf_stripspace(&d->buf, 0);
267+
strbuf_stripspace(&d->buf, NULL);
268268
strbuf_reset(&msg);
269269
}
270270
strbuf_release(&msg);

builtin/rebase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int edit_todo_file(unsigned flags)
204204
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
205205
return error_errno(_("could not read '%s'."), todo_file);
206206

207-
strbuf_stripspace(&todo_list.buf, comment_line_char);
207+
strbuf_stripspace(&todo_list.buf, comment_line_str);
208208
res = edit_todo_list(the_repository, &todo_list, &new_todo, NULL, NULL, flags);
209209
if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file,
210210
NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS)))

builtin/stripspace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
5959

6060
if (mode == STRIP_DEFAULT || mode == STRIP_COMMENTS)
6161
strbuf_stripspace(&buf,
62-
mode == STRIP_COMMENTS ? comment_line_char : '\0');
62+
mode == STRIP_COMMENTS ? comment_line_str : NULL);
6363
else
6464
comment_lines(&buf);
6565

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static void create_tag(const struct object_id *object, const char *object_ref,
310310

311311
if (opt->cleanup_mode != CLEANUP_NONE)
312312
strbuf_stripspace(buf,
313-
opt->cleanup_mode == CLEANUP_ALL ? comment_line_char : '\0');
313+
opt->cleanup_mode == CLEANUP_ALL ? comment_line_str : NULL);
314314

315315
if (!opt->message_given && !buf->len)
316316
die(_("no tag message?"));

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ static int can_use_local_refs(const struct add_opts *opts)
657657
strbuf_add_real_path(&path, get_worktree_git_dir(NULL));
658658
strbuf_addstr(&path, "/HEAD");
659659
strbuf_read_file(&contents, path.buf, 64);
660-
strbuf_stripspace(&contents, 0);
660+
strbuf_stripspace(&contents, NULL);
661661
strbuf_strip_suffix(&contents, "\n");
662662

663663
warning(_("HEAD points to an invalid (or orphaned) reference.\n"

gpg-interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,
586586
}
587587
}
588588

589-
strbuf_stripspace(&ssh_keygen_out, '\0');
590-
strbuf_stripspace(&ssh_keygen_err, '\0');
589+
strbuf_stripspace(&ssh_keygen_out, NULL);
590+
strbuf_stripspace(&ssh_keygen_err, NULL);
591591
/* Add stderr outputs to show the user actual ssh-keygen errors */
592592
strbuf_add(&ssh_keygen_out, ssh_principals_err.buf, ssh_principals_err.len);
593593
strbuf_add(&ssh_keygen_out, ssh_keygen_err.buf, ssh_keygen_err.len);

rebase-interactive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
130130
if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
131131
return -2;
132132

133-
strbuf_stripspace(&new_todo->buf, comment_line_char);
133+
strbuf_stripspace(&new_todo->buf, comment_line_str);
134134
if (initial && new_todo->buf.len == 0)
135135
return -3;
136136

sequencer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ void cleanup_message(struct strbuf *msgbuf,
11521152
strbuf_setlen(msgbuf, wt_status_locate_end(msgbuf->buf, msgbuf->len));
11531153
if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE)
11541154
strbuf_stripspace(msgbuf,
1155-
cleanup_mode == COMMIT_MSG_CLEANUP_ALL ? comment_line_char : '\0');
1155+
cleanup_mode == COMMIT_MSG_CLEANUP_ALL ? comment_line_str : NULL);
11561156
}
11571157

11581158
/*
@@ -1184,7 +1184,7 @@ int template_untouched(const struct strbuf *sb, const char *template_file,
11841184
return 0;
11851185

11861186
strbuf_stripspace(&tmpl,
1187-
cleanup_mode == COMMIT_MSG_CLEANUP_ALL ? comment_line_char : '\0');
1187+
cleanup_mode == COMMIT_MSG_CLEANUP_ALL ? comment_line_str : NULL);
11881188
if (!skip_prefix(sb->buf, tmpl.buf, &start))
11891189
start = sb->buf;
11901190
strbuf_release(&tmpl);
@@ -1557,7 +1557,7 @@ static int try_to_commit(struct repository *r,
15571557

15581558
if (cleanup != COMMIT_MSG_CLEANUP_NONE)
15591559
strbuf_stripspace(msg,
1560-
cleanup == COMMIT_MSG_CLEANUP_ALL ? comment_line_char : '\0');
1560+
cleanup == COMMIT_MSG_CLEANUP_ALL ? comment_line_str : NULL);
15611561
if ((flags & EDIT_MSG) && message_is_empty(msg, cleanup)) {
15621562
res = 1; /* run 'git commit' to display error message */
15631563
goto out;

strbuf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,10 @@ static size_t cleanup(char *line, size_t len)
10011001
*
10021002
* If last line does not have a newline at the end, one is added.
10031003
*
1004-
* Pass a non-NUL comment_prefix to skip every line starting
1004+
* Pass a non-NULL comment_prefix to skip every line starting
10051005
* with it.
10061006
*/
1007-
void strbuf_stripspace(struct strbuf *sb, char comment_prefix)
1007+
void strbuf_stripspace(struct strbuf *sb, const char *comment_prefix)
10081008
{
10091009
size_t empties = 0;
10101010
size_t i, j, len, newlen;
@@ -1018,7 +1018,7 @@ void strbuf_stripspace(struct strbuf *sb, char comment_prefix)
10181018
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
10191019

10201020
if (comment_prefix && len &&
1021-
sb->buf[i] == comment_prefix) {
1021+
starts_with(sb->buf + i, comment_prefix)) {
10221022
newlen = 0;
10231023
continue;
10241024
}

strbuf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,11 @@ int strbuf_getcwd(struct strbuf *sb);
513513
int strbuf_normalize_path(struct strbuf *sb);
514514

515515
/**
516-
* Strip whitespace from a buffer. If comment_prefix is non-NUL,
516+
* Strip whitespace from a buffer. If comment_prefix is non-NULL,
517517
* then lines beginning with that character are considered comments,
518518
* thus removed.
519519
*/
520-
void strbuf_stripspace(struct strbuf *buf, char comment_prefix);
520+
void strbuf_stripspace(struct strbuf *buf, const char *comment_prefix);
521521

522522
static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
523523
{

0 commit comments

Comments
 (0)