Re: [Annoyance] "git log .." thinks ".." is ambiguous
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 2, 2011, 20:36 UTC
- Message-ID
- <7vhb9clu0n.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20110502193321.GB10487@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 22 quoted lines
> On Mon, May 02, 2011 at 12:15:23PM -0700, Junio C Hamano wrote: > >> Either end of revision range operator can be omitted to default to >> HEAD, as in "origin.." (what did I do since I forked) or "..origin" (what >> did they do since I forked). But this resulted in ".." to be interpreted >> as an empty range "HEAD..HEAD", and worse yet, because ".." does exist on >> the filesystem, we get this annoying output: >> >> $ cd Documentation/howto >> $ git log .. ;# give me recent commits that touch Documentation/ area. >> fatal: ambiguous argument '..': both revision and filename >> Use '--' to separate filenames from revisions >> >> Surely we could say "git log .. --", but we shouldn't have to. > > I got slightly confused reading this, because I thought at first you > wanted ".." to be some kind of magic rev specifier. In particular, your > last line should say: > > git log -- .. > > no?
Yeah, sorry about that. Or "git log ../".
And a matching "rev-parse" update should look like this. I wonder if we could share some code between the two, though...
Documentation/revisions.txt | 7 +++++++ builtin/rev-parse.c | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index b290b61..ceed820 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -213,6 +213,13 @@ of 'r1' and 'r2' and is defined as It is the set of commits that are reachable from either one of 'r1' or 'r2' but not from both. +In these two shorthands, you can omit one end and let it default to HEAD. +For example, 'origin..' is a shorthand for 'origin..HEAD' and asks "What +did I do since I forked from the origin branch?" Similarly, '..origin' +is a shorthand for 'HEAD..origin' and asks "What did the origin do since +I forked from them?" Note that you cannot omit both ends. '..' is not +an empty range that is both reachable and unreachable from HEAD. + Two other shorthands for naming a set that is formed by a commit and its parent commits exist. The 'r1{caret}@' notation means all parents of 'r1'. 'r1{caret}!' includes commit 'r1' but excludes diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index adb1cae..3c8f171 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -223,6 +223,7 @@ static int try_difference(const char *arg) const char *next; const char *this; int symmetric; + static const char head_by_default[] = "HEAD"; if (!(dotdot = strstr(arg, ".."))) return 0; @@ -234,9 +235,20 @@ static int try_difference(const char *arg) next += symmetric; if (!*next) - next = "HEAD"; + next = head_by_default; if (dotdot == arg) - this = "HEAD"; + this = head_by_default; + + if (this == head_by_default && next == head_by_default && + !symmetric) { + /* + * Just ".."? That is not a range but the + * pathspec for the parent directory. + */ + *dotdot = '.'; + return 0; + } + if (!get_sha1(this, sha1) && !get_sha1(next, end)) { show_rev(NORMAL, end, next); show_rev(symmetric ? NORMAL : REVERSED, sha1, this);