From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Anthony Foiani <anthony.foiani@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] Improve errors from 'git diff --no-index'.
Date: Mon, 23 May 2011 16:50:38 -0400 [thread overview]
Message-ID: <20110523205038.GB6281@sigill.intra.peff.net> (raw)
In-Reply-To: <7vpqn9usqt.fsf@alter.siamese.dyndns.org>
On Mon, May 23, 2011 at 12:22:34PM -0700, Junio C Hamano wrote:
> > $ # with my patch:
> > $ ../git/git-diff /tmp/{foo,bar}
> > warning: neither '/tmp/foo' nor '/tmp/bar' are tracked, forcing --no-index
>
> I actually consider this a regression. We are giving an output that the
> user wanted to see, and I do not see a reason why we need to warn.
Agreed.
> One thing that I have always been unhappy about --no-index is that it does
> not really mesh well with the notion of what a "git diff" is. "git diff"
> inherently is an operation to take two collections of contents labeled
> with paths, and show series of patch output between corresponding paths in
> these collections, while rename/copy detection may affect the definition
> of "correspoinding paths".
It's not just --no-index that breaks this abstraction. How about:
git diff HEAD:Makefile v1.7.5:Makefile
or even
git diff :1:Makefile :2:Makefile
?
So I think even without --no-index, we have the concept that diff
compares two "things", and that only some of those things are a
collection of paths (either a tree-ish, or possibly a directory, but as
you note below, I suspect the latter is broken).
And obviously the two "things" must either both be single items, or must
both be collections, as any other comparison doesn't really make sense.
We do catch this, but it's another place where it might be nice to have
better error messages:
$ git diff HEAD:Makefile HEAD
usage: git diff [<options>] [<commit> [<commit>]] [--] [<path>...]
> $ git diff [--no-index] /tmp/foo /tmp/bar
>
> but such a request does not compare "two collections of paths that have
> corresponding paths" at all. We could say we are comparing a collection
> that has tmp/foo with another that has tmp/bar, but then we should either
> emit a delete patch for tmp/foo and a create patch for tmp/bar, or emit a
> rename patch to create tmp/bar out of tmp/foo if we want to be consistent.
>
> But that consistency goes totally against what the users would expect.
Right. If I give git two single items to compare, rather than
collections, I am not going to expect renames at all, which
fundamentally involve path movement. Those are a collection thing, and I
asked for a much narrower scope.
> The _only_ use of --no-index that is in line with what "git diff" does is
> to compare two directories as the "two collections of contents" above,
> i.e.
>
> $ git diff --no-index old/ new/
>
> and then support pathspecs, like this:
>
> $ git diff --no-index old/ new/ -- Makefile '*.c'
>
> But I do not think the current implementation does not even support this
> only sane usecase.
Yeah, I would expect git to support that, but knowing the builtin/diff.c
code, I am not too surprised if it doesn't. :)
On the subject of things git diff should probably do but I doubt anybody
cares enough to implement, it would be nice to be able to do:
git diff $merge^1 $merge^2 $merge
and get the combined diff that "git show $merge" would give you, but
without the log cruft.
I also wonder if the reverse would be useful:
git diff $ours $theirs `git merge-base $ours $theirs`
which would produce something like a reverse combined diff, or "how have
we diverged". E.g.,:
diff --combined file
index $base..$ours,$theirs
--- a/file
--- b/file
@@@ -1,1 +1,1 +1,1 @@@
--what was in the base
+ what is in ours
+what is in theirs
But that is more than just a git-diff interface problem; we would
actually have to write the reverse-combined diff code (I _think_ it
should be a pretty simple reversal of the regular combined diff, but I
haven't really thought it through).
-Peff
next prev parent reply other threads:[~2011-05-23 20:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-22 19:17 [PATCH] Improve errors from 'git diff --no-index' Anthony Foiani
[not found] ` <7vlixyw4cx.fsf@alter.siamese.dyndns.org>
2011-05-23 2:35 ` Anthony Foiani
2011-05-23 3:18 ` Junio C Hamano
2011-05-23 4:05 ` Anthony Foiani
2011-05-23 19:22 ` Junio C Hamano
2011-05-23 20:50 ` Jeff King [this message]
2011-05-23 21:24 ` Anthony Foiani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110523205038.GB6281@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=anthony.foiani@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).