git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: git describe fails without tags
Date: Thu, 26 Jan 2006 09:41:52 +0100	[thread overview]
Message-ID: <20060126084151.GB2941@informatik.uni-freiburg.de> (raw)
In-Reply-To: <7vek2wws61.fsf@assigned-by-dhcp.cox.net>

Hello Junio,

Junio C Hamano wrote:
> 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;
I see two things to fix in that patch:

 1) define DEFAULT_ABBREV (e.g. by moving it to cache.h, where
    find_unique_abbrev is defined.)

 2) describe.c allows only abbrev >= 4.  (Allowing values less than 2
    failes, because find_short_object_filename (and maybe others) assume
    len to be at least 2.)  I think 4 is sensible.

This results in the following patch:

--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.

This patch is a modification of a suggestion by Junio C Hamano.

Signed-off-by: Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de>

---

 cache.h     |    2 ++
 describe.c  |    1 -
 rev-parse.c |   14 ++++++++++++++
 3 files changed, 16 insertions(+), 1 deletions(-)

0d43ec7461b38d6a1d1563fd7dc2ebf399eabe9e
diff --git a/cache.h b/cache.h
index b493b65..139c670 100644
--- a/cache.h
+++ b/cache.h
@@ -177,6 +177,8 @@ extern int check_repository_format(void)
 #define DATA_CHANGED    0x0020
 #define TYPE_CHANGED    0x0040
 
+#define DEFAULT_ABBREV 8 /* maybe too many */
+
 /* Return a statically allocated filename matching the sha1 signature */
 extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
 extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
diff --git a/describe.c b/describe.c
index 4866510..6518f06 100644
--- a/describe.c
+++ b/describe.c
@@ -11,7 +11,6 @@ static const char describe_usage[] =
 static int all = 0;	/* Default to annotated tags only */
 static int tags = 0;	/* But allow any tags if --tags is specified */
 
-#define DEFAULT_ABBREV 8 /* maybe too many */
 static int abbrev = DEFAULT_ABBREV;
 
 static int names = 0, allocs = 0;
diff --git a/rev-parse.c b/rev-parse.c
index 0c951af..58cff6f 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 < 4 || 40 <= abbrev)
+					abbrev = DEFAULT_ABBREV;
+				continue;
+			}
 			if (!strcmp(arg, "--sq")) {
 				output_sq = 1;
 				continue;
-- 
1.1.4.g3e6c

Best regards
Uwe

-- 
Uwe Zeisberger

http://www.google.com/search?q=72+PS+point+in+inch

  parent reply	other threads:[~2006-01-26  8:42 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
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 [this message]
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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060126084151.GB2941@informatik.uni-freiburg.de \
    --to=zeisberg@informatik.uni-freiburg.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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.
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).