rebase--interactive: count squash commits above 10 correctly
authorJeff King <peff@peff.net>
Sat, 7 Jan 2017 08:23:19 +0000 (03:23 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sun, 8 Jan 2017 03:26:53 +0000 (19:26 -0800)
We generate the squash commit message incrementally running
a sed script once for each commit. It parses "This is
a combination of <N> commits" from the first line of the
existing message, adds one to <N>, and uses the result as
the number of our current message.

Since f2d17068fd (i18n: rebase-interactive: mark comments of
squash for translation, 2016-06-17), the first line may be
localized, and sed uses a pretty liberal regex, looking for:

/^#.*([0-9][0-9]*)/

The "[0-9][0-9]*" tries to match double digits, but it
doesn't quite work. The first ".*" is greedy, so if you
have:

This is a combination of 10 commits.

it will eat up "This is a combination of 1", leaving "0" to
match the first "[0-9]" digit, and then skipping the
optional match of "[0-9]*".

As a result, the count resets every 10 commits, and a
15-commit squash would end up as:

# This is a combination of 5 commits.
# This is the 1st commit message:
...
# This is the commit message #2:
... and so on ..
# This is the commit message #10:
...
# This is the commit message #1:
...
# This is the commit message #2:
... etc, up to 5 ...

We can fix this by making the ".*" less greedy. Instead of
depending on ".*?" working portably, we can just limit the
match to non-digit characters, which accomplishes the same
thing.

Reported-by: Brandon Tolsch <btolsch@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-rebase--interactive.sh
index ca994c5c545cb0394fc5d355ecb6ea2fe5f1f193..4bca73c94cc9688a855220909ed3b98f53c4d481 100644 (file)
@@ -416,7 +416,7 @@ update_squash_messages () {
        if test -f "$squash_msg"; then
                mv "$squash_msg" "$squash_msg".bak || exit
                count=$(($(sed -n \
-                       -e "1s/^$comment_char.*\([0-9][0-9]*\).*/\1/p" \
+                       -e "1s/^$comment_char[^0-9]*\([0-9][0-9]*\).*/\1/p" \
                        -e "q" < "$squash_msg".bak)+1))
                {
                        printf '%s\n' "$comment_char $(eval_ngettext \