git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
	git@vger.kernel.org,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH 3/3] reject @{-1} not at beginning of object name
Date: Thu, 28 Jan 2010 04:56:43 -0500	[thread overview]
Message-ID: <20100128095643.GC14253@coredump.intra.peff.net> (raw)
In-Reply-To: <20100128094446.GA14244@coredump.intra.peff.net>

Something like foo@{-1} is nonsensical, as the @{-N} syntax
is reserved for "the Nth last branch", and is not an actual
reflog selector. We should not feed such nonsense to
approxidate at all.

Signed-off-by: Jeff King <peff@peff.net>
---
We didn't discuss this one, but I came across it while trying to be
complete in testing the combinations. Right now "foo@{-1}" is
interpreted as a reflog entry at approxidate "-1". Approxidate doesn't
signal an error because it thinks it has found something useful. But
AFAIK we have declared all @{-...} to be Nth last branch, so it is
simply a semantic error.

Let me know if that is not the case (that is, if it was intentional to
leave foo@{-1} as the reflog at date "-1" because it has some meaning
that I am missing) and we can drop this patch.

 sha1_name.c                |    4 ++++
 t/t1508-at-combinations.sh |    2 +-
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 00fc415..7729925 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -399,6 +399,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 		unsigned long co_time;
 		int co_tz, co_cnt;
 
+		/* a @{-N} placed anywhere except the start is an error */
+		if (str[at+2] == '-')
+			return -1;
+
 		/* Is it asking for N-th entry, or approxidate? */
 		for (i = nth = 0; 0 <= nth && i < reflog_len; i++) {
 			char ch = str[at+2+i];
diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
index 2a46af2..d5d6244 100755
--- a/t/t1508-at-combinations.sh
+++ b/t/t1508-at-combinations.sh
@@ -45,7 +45,7 @@ check "@{u}" upstream-two
 check "@{u}@{1}" upstream-one
 check "@{-1}@{u}" master-two
 check "@{-1}@{u}@{1}" master-one
-fail nonsense "@{u}@{-1}"
+nonsense "@{u}@{-1}"
 nonsense "@{1}@{u}"
 
 test_done
-- 
1.7.0.rc0.41.g538720

  parent reply	other threads:[~2010-01-28  9:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-11 18:49 default behaviour for `gitmerge` (no arguments) Gareth Adams
2010-01-11 19:43 ` Junio C Hamano
2010-01-12 16:23   ` Jeff King
2010-01-12 18:11     ` Junio C Hamano
2010-01-12 18:25       ` Jeff King
2010-01-13  6:57         ` Junio C Hamano
2010-01-13  9:26           ` Johannes Schindelin
2010-01-13  9:47             ` Junio C Hamano
2010-01-13 11:04               ` Johannes Schindelin
2010-01-13 19:48                 ` Junio C Hamano
2010-01-13 22:49                   ` Johannes Schindelin
2010-01-13 23:13                     ` Junio C Hamano
2010-01-20  9:38           ` [PATCH 0/2] @{u} updates Junio C Hamano
2010-01-20  9:38             ` [PATCH 1/2] t1506: more test for @{upstream} syntax Junio C Hamano
2010-01-26 13:07               ` Jeff King
2010-01-26 19:58                 ` Junio C Hamano
2010-01-27 10:24                   ` Jeff King
2010-01-27 18:50                     ` Junio C Hamano
2010-01-28  8:52                       ` Jeff King
2010-01-26 21:32                 ` Junio C Hamano
2010-01-27 11:40                   ` Jeff King
2010-01-27 19:10                     ` Junio C Hamano
2010-01-28  9:44                       ` Jeff King
2010-01-28  9:50                         ` [PATCH 1/3] test combinations of @{} syntax Jeff King
2010-01-28  9:52                         ` [PATCH 2/3] fix parsing of @{-1}@{u} combination Jeff King
2010-01-28  9:56                         ` Jeff King [this message]
2010-01-28 20:02                           ` [PATCH 3/3] reject @{-1} not at beginning of object name Junio C Hamano
2010-01-29 11:22                             ` Jeff King
2010-01-20  9:38             ` [PATCH 2/2] Teach @{upstream} syntax to strbuf_branchanme() Junio C Hamano
2010-01-20 13:08             ` [PATCH 0/2] @{u} updates Johannes Schindelin

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=20100128095643.GC14253@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=spearce@spearce.org \
    /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).