Merge branch 'js/find-commit-subject-ignore-leading-blanks' into maint

A helper function that takes the contents of a commit object and
finds its subject line did not ignore leading blank lines, as is
commonly done by other codepaths.  Make it ignore leading blank
lines to match.

* js/find-commit-subject-ignore-leading-blanks:
  reset --hard: skip blank lines when reporting the commit subject
  sequencer: use skip_blank_lines() to find the commit subject
  commit -C: skip blank lines at the beginning of the message
  commit.c: make find_commit_subject() more robust
  pretty: make the skip_blank_lines() function public
This commit is contained in:
Junio C Hamano 2016-07-28 11:25:50 -07:00
Родитель 053e2fb579 054a5aee6f
Коммит 4966b58f3e
7 изменённых файлов: 31 добавлений и 15 удалений

Просмотреть файл

@ -714,7 +714,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
char *buffer;
buffer = strstr(use_message_buffer, "\n\n");
if (buffer)
strbuf_addstr(&sb, buffer + 2);
strbuf_addstr(&sb, skip_blank_lines(buffer + 2));
hook_arg1 = "commit";
hook_arg2 = use_message;
} else if (fixup_message) {

Просмотреть файл

@ -103,7 +103,7 @@ static void print_new_head_line(struct commit *commit)
if (body) {
const char *eol;
size_t len;
body += 2;
body = skip_blank_lines(body + 2);
eol = strchr(body, '\n');
len = eol ? eol - body : strlen(body);
printf(" %.*s\n", (int) len, body);

Просмотреть файл

@ -414,7 +414,7 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
while (*p && (*p != '\n' || p[1] != '\n'))
p++;
if (*p) {
p += 2;
p = skip_blank_lines(p + 2);
for (eol = p; *eol && *eol != '\n'; eol++)
; /* do nothing */
} else

Просмотреть файл

@ -178,6 +178,7 @@ extern const char *format_subject(struct strbuf *sb, const char *msg,
const char *line_separator);
extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
extern int commit_format_is_empty(enum cmit_fmt);
extern const char *skip_blank_lines(const char *msg);
extern void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *context);

Просмотреть файл

@ -507,7 +507,7 @@ void pp_user_info(struct pretty_print_context *pp,
}
}
static int is_empty_line(const char *line, int *len_p)
static int is_blank_line(const char *line, int *len_p)
{
int len = *len_p;
while (len && isspace(line[len - 1]))
@ -516,14 +516,14 @@ static int is_empty_line(const char *line, int *len_p)
return !len;
}
static const char *skip_empty_lines(const char *msg)
const char *skip_blank_lines(const char *msg)
{
for (;;) {
int linelen = get_one_line(msg);
int ll = linelen;
if (!linelen)
break;
if (!is_empty_line(msg, &ll))
if (!is_blank_line(msg, &ll))
break;
msg += linelen;
}
@ -875,7 +875,7 @@ const char *format_subject(struct strbuf *sb, const char *msg,
int linelen = get_one_line(line);
msg += linelen;
if (!linelen || is_empty_line(line, &linelen))
if (!linelen || is_blank_line(line, &linelen))
break;
if (!sb)
@ -894,11 +894,11 @@ static void parse_commit_message(struct format_commit_context *c)
const char *msg = c->message + c->message_off;
const char *start = c->message;
msg = skip_empty_lines(msg);
msg = skip_blank_lines(msg);
c->subject_off = msg - start;
msg = format_subject(NULL, msg, NULL);
msg = skip_empty_lines(msg);
msg = skip_blank_lines(msg);
c->body_off = msg - start;
c->commit_message_parsed = 1;
@ -1718,7 +1718,7 @@ void pp_remainder(struct pretty_print_context *pp,
if (!linelen)
break;
if (is_empty_line(line, &linelen)) {
if (is_blank_line(line, &linelen)) {
if (first)
continue;
if (pp->fmt == CMIT_FMT_SHORT)
@ -1789,7 +1789,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
}
/* Skip excess blank lines at the beginning of body, if any... */
msg = skip_empty_lines(msg);
msg = skip_blank_lines(msg);
/* These formats treat the title line specially. */
if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)

Просмотреть файл

@ -544,10 +544,8 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
* information followed by "\n\n".
*/
p = strstr(msg.message, "\n\n");
if (p) {
p += 2;
strbuf_addstr(&msgbuf, p);
}
if (p)
strbuf_addstr(&msgbuf, skip_blank_lines(p + 2));
if (opts->record_origin) {
if (!has_conforming_footer(&msgbuf, NULL, 0))

Просмотреть файл

@ -87,4 +87,21 @@ test_expect_success 'blame --line-porcelain output' '
test_cmp expect actual
'
test_expect_success '--porcelain detects first non-blank line as subject' '
(
GIT_INDEX_FILE=.git/tmp-index &&
export GIT_INDEX_FILE &&
echo "This is it" >single-file &&
git add single-file &&
tree=$(git write-tree) &&
commit=$(printf "%s\n%s\n%s\n\n\n \noneline\n\nbody\n" \
"tree $tree" \
"author A <a@b.c> 123456789 +0000" \
"committer C <c@d.e> 123456789 +0000" |
git hash-object -w -t commit --stdin) &&
git blame --porcelain $commit -- single-file >output &&
grep "^summary oneline$" output
)
'
test_done