Re: [PATCH] interpret-trailers: obey scissors lines
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 15, 2017, 02:12 UTC
- Message-ID
- <xmqqfug6yiks.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20170514035652.rn5npxxflku6s5k4@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 22 quoted lines
>> If a commit message is being editted as "verbose", it will contain a
>> scissors string ("-- >8 --") and a diff:
>>
>> my subject
>>
>> # ------------------------ >8 ------------------------
>> # Do not touch the line above.
>> # Everything below will be removed.
>> diff --git a/foo.txt b/foo.txt
>> index 5716ca5..7601807 100644
>> --- a/foo.txt
>> +++ b/foo.txt
>> @@ -1 +1 @@
>> -bar
>> +baz
>>
>> interpret-trailers doesn't interpret the scissors and therefore places
>> trailer information after the diff. A simple reproduction is:
>>
>> git config commit.verbose true
>> GIT_EDITOR='git interpret-trailers --in-place --trailer Acked-by:me' \
>> git commit --amendSo, "git commit --amend --verbose" prepares something like the above example and passes it to the GIT_EDITOR. The problem description indicates that because interpret-trailers (which happens to be used as the GIT_EDITOR) treats the cut-line used by "git commit" just like any other random line, it tries to find the trailer block way below, in the patch text. I agree that it is a problem. But...
Show 14 quoted lines
>> diff --git a/builtin/commit.c b/builtin/commit.c >> index 2de5f6cc6..2ce9c339d 100644 >> --- a/builtin/commit.c >> +++ b/builtin/commit.c >> @@ -1735,7 +1735,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) >> >> if (verbose || /* Truncate the message just before the diff, if any. */ >> cleanup_mode == CLEANUP_SCISSORS) >> - wt_status_truncate_message_at_cut_line(&sb); >> + strbuf_setlen(&sb, >> + wt_status_last_nonscissors_index(sb.buf, sb.len)); > > This hunk surprised me at first (that we would need to touch commit.c at > all), but the refactoring makes sense.
This still surprises me. If the problem is in interpret-trailers, why do we even need to touch cmd_commit()? If GIT_EDITOR returns us
my subject
Acked-by: me
# ------------------------ >8 ------------------------
# Do not touch the line above.
# Everything below will be removed.
diff --git a/foo.txt b/foo.txt
index 5716ca5..7601807 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-bar
+bazafter this patch fixes interpret-trailers, wouldn't the cmd_commit() function work as expected without any change?
Puzzled.
The proposed log message calls the cut-line "scissors", but that is probably a source of this confusion. The cut-line and scissors do not have much in commmon. For one thing, scissors is a mechanism to discard everything _ABOVE_ it. The cut-line we see in this example, on the other hand, is about discarding everything _BELOW_ it.