From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org, Andy Parkins <andyparkins@gmail.com>
Subject: [PATCH 2/4] If abbrev is set to zero in git-describe, don't add the unique suffix
Date: Sat, 27 Jan 2007 01:53:51 -0500 [thread overview]
Message-ID: <20070127065351.GB10380@spearce.org> (raw)
In-Reply-To: <a23c4e55ca5c09f742fa2a047e45613e7797e720.1169880681.git.spearce@spearce.org>
From: Andy Parkins <andyparkins@gmail.com>
When on a non-tag commit, git-describe normally outputs descriptions of
the form
v1.0.0-g1234567890
Some scripts (for example the update hook script) might just want to
know the name of the nearest tag, so they then have to do
x=$(git-describe HEAD | sed 's/-g*//')
This is costly, but more importantly is fragile as it is relying on the
output format of git-describe, which we would then have to maintain
forever.
This patch adds support for setting the --abbrev option to zero. In
that case git-describe does as it always has, but outputs only the
nearest found tag instead of a completely unique name. This means that
scripts would not have to parse the output format and won't need
changing if the git-describe suffix is ever changed.
Signed-off-by: Andy Parkins <andyparkins@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
This is a resend of Andy's original patch. I added documentation
updates and slighlty modified the code so it conformed to our
conventions. Reason is, my next patch alters the same lines...
Documentation/git-describe.txt | 7 ++++++-
builtin-describe.c | 9 ++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index b87783c..a615996 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -33,7 +33,9 @@ OPTIONS
--abbrev=<n>::
Instead of using the default 8 hexadecimal digits as the
- abbreviated object name, use <n> digits.
+ abbreviated object name, use <n> digits. If set to 0
+ then abbreviated object name will not be displayed on
+ a non-exact match.
--candidates=<n>::
Instead of considering only the 10 most recent tags as
@@ -70,6 +72,9 @@ the output shows the reference path as well:
[torvalds@g5 git]$ git describe --all --abbrev=4 v1.0.5^2
tags/v1.0.0-g975b
+ [torvalds@g5 git]$ git describe --all --abbrev=0 v1.0.5^2
+ tags/v1.0.0
+
[torvalds@g5 git]$ git describe --all HEAD^
heads/lt/describe-g975b
diff --git a/builtin-describe.c b/builtin-describe.c
index f8afb9c..70578dc 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -188,8 +188,11 @@ static void describe(const char *arg, int last_one)
sha1_to_hex(gave_up_on->object.sha1));
}
}
- printf("%s-g%s\n", all_matches[0].name->path,
- find_unique_abbrev(cmit->object.sha1, abbrev));
+ if (!abbrev)
+ printf("%s\n", all_matches[0].name->path);
+ else
+ printf("%s-g%s\n", all_matches[0].name->path,
+ find_unique_abbrev(cmit->object.sha1, abbrev));
if (!last_one)
clear_commit_marks(cmit, -1);
@@ -212,7 +215,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
tags = 1;
else if (!strncmp(arg, "--abbrev=", 9)) {
abbrev = strtoul(arg + 9, NULL, 10);
- if (abbrev < MINIMUM_ABBREV || 40 < abbrev)
+ if (abbrev && (abbrev < MINIMUM_ABBREV || 40 < abbrev))
abbrev = DEFAULT_ABBREV;
}
else if (!strncmp(arg, "--candidates=", 13)) {
--
1.5.0.rc2.g8a816
next parent reply other threads:[~2007-01-27 6:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <a23c4e55ca5c09f742fa2a047e45613e7797e720.1169880681.git.spearce@spearce.org>
2007-01-27 6:53 ` Shawn O. Pearce [this message]
2007-01-27 6:54 ` [PATCH 3/4] Teach git-describe to display distances from tags Shawn O. Pearce
2007-01-27 8:47 ` Junio C Hamano
2007-01-27 12:50 ` Johannes Schindelin
2007-01-28 7:24 ` Shawn O. Pearce
2007-01-27 6:54 ` [PATCH 4/4] Compute accurate distances in git-describe before output Shawn O. Pearce
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=20070127065351.GB10380@spearce.org \
--to=spearce@spearce.org \
--cc=andyparkins@gmail.com \
--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.
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.