git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Add a new extended SHA1 syntax <name>:<num>
@ 2005-08-21  9:43 Junio C Hamano
  2005-08-21 18:26 ` Johannes Schindelin
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2005-08-21  9:43 UTC (permalink / raw
  To: git

The new notation is a short-hand for <name> followed by <num>
caret ('^') characters.  E.g. "master:4" is the fourth
generation ancestor of the current "master" branch head,
following the first parents; same as "master^^^^" but a bit more
readable.

This will be used in the updated "git show-branch" command.

Signed-off-by: Junio C Hamano <junkio@cox.net>

---

 sha1_name.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

3a371474bc20e192b0e9d3b48fb7c84ca107b818
diff --git a/sha1_name.c b/sha1_name.c
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -191,9 +191,29 @@ static int get_parent(const char *name, 
 	return -1;
 }
 
+static int get_nth_ancestor(const char *name, int len,
+			    unsigned char *result, int generation)
+{
+	unsigned char sha1[20];
+	int ret = get_sha1_1(name, len, sha1);
+	if (ret)
+		return ret;
+
+	while (generation--) {
+		struct commit *commit = lookup_commit_reference(sha1);
+
+		if (!commit || parse_commit(commit) || !commit->parents)
+			return -1;
+		memcpy(sha1, commit->parents->item->object.sha1, 20);
+	}
+	memcpy(result, sha1, 20);
+	return 0;
+}
+
 static int get_sha1_1(const char *name, int len, unsigned char *sha1)
 {
 	int parent, ret;
+	const char *cp;
 
 	/* foo^[0-9] or foo^ (== foo^1); we do not do more than 9 parents. */
 	if (len > 2 && name[len-2] == '^' &&
@@ -210,6 +230,27 @@ static int get_sha1_1(const char *name, 
 	if (parent >= 0)
 		return get_parent(name, len, sha1, parent);
 
+	/* name:3 is name^^^,
+	 * name:12 is name^^^^^^^^^^^^, and
+	 * name: is name
+	 */
+	parent = 0;
+	for (cp = name + len - 1; name <= cp; cp--) {
+		int ch = *cp;
+		if ('0' <= ch && ch <= '9')
+			continue;
+		if (ch != ':')
+			parent = -1;
+		break;
+	}
+	if (!parent && *cp == ':') {
+		int len1 = cp - name;
+		cp++;
+		while (cp < name + len)
+			parent = parent * 10 + *cp++ - '0';
+		return get_nth_ancestor(name, len1, sha1, parent);
+	}
+
 	ret = get_sha1_basic(name, len, sha1);
 	if (!ret)
 		return 0;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add a new extended SHA1 syntax <name>:<num>
  2005-08-21  9:43 [PATCH] Add a new extended SHA1 syntax <name>:<num> Junio C Hamano
@ 2005-08-21 18:26 ` Johannes Schindelin
  2005-08-21 18:37   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2005-08-21 18:26 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

Hi,

On Sun, 21 Aug 2005, Junio C Hamano wrote:

> The new notation is a short-hand for <name> followed by <num>
> caret ('^') characters.  E.g. "master:4" is the fourth
> generation ancestor of the current "master" branch head,
> following the first parents; same as "master^^^^" but a bit more
> readable.

This might confuse some people with the <src>:<dest> notation of the 
renaming fetch...

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add a new extended SHA1 syntax <name>:<num>
  2005-08-21 18:26 ` Johannes Schindelin
@ 2005-08-21 18:37   ` Junio C Hamano
  2005-08-21 18:41     ` Johannes Schindelin
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2005-08-21 18:37 UTC (permalink / raw
  To: Johannes Schindelin; +Cc: git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> This might confuse some people with the <src>:<dest> notation of the 
> renaming fetch...

True.  How about using a tilde '~'?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add a new extended SHA1 syntax <name>:<num>
  2005-08-21 18:37   ` Junio C Hamano
@ 2005-08-21 18:41     ` Johannes Schindelin
  0 siblings, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2005-08-21 18:41 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

Hi,

On Sun, 21 Aug 2005, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > This might confuse some people with the <src>:<dest> notation of the 
> > renaming fetch...
> 
> True.  How about using a tilde '~'?

I like it.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-08-21 21:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-21  9:43 [PATCH] Add a new extended SHA1 syntax <name>:<num> Junio C Hamano
2005-08-21 18:26 ` Johannes Schindelin
2005-08-21 18:37   ` Junio C Hamano
2005-08-21 18:41     ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).