All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Petr Baudis <pasky@suse.cz>, Andreas Gruenbacher <agruen@suse.de>,
	git@vger.kernel.org
Subject: Re: ref name troubles, was Re: [PATCH v2] Introduce %<branch> as shortcut to the tracked branch
Date: Sat, 21 Mar 2009 14:00:31 -0700	[thread overview]
Message-ID: <7vab7eegls.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 20090320004029.GX23521@spearce.org

"Shawn O. Pearce" <spearce@spearce.org> writes:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>> On Fri, 20 Mar 2009, Johannes Schindelin wrote:
>> 
>> > Just try this:
>> > 
>> > 	$ git checkout -b %helloworld
>> 
>> It gets worse.  Much worse.
>> 
>> Try this (triggered by a comment by Ilari on IRC):
>> 
>> 	$ git checkout -b '@{1}'
>> 
>> That _works_! WTH?
>
> '@' is not reserved.  Neither is '{' or '}'.  Neither is
> the combination.
>
> Waaaaaay back when I added reflog query syntax I tried to use only
> '@', people with branch names like 'foo@bar' made a point that they
> didn't want to reserve it.  We stuck the {} in as a "highly unlikely
> to conflict with a branch name" and others pointed out most shells
> will do fun things with those, but we kept it to avoid ambiguous
> meanings of "foo@noon" when foo@noon is already a branch.

Let's do something along this line.

-- >8 --
Subject: [PATCH] check_ref_format(): tighten refname rules

Yes, I know that tightening rules retroactively is bad, but this changes
the rules for refnames to forbid:

 (1) a refname that ends with a dot.

     We already reject a path component that begins with a dot, primarily
     to avoid ambiguous range interpretation.  If we allowed ".B" as a
     valid ref, it is unclear if "A...B" means "in dot-B but not in A" or
     "either in A or B but not in both".

     But for this to be complete, we need also to forbid "A." to avoid "in
     B but not in A-dot".  This was not a problem in the original range
     notation, but we should have added this restriction when three-dot
     notation was introduced.

     Unlike "no dot at the beginning of any path component" rule, this
     rule does not have to be "no dot at the end of any path component",
     because you cannot abbreviate the tail end away, similar to you can
     say "dot-B" to mean "refs/heads/dot-B".

 (2) a refname that contains "@{" in it.

     Some people and foreign SCM converter may have named their branches
     as frotz@243 and we still want to keep supporting it, but "git branch
     @{1}" is a disaster.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 refs.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/refs.c b/refs.c
index 8d3c502..abd5623 100644
--- a/refs.c
+++ b/refs.c
@@ -693,7 +693,7 @@ static inline int bad_ref_char(int ch)
 
 int check_ref_format(const char *ref)
 {
-	int ch, level, bad_type;
+	int ch, level, bad_type, last;
 	int ret = CHECK_REF_FORMAT_OK;
 	const char *cp = ref;
 
@@ -717,19 +717,23 @@ int check_ref_format(const char *ref)
 				return CHECK_REF_FORMAT_ERROR;
 		}
 
+		last = ch;
 		/* scan the rest of the path component */
 		while ((ch = *cp++) != 0) {
 			bad_type = bad_ref_char(ch);
-			if (bad_type) {
+			if (bad_type)
 				return CHECK_REF_FORMAT_ERROR;
-			}
 			if (ch == '/')
 				break;
-			if (ch == '.' && *cp == '.')
+			if (last == '.' && ch == '.')
+				return CHECK_REF_FORMAT_ERROR;
+			if (last == '@' && ch == '{')
 				return CHECK_REF_FORMAT_ERROR;
 		}
 		level++;
 		if (!ch) {
+			if (ref <= cp - 2 && cp[-2] == '.')
+				return CHECK_REF_FORMAT_ERROR;
 			if (level < 2)
 				return CHECK_REF_FORMAT_ONELEVEL;
 			return ret;
-- 
1.6.2.1.299.gda643a

      parent reply	other threads:[~2009-03-21 21:02 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200903181448.50706.agruen@suse.de>
2009-03-18 18:26 ` Git {log,diff} against tracked branch? Petr Baudis
2009-03-18 21:12   ` [PATCH] Introduce %<branch> as shortcut to the tracked branch Johannes Schindelin
2009-03-18 21:41     ` Andreas Gruenbacher
2009-03-18 21:46     ` [PATCH v2] " Johannes Schindelin
2009-03-18 21:58       ` Andreas Gruenbacher
2009-03-18 22:43         ` Johannes Schindelin
2009-03-18 22:34       ` Junio C Hamano
2009-03-18 22:46         ` Johannes Schindelin
2009-03-19 14:52           ` Michael J Gruber
2009-03-19 15:17             ` Michael J Gruber
2009-03-20  0:23           ` Johannes Schindelin
2009-03-20  0:38             ` ref name troubles, was " Johannes Schindelin
2009-03-20  0:40               ` Shawn O. Pearce
2009-03-20  0:44                 ` Shawn O. Pearce
2009-03-20  5:59                   ` Sverre Rabbelier
2009-03-20  9:29                   ` [PATCH v3] Introduce BEL<branch> " Johannes Schindelin
2009-03-20  9:42                     ` Wincent Colaiuta
2009-03-20  9:54                       ` Johannes Schindelin
2009-03-20 12:33                         ` Santi Béjar
2009-03-20 12:45                           ` Andreas Gruenbacher
2009-03-20 13:05                             ` Matthieu Moy
2009-03-20 12:46                           ` Johannes Schindelin
2009-03-20 12:53                             ` Mikael Magnusson
2009-03-20 14:00                               ` Johannes Schindelin
2009-03-20 10:04                     ` [PATCH] Document and test the new % shotcut for " Michael J Gruber
2009-03-20 10:31                       ` Johannes Schindelin
2009-03-20 10:38                         ` Michael J Gruber
2009-03-20 11:16                         ` Petr Baudis
2009-03-20 11:48                           ` Johannes Schindelin
2009-03-22 17:40                             ` Petr Baudis
2009-03-20 14:15                         ` Michael J Gruber
2009-03-20 16:17                     ` [PATCH v4] Introduce %<branch> as shortcut to " Johannes Schindelin
2009-03-20 17:03                       ` Junio C Hamano
2009-03-20 17:32                         ` Johannes Schindelin
2009-03-20 18:02                         ` Junio C Hamano
2009-03-20 19:36                           ` Jeff King
2009-03-20 20:28                             ` Julian Phillips
2009-03-20 20:50                               ` Jeff King
2009-03-20 23:08                         ` Julian Phillips
2009-03-20 23:20                           ` Sverre Rabbelier
2009-03-20 23:41                             ` Julian Phillips
2009-03-20 23:45                               ` Sverre Rabbelier
2009-03-21  0:35                           ` Andreas Gruenbacher
2009-03-21  1:10                             ` Miles Bader
2009-03-21 13:24                             ` Julian Phillips
2009-03-21 13:28                               ` Julian Phillips
2009-03-20 17:08                       ` Björn Steinbrink
2009-03-20  6:05                 ` ref name troubles, was Re: [PATCH v2] " Jeff King
2009-03-20  6:57                   ` Junio C Hamano
2009-03-20  9:30                     ` Johannes Schindelin
2009-03-20 11:12                       ` Petr Baudis
2009-03-20 11:46                         ` Johannes Schindelin
2009-03-20 11:50                           ` Petr Baudis
2009-03-20 11:57                             ` Johannes Schindelin
2009-03-20 14:31                               ` Michael J Gruber
2009-03-20 15:01                                 ` Johannes Schindelin
2009-03-20 15:12                                   ` Michael J Gruber
2009-03-20 16:47                         ` Junio C Hamano
2009-03-20 19:34                           ` Daniel Barkalow
2009-03-20 21:48                             ` Johannes Schindelin
2009-03-21 21:00                 ` Junio C Hamano [this message]

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=7vab7eegls.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=agruen@suse.de \
    --cc=git@vger.kernel.org \
    --cc=pasky@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.