git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/1] Fix git rebase --stat -i <unrelated-history>
@ 2018-11-27 11:13 Johannes Schindelin via GitGitGadget
  2018-11-27 11:13 ` [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history Johannes Schindelin via GitGitGadget
  2018-11-29 13:01 ` [PATCH v2 0/1] Fix git rebase --stat -i <unrelated-history> Johannes Schindelin via GitGitGadget
  0 siblings, 2 replies; 7+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2018-11-27 11:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

We're really entering obscure territory here, I would say.

To trigger the bug, two things have to come together: the user must have
asked for a diffstat afterwards, and the commits need to have been rebased
onto a completely unrelated commit history (i.e. there must exist no merge
base between the pre-rebase HEAD and the post-rebase HEAD).

Please note that this bug existed already in the scripted rebase, but it was
never detected because the scripted version would not even perform any error
checking.

It will make Junio very happy that I squashed the regression test in to the
patch that fixes it. The reason, however, was not to make Junio happy (I
hope to make him happy by fixing bugs), but simply that an earlier iteration
of test would only fail with the built-in rebase, but not with the scripted
version. The current version would fail with the scripted version, but I'll
save the time to split the patch again now.

Johannes Schindelin (1):
  rebase --stat: fix when rebasing to an unrelated history

 builtin/rebase.c          |  8 +++++---
 git-legacy-rebase.sh      |  6 ++++--
 t/t3406-rebase-message.sh | 10 ++++++++++
 3 files changed, 19 insertions(+), 5 deletions(-)


base-commit: a1598010f775d82b5adf12c29d0f5bc9b41434c6
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-88%2Fdscho%2Frebase-stat-fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-88/dscho/rebase-stat-fix-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/88
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history
  2018-11-27 11:13 [PATCH 0/1] Fix git rebase --stat -i <unrelated-history> Johannes Schindelin via GitGitGadget
@ 2018-11-27 11:13 ` Johannes Schindelin via GitGitGadget
  2018-11-29  5:51   ` Junio C Hamano
  2018-11-29 13:01 ` [PATCH v2 0/1] Fix git rebase --stat -i <unrelated-history> Johannes Schindelin via GitGitGadget
  1 sibling, 1 reply; 7+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2018-11-27 11:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

When rebasing to a commit history that has no common commits with the
current branch, there is no merge base. The scripted version of the `git
rebase` command was not prepared for that and spewed out

	fatal: ambiguous argument '': unknown revision or path not in
	the working tree.

but then continued (due to lack of error checking).

The built-in version of the `git rebase` command blindly translated that
shell script code, assuming that there is no need to test whether there
*was* a merge base, and due to its better error checking, exited with a
fatal error (because it tried to read the object with hash 00000000...
as a tree).

Fix both scripted and built-in versions to output something sensibly,
and add a regression test to keep this working in all eternity.

Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/rebase.c          |  8 +++++---
 git-legacy-rebase.sh      |  6 ++++--
 t/t3406-rebase-message.sh | 10 ++++++++++
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 5b3e5baec8..9e4b0b564f 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1483,7 +1483,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 
 		if (options.flags & REBASE_VERBOSE)
 			printf(_("Changes from %s to %s:\n"),
-				oid_to_hex(&merge_base),
+				is_null_oid(&merge_base) ?
+				"(empty)" : oid_to_hex(&merge_base),
 				oid_to_hex(&options.onto->object.oid));
 
 		/* We want color (if set), but no pager */
@@ -1494,8 +1495,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
 		opts.detect_rename = DIFF_DETECT_RENAME;
 		diff_setup_done(&opts);
-		diff_tree_oid(&merge_base, &options.onto->object.oid,
-			      "", &opts);
+		diff_tree_oid(is_null_oid(&merge_base) ?
+			      the_hash_algo->empty_tree : &merge_base,
+			      &options.onto->object.oid, "", &opts);
 		diffcore_std(&opts);
 		diff_flush(&opts);
 	}
diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh
index b97ffdc9dd..be3b241676 100755
--- a/git-legacy-rebase.sh
+++ b/git-legacy-rebase.sh
@@ -718,10 +718,12 @@ if test -n "$diffstat"
 then
 	if test -n "$verbose"
 	then
-		echo "$(eval_gettext "Changes from \$mb to \$onto:")"
+		mb_display="${mb:-(empty)}"
+		echo "$(eval_gettext "Changes from \$mb_display to \$onto:")"
 	fi
+	mb_tree="${mb:-$(git hash-object -t tree /dev/null)}"
 	# We want color (if set), but no pager
-	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
+	GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"
 fi
 
 test -n "$interactive_rebase" && run_specific_rebase
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 38bd876cab..a1ee912118 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -91,4 +91,14 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
 	test_i18ngrep "Invalid whitespace option" err
 '
 
+test_expect_success 'rebase -i onto unrelated history' '
+	git init unrelated &&
+	test_commit -C unrelated 1 &&
+	git -C unrelated remote add -f origin "$PWD" &&
+	git -C unrelated branch --set-upstream-to=origin/master &&
+	git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
+	test_i18ngrep "Changes from (empty)" actual &&
+	test_i18ngrep "5 files changed" actual
+'
+
 test_done
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history
  2018-11-27 11:13 ` [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history Johannes Schindelin via GitGitGadget
@ 2018-11-29  5:51   ` Junio C Hamano
  2018-11-29 12:51     ` Johannes Schindelin
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2018-11-29  5:51 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget; +Cc: git, Johannes Schindelin

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> The built-in version of the `git rebase` command blindly translated that
> shell script code, assuming that there is no need to test whether there
> *was* a merge base, and due to its better error checking, exited with a
> fatal error (because it tried to read the object with hash 00000000...
> as a tree).

And the scripted version produced a wrong result because it did not
check the lack of merge base and fed an empty string (presumably, as
that is what you would get from mb=$(merge-base A B) when A and B
are unrelated) to later steps?  If that is the case, then it *is* a
very significant thing to record here.  As it was not merely "failed
to stop due to lack of error checking", but a lot worse.  It was
producing a wrong result.

A more faithful reimplementation would not have exited with fatal
error, but would have produced the same wrong result, so "a better
error checking caused the reimplementation die where the original
did not die" may be correct but is much less important than the fact
that "the logic used in the original to produce diffstat forgot that
there may not be a merge base and would not have worked correctly in
such a case, and that is what we are correcting" is more important.

Please descibe the issue as such, if that is the case (I cannot read
from the description in the proposed log message if that is the
case---but I came to the conclusion that it is what you wanted to
fix reading the code).

>  		if (options.flags & REBASE_VERBOSE)
>  			printf(_("Changes from %s to %s:\n"),
> -				oid_to_hex(&merge_base),
> +				is_null_oid(&merge_base) ?
> +				"(empty)" : oid_to_hex(&merge_base),

I am not sure (empty) is a good idea for two reasons.  It is going
to be inserted into an translated string without translation.  Also
it is too similar to the fallback string used by some printf
implementations when NULL was given to %s by mistake.

If there weren't i18n issues, I would suggest to use "empty merge
base" or "empty tree" instead, but the old one would have shown
0{40}, so perhaps empty_tree_oid_hex() is a good substitute?

> @@ -1494,8 +1495,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  			DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
>  		opts.detect_rename = DIFF_DETECT_RENAME;
>  		diff_setup_done(&opts);
> -		diff_tree_oid(&merge_base, &options.onto->object.oid,
> -			      "", &opts);
> +		diff_tree_oid(is_null_oid(&merge_base) ?
> +			      the_hash_algo->empty_tree : &merge_base,
> +			      &options.onto->object.oid, "", &opts);

The original would have run "git diff '' $onto", and died with an
error message, so both the original and the reimplementation were
failing.  Just in different ways ;-)

> diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh
> index b97ffdc9dd..be3b241676 100755
> --- a/git-legacy-rebase.sh
> +++ b/git-legacy-rebase.sh
> @@ -718,10 +718,12 @@ if test -n "$diffstat"
>  then
>  	if test -n "$verbose"
>  	then
> -		echo "$(eval_gettext "Changes from \$mb to \$onto:")"
> +		mb_display="${mb:-(empty)}"
> +		echo "$(eval_gettext "Changes from \$mb_display to \$onto:")"
>  	fi
> +	mb_tree="${mb:-$(git hash-object -t tree /dev/null)}"
>  	# We want color (if set), but no pager
> -	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
> +	GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"

Code fix for diff-tree invocation, both in the builtin/ version and
this one, looks correct.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history
  2018-11-29  5:51   ` Junio C Hamano
@ 2018-11-29 12:51     ` Johannes Schindelin
  2018-11-30  1:40       ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Schindelin @ 2018-11-29 12:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin via GitGitGadget, git

Hi Junio,

On Thu, 29 Nov 2018, Junio C Hamano wrote:

> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
> 
> > The built-in version of the `git rebase` command blindly translated that
> > shell script code, assuming that there is no need to test whether there
> > *was* a merge base, and due to its better error checking, exited with a
> > fatal error (because it tried to read the object with hash 00000000...
> > as a tree).
> 
> And the scripted version produced a wrong result because it did not
> check the lack of merge base and fed an empty string (presumably, as
> that is what you would get from mb=$(merge-base A B) when A and B
> are unrelated) to later steps?  If that is the case, then it *is* a
> very significant thing to record here.  As it was not merely "failed
> to stop due to lack of error checking", but a lot worse.  It was
> producing a wrong result.

Indeed. But it was only in the `--stat` reporting, so it did not produce
an incorrect rebased history.

> A more faithful reimplementation would not have exited with fatal
> error, but would have produced the same wrong result, so "a better
> error checking caused the reimplementation die where the original
> did not die" may be correct but is much less important than the fact
> that "the logic used in the original to produce diffstat forgot that
> there may not be a merge base and would not have worked correctly in
> such a case, and that is what we are correcting" is more important.

True.

> Please descibe the issue as such, if that is the case (I cannot read
> from the description in the proposed log message if that is the
> case---but I came to the conclusion that it is what you wanted to
> fix reading the code).

Indeed, my commit message is a bit too close to what I fixed, and not
enough about what needed to be fixed.

> >  		if (options.flags & REBASE_VERBOSE)
> >  			printf(_("Changes from %s to %s:\n"),
> > -				oid_to_hex(&merge_base),
> > +				is_null_oid(&merge_base) ?
> > +				"(empty)" : oid_to_hex(&merge_base),
> 
> I am not sure (empty) is a good idea for two reasons.  It is going
> to be inserted into an translated string without translation.

Oooops.

> Also it is too similar to the fallback string used by some printf
> implementations when NULL was given to %s by mistake.

You mean `(null)`? That was actually intentional, I just thought that
`(empty)` would be different enough...

> If there weren't i18n issues, I would suggest to use "empty merge
> base" or "empty tree" instead, but the old one would have shown
> 0{40}, so perhaps empty_tree_oid_hex() is a good substitute?

As this is a user-facing message, I'd rather avoid something like
`empty_tree_oid_hex()`, which to every Git user who does not happen to be
a Git developer, too, must sound very cryptic.

But I guess that I should not be so lazy and really use two different
messages here:

	Changes from <merge-base> to <onto>

and if there is no merge base,

	Changes in <onto>

Will fix.

> > @@ -1494,8 +1495,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
> >  			DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
> >  		opts.detect_rename = DIFF_DETECT_RENAME;
> >  		diff_setup_done(&opts);
> > -		diff_tree_oid(&merge_base, &options.onto->object.oid,
> > -			      "", &opts);
> > +		diff_tree_oid(is_null_oid(&merge_base) ?
> > +			      the_hash_algo->empty_tree : &merge_base,
> > +			      &options.onto->object.oid, "", &opts);
> 
> The original would have run "git diff '' $onto", and died with an
> error message, so both the original and the reimplementation were
> failing.  Just in different ways ;-)

Right.

> > diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh
> > index b97ffdc9dd..be3b241676 100755
> > --- a/git-legacy-rebase.sh
> > +++ b/git-legacy-rebase.sh
> > @@ -718,10 +718,12 @@ if test -n "$diffstat"
> >  then
> >  	if test -n "$verbose"
> >  	then
> > -		echo "$(eval_gettext "Changes from \$mb to \$onto:")"
> > +		mb_display="${mb:-(empty)}"
> > +		echo "$(eval_gettext "Changes from \$mb_display to \$onto:")"
> >  	fi
> > +	mb_tree="${mb:-$(git hash-object -t tree /dev/null)}"
> >  	# We want color (if set), but no pager
> > -	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
> > +	GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"
> 
> Code fix for diff-tree invocation, both in the builtin/ version and
> this one, looks correct.

Okay. I fixed the two things you pointed out, just waiting for the Linux
phase to finish (I don't think there is anything OS-specific in this
patch, so I trust macOS and Windows to pass if Linux passes):
https://git-for-windows.visualstudio.com/git/_build/results?buildId=26116

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 0/1] Fix git rebase --stat -i <unrelated-history>
  2018-11-27 11:13 [PATCH 0/1] Fix git rebase --stat -i <unrelated-history> Johannes Schindelin via GitGitGadget
  2018-11-27 11:13 ` [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history Johannes Schindelin via GitGitGadget
@ 2018-11-29 13:01 ` Johannes Schindelin via GitGitGadget
  2018-11-29 13:01   ` [PATCH v2 1/1] rebase --stat: fix when rebasing to an unrelated history Johannes Schindelin via GitGitGadget
  1 sibling, 1 reply; 7+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2018-11-29 13:01 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

We're really entering obscure territory here, I would say.

To trigger the bug, two things have to come together: the user must have
asked for a diffstat afterwards, and the commits need to have been rebased
onto a completely unrelated commit history (i.e. there must exist no merge
base between the pre-rebase HEAD and the post-rebase HEAD).

Please note that this bug existed already in the scripted rebase, but it was
never detected because the scripted version would not even perform any error
checking.

It will make Junio very happy that I squashed the regression test in to the
patch that fixes it. The reason, however, was not to make Junio happy (I
hope to make him happy by fixing bugs), but simply that an earlier iteration
of test would only fail with the built-in rebase, but not with the scripted
version. The current version would fail with the scripted version, but I'll
save the time to split the patch again now.

Changes since v1:

 * The commit message now talks more about what we should do in case that
   there is no merge base, rather than stressing the differences between the
   way scripted vs built-in rebase handled it (both buggy, and fixed by this
   patch).
 * In case that there is no merge base, it no longer reports "Changes from
   (empty) to ..." but "Changes to ...", which should be a lot less
   controversial.

Johannes Schindelin (1):
  rebase --stat: fix when rebasing to an unrelated history

 builtin/rebase.c          | 18 ++++++++++++------
 git-legacy-rebase.sh      | 10 ++++++++--
 t/t3406-rebase-message.sh | 10 ++++++++++
 3 files changed, 30 insertions(+), 8 deletions(-)


base-commit: a1598010f775d82b5adf12c29d0f5bc9b41434c6
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-88%2Fdscho%2Frebase-stat-fix-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-88/dscho/rebase-stat-fix-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/88

Range-diff vs v1:

 1:  680385e4bd ! 1:  190c7856ad rebase --stat: fix when rebasing to an unrelated history
     @@ -3,22 +3,21 @@
          rebase --stat: fix when rebasing to an unrelated history
      
          When rebasing to a commit history that has no common commits with the
     -    current branch, there is no merge base. The scripted version of the `git
     -    rebase` command was not prepared for that and spewed out
     +    current branch, there is no merge base. In diffstat mode, this means
     +    that we cannot compare to the merge base, but we have to compare to the
     +    empty tree instead.
      
     -            fatal: ambiguous argument '': unknown revision or path not in
     -            the working tree.
     +    Also, if running in verbose diffstat mode, we should not output
      
     -    but then continued (due to lack of error checking).
     +            Changes from <merge-base> to <onto>
      
     -    The built-in version of the `git rebase` command blindly translated that
     -    shell script code, assuming that there is no need to test whether there
     -    *was* a merge base, and due to its better error checking, exited with a
     -    fatal error (because it tried to read the object with hash 00000000...
     -    as a tree).
     +    as that does not make sense without any merge base.
      
     -    Fix both scripted and built-in versions to output something sensibly,
     -    and add a regression test to keep this working in all eternity.
     +    Note: neither scripted nor built-in versoin of `git rebase` were
     +    prepared for this situation well. We use this opportunity not only to
     +    fix the bug(s), but also to make both versions' output consistent in
     +    this instance. And add a regression test to keep this working in all
     +    eternity.
      
          Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
     @@ -27,15 +26,25 @@
      --- a/builtin/rebase.c
      +++ b/builtin/rebase.c
      @@
     + 	if (options.flags & REBASE_DIFFSTAT) {
     + 		struct diff_options opts;
       
     - 		if (options.flags & REBASE_VERBOSE)
     - 			printf(_("Changes from %s to %s:\n"),
     +-		if (options.flags & REBASE_VERBOSE)
     +-			printf(_("Changes from %s to %s:\n"),
      -				oid_to_hex(&merge_base),
     -+				is_null_oid(&merge_base) ?
     -+				"(empty)" : oid_to_hex(&merge_base),
     - 				oid_to_hex(&options.onto->object.oid));
     +-				oid_to_hex(&options.onto->object.oid));
     ++		if (options.flags & REBASE_VERBOSE) {
     ++			if (is_null_oid(&merge_base))
     ++				printf(_("Changes to %s:\n"),
     ++				       oid_to_hex(&options.onto->object.oid));
     ++			else
     ++				printf(_("Changes from %s to %s:\n"),
     ++				       oid_to_hex(&merge_base),
     ++				       oid_to_hex(&options.onto->object.oid));
     ++		}
       
       		/* We want color (if set), but no pager */
     + 		diff_setup(&opts);
      @@
       			DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
       		opts.detect_rename = DIFF_DETECT_RENAME;
     @@ -57,8 +66,12 @@
       	if test -n "$verbose"
       	then
      -		echo "$(eval_gettext "Changes from \$mb to \$onto:")"
     -+		mb_display="${mb:-(empty)}"
     -+		echo "$(eval_gettext "Changes from \$mb_display to \$onto:")"
     ++		if test -z "$mb"
     ++		then
     ++			echo "$(eval_gettext "Changes to \$onto:")"
     ++		else
     ++			echo "$(eval_gettext "Changes from \$mb to \$onto:")"
     ++		fi
       	fi
      +	mb_tree="${mb:-$(git hash-object -t tree /dev/null)}"
       	# We want color (if set), but no pager
     @@ -81,7 +94,7 @@
      +	git -C unrelated remote add -f origin "$PWD" &&
      +	git -C unrelated branch --set-upstream-to=origin/master &&
      +	git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
     -+	test_i18ngrep "Changes from (empty)" actual &&
     ++	test_i18ngrep "Changes to " actual &&
      +	test_i18ngrep "5 files changed" actual
      +'
      +

-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/1] rebase --stat: fix when rebasing to an unrelated history
  2018-11-29 13:01 ` [PATCH v2 0/1] Fix git rebase --stat -i <unrelated-history> Johannes Schindelin via GitGitGadget
@ 2018-11-29 13:01   ` Johannes Schindelin via GitGitGadget
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2018-11-29 13:01 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

When rebasing to a commit history that has no common commits with the
current branch, there is no merge base. In diffstat mode, this means
that we cannot compare to the merge base, but we have to compare to the
empty tree instead.

Also, if running in verbose diffstat mode, we should not output

	Changes from <merge-base> to <onto>

as that does not make sense without any merge base.

Note: neither scripted nor built-in versoin of `git rebase` were
prepared for this situation well. We use this opportunity not only to
fix the bug(s), but also to make both versions' output consistent in
this instance. And add a regression test to keep this working in all
eternity.

Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/rebase.c          | 18 ++++++++++++------
 git-legacy-rebase.sh      | 10 ++++++++--
 t/t3406-rebase-message.sh | 10 ++++++++++
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 5b3e5baec8..1c6f817f4b 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1481,10 +1481,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	if (options.flags & REBASE_DIFFSTAT) {
 		struct diff_options opts;
 
-		if (options.flags & REBASE_VERBOSE)
-			printf(_("Changes from %s to %s:\n"),
-				oid_to_hex(&merge_base),
-				oid_to_hex(&options.onto->object.oid));
+		if (options.flags & REBASE_VERBOSE) {
+			if (is_null_oid(&merge_base))
+				printf(_("Changes to %s:\n"),
+				       oid_to_hex(&options.onto->object.oid));
+			else
+				printf(_("Changes from %s to %s:\n"),
+				       oid_to_hex(&merge_base),
+				       oid_to_hex(&options.onto->object.oid));
+		}
 
 		/* We want color (if set), but no pager */
 		diff_setup(&opts);
@@ -1494,8 +1499,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
 		opts.detect_rename = DIFF_DETECT_RENAME;
 		diff_setup_done(&opts);
-		diff_tree_oid(&merge_base, &options.onto->object.oid,
-			      "", &opts);
+		diff_tree_oid(is_null_oid(&merge_base) ?
+			      the_hash_algo->empty_tree : &merge_base,
+			      &options.onto->object.oid, "", &opts);
 		diffcore_std(&opts);
 		diff_flush(&opts);
 	}
diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh
index b97ffdc9dd..b4c7dbfa57 100755
--- a/git-legacy-rebase.sh
+++ b/git-legacy-rebase.sh
@@ -718,10 +718,16 @@ if test -n "$diffstat"
 then
 	if test -n "$verbose"
 	then
-		echo "$(eval_gettext "Changes from \$mb to \$onto:")"
+		if test -z "$mb"
+		then
+			echo "$(eval_gettext "Changes to \$onto:")"
+		else
+			echo "$(eval_gettext "Changes from \$mb to \$onto:")"
+		fi
 	fi
+	mb_tree="${mb:-$(git hash-object -t tree /dev/null)}"
 	# We want color (if set), but no pager
-	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
+	GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"
 fi
 
 test -n "$interactive_rebase" && run_specific_rebase
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 38bd876cab..c2c9950568 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -91,4 +91,14 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
 	test_i18ngrep "Invalid whitespace option" err
 '
 
+test_expect_success 'rebase -i onto unrelated history' '
+	git init unrelated &&
+	test_commit -C unrelated 1 &&
+	git -C unrelated remote add -f origin "$PWD" &&
+	git -C unrelated branch --set-upstream-to=origin/master &&
+	git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
+	test_i18ngrep "Changes to " actual &&
+	test_i18ngrep "5 files changed" actual
+'
+
 test_done
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history
  2018-11-29 12:51     ` Johannes Schindelin
@ 2018-11-30  1:40       ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2018-11-30  1:40 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Johannes Schindelin via GitGitGadget, git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> But I guess that I should not be so lazy and really use two different
> messages here:
>
> 	Changes from <merge-base> to <onto>
>
> and if there is no merge base,
>
> 	Changes in <onto>

Ah, that's excellent.

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-11-30  1:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-27 11:13 [PATCH 0/1] Fix git rebase --stat -i <unrelated-history> Johannes Schindelin via GitGitGadget
2018-11-27 11:13 ` [PATCH 1/1] rebase --stat: fix when rebasing to an unrelated history Johannes Schindelin via GitGitGadget
2018-11-29  5:51   ` Junio C Hamano
2018-11-29 12:51     ` Johannes Schindelin
2018-11-30  1:40       ` Junio C Hamano
2018-11-29 13:01 ` [PATCH v2 0/1] Fix git rebase --stat -i <unrelated-history> Johannes Schindelin via GitGitGadget
2018-11-29 13:01   ` [PATCH v2 1/1] rebase --stat: fix when rebasing to an unrelated history Johannes Schindelin via GitGitGadget

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).