зеркало из https://github.com/microsoft/git.git
strbuf: accept a comment string for strbuf_add_commented_lines()
As part of our transition to multi-byte comment characters, let's take a NUL-terminated string pointer for strbuf_add_commented_lines() rather than a single character. All of the callers have to be adjusted; most can just pass comment_line_str rather than comment_line_char. And now our "cheat" in strbuf_commented_addf() can go away, as we can take the full string from it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
3a35d96284
Коммит
a1bb146aaf
|
@ -179,7 +179,7 @@ static void write_commented_object(int fd, const struct object_id *object)
|
|||
|
||||
if (strbuf_read(&buf, show.out, 0) < 0)
|
||||
die_errno(_("could not read 'show' output"));
|
||||
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_char);
|
||||
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_str);
|
||||
write_or_die(fd, cbuf.buf, cbuf.len);
|
||||
|
||||
strbuf_release(&cbuf);
|
||||
|
@ -207,10 +207,10 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
|
|||
copy_obj_to_fd(fd, old_note);
|
||||
|
||||
strbuf_addch(&buf, '\n');
|
||||
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
|
||||
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
|
||||
strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)),
|
||||
comment_line_char);
|
||||
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
|
||||
comment_line_str);
|
||||
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
|
||||
write_or_die(fd, buf.buf, buf.len);
|
||||
|
||||
write_commented_object(fd, object);
|
||||
|
|
|
@ -13,7 +13,7 @@ static void comment_lines(struct strbuf *buf)
|
|||
size_t len;
|
||||
|
||||
msg = strbuf_detach(buf, &len);
|
||||
strbuf_add_commented_lines(buf, msg, len, comment_line_char);
|
||||
strbuf_add_commented_lines(buf, msg, len, comment_line_str);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -510,7 +510,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
|
|||
if (sig->len) {
|
||||
strbuf_addch(tagbuf, '\n');
|
||||
strbuf_add_commented_lines(tagbuf, sig->buf, sig->len,
|
||||
comment_line_char);
|
||||
comment_line_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,7 +557,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
|
|||
strbuf_add_commented_lines(&tagline,
|
||||
origins.items[first_tag].string,
|
||||
strlen(origins.items[first_tag].string),
|
||||
comment_line_char);
|
||||
comment_line_str);
|
||||
strbuf_insert(&tagbuf, 0, tagline.buf,
|
||||
tagline.len);
|
||||
strbuf_release(&tagline);
|
||||
|
@ -566,7 +566,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
|
|||
strbuf_add_commented_lines(&tagbuf,
|
||||
origins.items[i].string,
|
||||
strlen(origins.items[i].string),
|
||||
comment_line_char);
|
||||
comment_line_str);
|
||||
fmt_tag_signature(&tagbuf, &sig, buf, len);
|
||||
}
|
||||
strbuf_release(&payload);
|
||||
|
|
|
@ -78,7 +78,7 @@ void append_todo_help(int command_count,
|
|||
shortrevisions, shortonto, command_count);
|
||||
}
|
||||
|
||||
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
|
||||
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
|
||||
|
||||
if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR)
|
||||
msg = _("\nDo not remove any line. Use 'drop' "
|
||||
|
@ -87,7 +87,7 @@ void append_todo_help(int command_count,
|
|||
msg = _("\nIf you remove a line here "
|
||||
"THAT COMMIT WILL BE LOST.\n");
|
||||
|
||||
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
|
||||
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
|
||||
|
||||
if (edit_todo)
|
||||
msg = _("\nYou are editing the todo file "
|
||||
|
@ -98,7 +98,7 @@ void append_todo_help(int command_count,
|
|||
msg = _("\nHowever, if you remove everything, "
|
||||
"the rebase will be aborted.\n\n");
|
||||
|
||||
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
|
||||
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
|
||||
}
|
||||
|
||||
int edit_todo_list(struct repository *r, struct todo_list *todo_list,
|
||||
|
|
|
@ -1851,7 +1851,7 @@ static void add_commented_lines(struct strbuf *buf, const void *str, size_t len)
|
|||
s += count;
|
||||
len -= count;
|
||||
}
|
||||
strbuf_add_commented_lines(buf, s, len, comment_line_char);
|
||||
strbuf_add_commented_lines(buf, s, len, comment_line_str);
|
||||
}
|
||||
|
||||
/* Does the current fixup chain contain a squash command? */
|
||||
|
@ -1950,7 +1950,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
|
|||
strbuf_addf(buf, _(nth_commit_msg_fmt),
|
||||
++opts->current_fixup_count + 1);
|
||||
strbuf_addstr(buf, "\n\n");
|
||||
strbuf_add_commented_lines(buf, body, commented_len, comment_line_char);
|
||||
strbuf_add_commented_lines(buf, body, commented_len, comment_line_str);
|
||||
/* buf->buf may be reallocated so store an offset into the buffer */
|
||||
fixup_off = buf->len;
|
||||
strbuf_addstr(buf, body + commented_len);
|
||||
|
@ -2041,7 +2041,7 @@ static int update_squash_messages(struct repository *r,
|
|||
strbuf_addstr(&buf, "\n\n");
|
||||
if (is_fixup_flag(command, flag))
|
||||
strbuf_add_commented_lines(&buf, body, strlen(body),
|
||||
comment_line_char);
|
||||
comment_line_str);
|
||||
else
|
||||
strbuf_addstr(&buf, body);
|
||||
|
||||
|
@ -2061,7 +2061,7 @@ static int update_squash_messages(struct repository *r,
|
|||
++opts->current_fixup_count + 1);
|
||||
strbuf_addstr(&buf, "\n\n");
|
||||
strbuf_add_commented_lines(&buf, body, strlen(body),
|
||||
comment_line_char);
|
||||
comment_line_str);
|
||||
} else
|
||||
return error(_("unknown command: %d"), command);
|
||||
repo_unuse_commit_buffer(r, commit, message);
|
||||
|
|
16
strbuf.c
16
strbuf.c
|
@ -359,13 +359,9 @@ static void add_lines(struct strbuf *out,
|
|||
}
|
||||
|
||||
void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
|
||||
size_t size, char comment_prefix)
|
||||
size_t size, const char *comment_prefix)
|
||||
{
|
||||
char prefix[2];
|
||||
|
||||
prefix[0] = comment_prefix;
|
||||
prefix[1] = '\0';
|
||||
add_lines(out, prefix, buf, size, 1);
|
||||
add_lines(out, comment_prefix, buf, size, 1);
|
||||
}
|
||||
|
||||
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
|
||||
|
@ -379,13 +375,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
|
|||
strbuf_vaddf(&buf, fmt, params);
|
||||
va_end(params);
|
||||
|
||||
/*
|
||||
* TODO Our commented_lines helper does not yet understand
|
||||
* comment strings. But since we know that the strings are
|
||||
* always single-char, we can cheat for the moment, and
|
||||
* fix this later.
|
||||
*/
|
||||
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix[0]);
|
||||
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix);
|
||||
if (incomplete_line)
|
||||
sb->buf[--sb->len] = '\0';
|
||||
|
||||
|
|
2
strbuf.h
2
strbuf.h
|
@ -288,7 +288,7 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
|
|||
*/
|
||||
void strbuf_add_commented_lines(struct strbuf *out,
|
||||
const char *buf, size_t size,
|
||||
char comment_prefix);
|
||||
const char *comment_prefix);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -1028,7 +1028,7 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom
|
|||
if (s->display_comment_prefix) {
|
||||
size_t len;
|
||||
summary_content = strbuf_detach(&summary, &len);
|
||||
strbuf_add_commented_lines(&summary, summary_content, len, comment_line_char);
|
||||
strbuf_add_commented_lines(&summary, summary_content, len, comment_line_str);
|
||||
free(summary_content);
|
||||
}
|
||||
|
||||
|
@ -1104,7 +1104,7 @@ void wt_status_append_cut_line(struct strbuf *buf)
|
|||
const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
|
||||
|
||||
strbuf_commented_addf(buf, comment_line_str, "%s", cut_line);
|
||||
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char);
|
||||
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_str);
|
||||
}
|
||||
|
||||
void wt_status_add_cut_line(FILE *fp)
|
||||
|
|
Загрузка…
Ссылка в новой задаче