threads / bug / 14841

[BUG] git diff-tree --stdin doesn't accept two trees

Subject: [BUG] git diff-tree --stdin doesn't accept two trees

## tl;dr

6 messages between Aug 5, 2008 and Aug 6, 2008.

replies: 5people: 2as markdown or json

Karl Hasselström· Aug 5, 2008, 16:48 UTC · lore

I'm trying to use diff-tree --stdin to diff several trees in one go. But I just get error messages when I feed it two space-separated trees (one commit works fine):

  $ echo $(git rev-parse HEAD^{tree}) $(git rev-parse HEAD^^{tree}) | git diff-tree -p --stdin
  error: Object 7bfd9971f77438858e412be0219ec78afb3ca46f not a commit
This is at odds with the documentation:
  --stdin::
        When '--stdin' is specified, the command does not take
        <tree-ish> arguments from the command line.  Instead, it
        reads either one <commit> or a pair of <tree-ish>
        separated with a single space from its standard input.

I tried reading the code to figure out what's wrong, and as far as I can tell the code to do this is there, but seems to be protected by logic that aborts everything unless the whole input line is a valid commit. Or maybe I'm just confused ...

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Junio C Hamano· Aug 5, 2008, 20:07 UTC · re: Karl Hasselström · lore

Re: [BUG] git diff-tree --stdin doesn't accept two trees

Karl Hasselström <kha@treskal.com> writes:
Show 19 quoted lines
> I'm trying to use diff-tree --stdin to diff several trees in one go.
> But I just get error messages when I feed it two space-separated trees
> (one commit works fine):
>
>   $ echo $(git rev-parse HEAD^{tree}) $(git rev-parse HEAD^^{tree}) | git diff-tree -p --stdin
>   error: Object 7bfd9971f77438858e412be0219ec78afb3ca46f not a commit
>
> This is at odds with the documentation:
>
>   --stdin::
>         When '--stdin' is specified, the command does not take
>         <tree-ish> arguments from the command line.  Instead, it
>         reads either one <commit> or a pair of <tree-ish>
>         separated with a single space from its standard input.
>
> I tried reading the code to figure out what's wrong, and as far as I
> can tell the code to do this is there, but seems to be protected by
> logic that aborts everything unless the whole input line is a valid
> commit. Or maybe I'm just confused ...
No, the documentation was made wrong during 1.2.0 timeperiod.

The feature of --stdin to take a commit and its parents on one line was broken before that to support the common

	rev-list --parents $commits... -- $paths... |
        diff-tree --stdin -v -p

usage pattern by Porcelains. For diff-tree to talk sensibly about commits, it needs to see commits, not just trees.

 
Junio C Hamano· Aug 6, 2008, 05:32 UTC · re: Junio C Hamano · lore

[PATCH] fix diff-tree --stdin documentation

Long time ago, the feature of "diff-tree --stdin" to take a commit and its parents on one line was broken, and did not support the common:

    git rev-list --parents $commits... -- $paths... |
    git diff-tree --stdin -v -p

usage pattern by Porcelains properly. For diff-tree to talk sensibly about commits, it needs to see commits, not just trees; the code was fixed to take list of commits on the standard input in 1.2.0.

However we left the documentation stale for a long time, until Karl Hasselström finally noticed it very recently.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt
index 8c8f35b..1fdf20d 100644
--- a/Documentation/git-diff-tree.txt
+++ b/Documentation/git-diff-tree.txt
@@ -49,13 +49,13 @@ include::diff-options.txt[]
 --stdin::
 	When '--stdin' is specified, the command does not take
 	<tree-ish> arguments from the command line.  Instead, it
-	reads either one <commit> or a pair of <tree-ish>
+	reads either one <commit> or a list of <commit>
 	separated with a single space from its standard input.
 +
 When a single commit is given on one line of such input, it compares
 the commit with its parents.  The following flags further affects its
-behavior.  This does not apply to the case where two <tree-ish>
-separated with a single space are given.
+behavior.  The remaining commits, when given, are used as if they are
+parents of the first commit.
 
 -m::
 	By default, 'git-diff-tree --stdin' does not show
Karl Hasselström· Aug 6, 2008, 10:04 UTC · re: Junio C Hamano · lore

Re: [PATCH] fix diff-tree --stdin documentation

On 2008-08-05 22:32:28 -0700, Junio C Hamano wrote:
> -	reads either one <commit> or a pair of <tree-ish>
> +	reads either one <commit> or a list of <commit>

Thanks. Didn't quite solve my problem though, since diffing trees was what I wanted to use diff-tree for. :-/ But I think I can rephrase my problem so that I give it a commit instead.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Karl Hasselström· Aug 6, 2008, 11:53 UTC · re: Junio C Hamano · lore

Re: [BUG] git diff-tree --stdin doesn't accept two trees

On 2008-08-05 13:07:17 -0700, Junio C Hamano wrote:
Show 16 quoted lines
> Karl Hasselström <kha@treskal.com> writes:
>
> > I'm trying to use diff-tree --stdin to diff several trees in one
> > go. But I just get error messages when I feed it two
> > space-separated trees (one commit works fine):
>
> No, the documentation was made wrong during 1.2.0 timeperiod.
>
> The feature of --stdin to take a commit and its parents on one line was
> broken before that to support the common
>
>         rev-list --parents $commits... -- $paths... |
>                 diff-tree --stdin -v -p
>
> usage pattern by Porcelains.  For diff-tree to talk sensibly about
> commits, it needs to see commits, not just trees.

But is there any fundamental reason why it couldn't accept tree-ishes as well? It only talks about commits if asked to do so with command-line options.

Or would that break existing users somehow?
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Junio C Hamano· Aug 6, 2008, 15:31 UTC · re: Karl Hasselström · lore

Re: [BUG] git diff-tree --stdin doesn't accept two trees

Karl Hasselström <kha@treskal.com> writes:
Show 11 quoted lines
>> The feature of --stdin to take a commit and its parents on one line was
>> broken before that to support the common
>>
>>         rev-list --parents $commits... -- $paths... |
>>                 diff-tree --stdin -v -p
>>
>> usage pattern by Porcelains.  For diff-tree to talk sensibly about
>> commits, it needs to see commits, not just trees.
>
> But is there any fundamental reason why it couldn't accept tree-ishes
> as well?

The -v option given to diff-tree is the key. Without it, it could take trees.

← back to recent threads