summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-07-28 11:25:50 -0700
committerJunio C Hamano <gitster@pobox.com>2016-07-28 11:25:50 -0700
commit4966b58f3e1f295e3fb22560006b1db717b56f37 (patch)
treeaf3813c17a7bc43822bd9d7b0b6ca008eeff8789
parent053e2fb5798374d1628b8cd4d797a64e48c944b6 (diff)
parent054a5aee6f3e8e90d96f7b3f76f5f55752561c59 (diff)
downloadgit-4966b58f3e1f295e3fb22560006b1db717b56f37.tar.gz
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
-rw-r--r--builtin/commit.c2
-rw-r--r--builtin/reset.c2
-rw-r--r--commit.c2
-rw-r--r--commit.h1
-rw-r--r--pretty.c16
-rw-r--r--sequencer.c6
-rwxr-xr-xt/t8008-blame-formats.sh17
7 files changed, 31 insertions, 15 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index 163dbcabf3..37702f3561 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -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) {
diff --git a/builtin/reset.c b/builtin/reset.c
index 092c3a5399..e8c5767030 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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);
diff --git a/commit.c b/commit.c
index 3f4f371e5e..24d4715f24 100644
--- a/commit.c
+++ b/commit.c
@@ -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
diff --git a/commit.h b/commit.h
index 0c923f05f7..adf57d6c94 100644
--- a/commit.h
+++ b/commit.h
@@ -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);
diff --git a/pretty.c b/pretty.c
index 8d182472e7..b27165603a 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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)
diff --git a/sequencer.c b/sequencer.c
index c6362d63f3..a33c39b64f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -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))
diff --git a/t/t8008-blame-formats.sh b/t/t8008-blame-formats.sh
index 29f84a6dd1..92c8e792d1 100755
--- a/t/t8008-blame-formats.sh
+++ b/t/t8008-blame-formats.sh
@@ -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