Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de>
Cc: git@vger.kernel.org
Subject: Re: git describe fails without tags
Date: Wed, 25 Jan 2006 01:52:38 -0800	[thread overview]
Message-ID: <7vek2wws61.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: 20060125074725.GA2768@informatik.uni-freiburg.de

Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:

> I wonder if it would be sane to assume an implicit tag for the empty
> repository, s.t. git describe results in 
>
> 	<empty>-62ac6c16
>
> (whatever name is choosen for <empty>).
>
> Any opinions?

The value of 'describe' is not in the 62ac6c part, but in the
tag part, which lets us find out that the rev in question is at
least newer than that tag.  If the reason you are doing
"describe" is to find out an usable abbreviated name, you could
feed the first few hexdigits to "git rev-parse --verify",
lengthening the prefix longer by one until it says you have a
unique prefix [*1*].

In other words, not particularly interested, although it is
trivial to implement, like this:

diff --git a/describe.c b/describe.c
index 4866510..aeaf0fb 100644
--- a/describe.c
+++ b/describe.c
@@ -137,7 +137,7 @@ static void describe(char *arg, int last
 			return;
 		}
 	}
-	die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
+	printf("%s\n", find_unique_abbrev(cmit->object.sha1, abbrev));
 }
 
 int main(int argc, char **argv)


[Footnote]

*1* If you do this often, we could introduce

	$ git rev-parse --abbrev=<n> HEAD

    that quacks like --verify (i.e. makes sure there is a single
    "extended SHA1 expression" that evaluates to a valid object
    name) but outputs the result abbreviated to at least <n>
    hexdigits.
    
    This has an added advantage that it would work on a
    non-commit object name.


-- >8 --
[PATCH] rev-parse: --abbrev option.

The new option behaves just like --verify, but outputs an
abbreviated object name that is unique within the repository.

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

---

 rev-parse.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

3c7c31a913c3c4060e85f2919e2136412928dcec
diff --git a/rev-parse.c b/rev-parse.c
index 0c951af..c1646e4 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -20,6 +20,7 @@ static char *def = NULL;
 #define REVERSED 1
 static int show_type = NORMAL;
 static int symbolic = 0;
+static int abbrev = 0;
 static int output_sq = 0;
 
 static int revs_count = 0;
@@ -95,6 +96,8 @@ static void show_rev(int type, const uns
 		putchar('^');
 	if (symbolic && name)
 		show(name);
+	else if (abbrev)
+		show(find_unique_abbrev(sha1, abbrev));
 	else
 		show(sha1_to_hex(sha1));
 }
@@ -195,6 +198,17 @@ int main(int argc, char **argv)
 				verify = 1;
 				continue;
 			}
+			if (!strcmp(arg, "--abbrev") ||
+			    !strncmp(arg, "--abbrev=", 9)) {
+				filter &= ~(DO_FLAGS|DO_NOREV);
+				verify = 1;
+				abbrev = DEFAULT_ABBREV;
+				if (arg[8] == '=')
+					abbrev = strtoul(arg + 9, NULL, 10);
+				if (abbrev < 0 || 40 <= abbrev)
+					abbrev = DEFAULT_ABBREV;
+				continue;
+			}
 			if (!strcmp(arg, "--sq")) {
 				output_sq = 1;
 				continue;
-- 
1.1.4.g869a

  reply	other threads:[~2006-01-25  9:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-25  7:47 git describe fails without tags Uwe Zeisberger
2006-01-25  9:52 ` Junio C Hamano [this message]
2006-01-26  7:44   ` Uwe Zeisberger
2006-01-26  8:07     ` Junio C Hamano
2006-01-26  8:45       ` Uwe Zeisberger
2006-01-26  8:41   ` Uwe Zeisberger
2006-01-26  9:02     ` Junio C Hamano

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=7vek2wws61.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --cc=zeisberg@informatik.uni-freiburg.de \
    /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