From: Sam Vilain <sam@vilain.net>
To: Martin Waitz <tali@admingilde.org>
Cc: Sam Vilain <sam.vilain@catalyst.net.nz>,
Junio C Hamano <junkio@cox.net>,
git@vger.kernel.org
Subject: Re: [PATCH] Make sure an autogenerated version has at least four parts
Date: Fri, 25 May 2007 13:33:21 +1200 [thread overview]
Message-ID: <46563CE1.9020007@vilain.net> (raw)
In-Reply-To: <20070521073650.GV5412@admingilde.org>
Martin Waitz wrote:
> hoi :)
>
> On Mon, May 21, 2007 at 02:52:21PM +1200, Sam Vilain wrote:
>> Otherwise, a custom "v1.5.2.42.gd00b" is considered newer than a
>> "v1.5.2.1.69.gcafe".
>
> or just use git describe output without replacing "-" with "."?
>
dpkg uses "-" in version numbers for its own uses - to delimit the
packager's packaging version from the software version. The change I
posted keeps original behaviour - just fills out the .0's.
Perhaps the munging should go in git-describe instead?
Subject: [PATCH] describe: add --levels option
Some projects might want git describe to always give a result that
has a given number of version levels. ie, if you say --levels=4
and describe finds a name like 'v1.5.2', the result will be 'v1.5.2.0'.
This does mean that on exact tag matches, the returned version
is not a resolvable ref - but that is probably caveat emptor.
Signed-off-by: Sam Vilain <sam@vilain.net>
---
builtin-describe.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
t/t6120-describe.sh | 8 ++++++++
2 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/builtin-describe.c b/builtin-describe.c
index 165917e..05eabc5 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -15,6 +15,7 @@ static int all; /* Default to annotated tags only */
static int tags; /* But allow any tags if --tags is specified */
static int abbrev = DEFAULT_ABBREV;
static int max_candidates = 10;
+static int num_levels = 0;
struct commit_name {
int prio; /* annotated tag = 2, tag = 1, head = 0 */
@@ -134,6 +135,7 @@ static void describe(const char *arg, int last_one)
struct possible_tag all_matches[MAX_TAGS];
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
unsigned long seen_commits = 0;
+ char* chosen;
if (get_sha1(arg, sha1))
die("Not a valid object name %s", arg);
@@ -148,8 +150,9 @@ static void describe(const char *arg, int last_one)
n = cmit->util;
if (n) {
- printf("%s\n", n->path);
- return;
+ chosen = n->path;
+ abbrev = 0;
+ goto show;
}
if (debug)
@@ -228,10 +231,44 @@ static void describe(const char *arg, int last_one)
sha1_to_hex(gave_up_on->object.sha1));
}
}
+
+ chosen = all_matches[0].name->path;
+
+ /* make the described version have the desired number of
+ * levels in it */
+ show:
+ if (num_levels) {
+ int found = 1;
+ char* idx = chosen;
+ int i;
+ while ((idx = index(idx, '.'))) {
+ found++;
+ idx++;
+ }
+ if (found > num_levels) {
+ idx = chosen;
+ for (i = 0; i < num_levels; i++) {
+ if (i)
+ idx++;
+ idx = index(idx, '.');
+ }
+ *idx = '\0';
+ }
+ else if (found < num_levels) {
+ int extra = 2 * (num_levels - found);
+ char* new = xmalloc(strlen(chosen) + extra + 1);
+ chosen = strcpy(new, chosen);
+ while (found < num_levels) {
+ strcat(chosen, ".0");
+ found++;
+ }
+ }
+ }
+
if (abbrev == 0)
- printf("%s\n", all_matches[0].name->path );
+ printf("%s\n", chosen);
else
- printf("%s-%d-g%s\n", all_matches[0].name->path,
+ printf("%s-%d-g%s\n", chosen,
all_matches[0].depth,
find_unique_abbrev(cmit->object.sha1, abbrev));
@@ -266,6 +303,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
else if (max_candidates > MAX_TAGS)
max_candidates = MAX_TAGS;
}
+ else if (!prefixcmp(arg, "--levels=")) {
+ num_levels = strtoul(arg + 9, NULL, 10);
+ if (num_levels < 0)
+ num_levels = 0;
+ }
else
usage(describe_usage);
}
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index 3e9edda..0336ddd 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -33,6 +33,7 @@ test_expect_success setup '
test_tick &&
echo two >file && git-add file && git-commit -m second &&
+ git-tag -a -m v1.1 v1.1 &&
two=$(git-rev-parse HEAD) &&
test_tick &&
@@ -94,4 +95,11 @@ check_describe D-* --tags HEAD^^
check_describe A-* --tags HEAD^^2
check_describe B --tags HEAD^^2^
+check_describe A.0-* --tags --levels=2 HEAD
+check_describe A.0.0-* --tags --levels=3 HEAD
+check_describe v1 --tags --levels=1 v1.1
+check_describe v1.1 --tags --levels=2 v1.1
+check_describe v1.1.0 --tags --levels=3 v1.1
+check_describe v1-* --tags --levels=1 A^1
+
test_done
--
1.5.2.0.45.gfea6d-dirty
next prev parent reply other threads:[~2007-05-25 1:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-21 2:52 [PATCH] Make sure an autogenerated version has at least four parts Sam Vilain
2007-05-21 7:36 ` Martin Waitz
2007-05-21 19:57 ` Jan Hudec
2007-05-21 20:06 ` Martin Waitz
2007-05-25 1:33 ` Sam Vilain [this message]
2007-05-25 1:42 ` Sam Vilain
2007-05-25 9:47 ` Martin Waitz
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=46563CE1.9020007@vilain.net \
--to=sam@vilain.net \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
--cc=sam.vilain@catalyst.net.nz \
--cc=tali@admingilde.org \
/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;
as well as URLs for NNTP newsgroup(s).