All of lore.kernel.org
 help / color / mirror / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Thomas Rast <trast@inf.ethz.ch>
Cc: Ramkumar Ramachandra <artagnon@gmail.com>,
	Git List <git@vger.kernel.org>,
	Felipe Contreras <felipe.contreras@gmail.com>,
	Michael Haggerty <mhagger@alum.mit.edu>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] refs.c: interpret @ as HEAD
Date: Tue, 30 Apr 2013 22:04:31 +0700	[thread overview]
Message-ID: <20130430150430.GA13398@lanh> (raw)
In-Reply-To: <87zjwguq8t.fsf@linux-k42r.v.cablecom.net>

On Tue, Apr 30, 2013 at 03:01:22PM +0200, Thomas Rast wrote:
> > This patch has the exact same effect as:
> >
> >     $ git symbolic-ref @ HEAD
> 
> But then why don't you just 'git symbolic-ref H HEAD' for a sort of
> "local alias"?

For me, it's because I don't want to do that on every repo. One day if
I change my mind and make P the new alias, i'll need to update every
repo again.

> 
> What annoys me more is that there's no way to say
> 
>   git symbolic-ref U @{u}
> 
> so that I can avoid that -- it's really clumsy to type on a Swiss German
> keyboard.  We'd need some sort of ref-alias feature for that to work.

It's not hard to do. The below patch makes "." equivalent to HEAD and
".U" -> "@{u}". Refs are not supposed to have '.' at the beginning, so
it's easy to figure somebody is using alias from what they send
you. Supporting refalias.* config should be easy.

-- 8< --
diff --git a/sha1_name.c b/sha1_name.c
index 3820f28..7842147 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1239,6 +1239,27 @@ static char *resolve_relative_path(const char *rel)
 			   rel);
 }
 
+static int get_sha1_with_alias(const char *name, int namelen,
+			       unsigned char *sha1, int flags)
+{
+	int ret;
+	struct strbuf sb = STRBUF_INIT;
+	int alias_len = strcspn(name, "@^~:");
+	if (alias_len > namelen)
+		alias_len = namelen;
+
+	if (alias_len == 0)	/* '.' is equal to HEAD */
+		strbuf_addstr(&sb, "HEAD");
+	else if (alias_len == 1 && !strncmp(name, "U", 1))
+		strbuf_addstr(&sb, "@{u}");
+	else
+		return error("unknown alias %.*s", alias_len, name);
+	strbuf_addstr(&sb, name + alias_len);
+	ret = get_sha1_1(sb.buf, sb.len, sha1, flags);
+	strbuf_release(&sb);
+	return ret;
+}
+
 static int get_sha1_with_context_1(const char *name,
 				   unsigned flags,
 				   const char *prefix,
@@ -1252,6 +1273,8 @@ static int get_sha1_with_context_1(const char *name,
 
 	memset(oc, 0, sizeof(*oc));
 	oc->mode = S_IFINVALID;
+	if (name[0] == '.')
+		return get_sha1_with_alias(name + 1, namelen - 1, sha1, flags);
 	ret = get_sha1_1(name, namelen, sha1, flags);
 	if (!ret)
 		return ret;
-- 8< --

  parent reply	other threads:[~2013-04-30 15:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-30 12:24 [PATCH] refs.c: interpret @ as HEAD Ramkumar Ramachandra
2013-04-30 12:31 ` Duy Nguyen
2013-04-30 13:01 ` Thomas Rast
2013-04-30 13:32   ` Ramkumar Ramachandra
2013-04-30 15:04   ` Duy Nguyen [this message]
2013-04-30 16:08     ` Michael Haggerty
2013-04-30 16:09     ` Junio C Hamano
2013-04-30 16:26       ` Duy Nguyen
2013-04-30 17:15         ` Ramkumar Ramachandra
2013-05-01  2:18           ` Duy Nguyen
2013-05-01  8:35             ` Thomas Rast
2013-04-30 17:07       ` Ramkumar Ramachandra
2013-04-30 17:23       ` Ramkumar Ramachandra
2013-04-30 17:28         ` Felipe Contreras
2013-04-30 17:32           ` Ramkumar Ramachandra
2013-04-30 18:08             ` Junio C Hamano
2013-04-30 18:22               ` Ramkumar Ramachandra
2013-04-30 18:24                 ` Ramkumar Ramachandra
2013-04-30 18:40                 ` Ramkumar Ramachandra
2013-04-30 18:50                   ` Ramkumar Ramachandra
2013-04-30 22:00                 ` Felipe Contreras

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=20130430150430.GA13398@lanh \
    --to=pclouds@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mhagger@alum.mit.edu \
    --cc=trast@inf.ethz.ch \
    /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.