* [PATCH] Make sure an autogenerated version has at least four parts
@ 2007-05-21  2:52 Sam Vilain
  2007-05-21  7:36 ` Martin Waitz
  0 siblings, 1 reply; 7+ messages in thread
From: Sam Vilain @ 2007-05-21  2:52 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Sam Vilain
Otherwise, a custom "v1.5.2.42.gd00b" is considered newer than a
"v1.5.2.1.69.gcafe".
Warning: contains awk.
Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
---
 GIT-VERSION-GEN |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 06c360b..5eb58c3 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -18,7 +18,7 @@ elif test -d .git &&
 	v[0-9]*) : happy ;;
 	esac
 then
-	VN=$(echo "$VN" | sed -e 's/-/./g');
+	VN=$(echo "$VN" | awk -F- 'X=$1 { Y=$2; Z=$3; while (!(X ~ /\..*\..*\./)) { X = X ".0" } print X ( Y ? "." Y : "" ) ( Z ? "." Z : "" ) }');
 else
 	VN="$DEF_VER"
 fi
-- 
1.5.1.1.175.g31e4
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [PATCH] Make sure an autogenerated version has at least four parts
  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-25  1:33   ` Sam Vilain
  0 siblings, 2 replies; 7+ messages in thread
From: Martin Waitz @ 2007-05-21  7:36 UTC (permalink / raw)
  To: Sam Vilain; +Cc: Junio C Hamano, git
[-- Attachment #1: Type: text/plain, Size: 251 bytes --]
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 "."?
-- 
Martin Waitz
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH] Make sure an autogenerated version has at least four parts
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Jan Hudec @ 2007-05-21 19:57 UTC (permalink / raw)
  To: Martin Waitz; +Cc: Sam Vilain, Junio C Hamano, git
[-- Attachment #1: Type: text/plain, Size: 504 bytes --]
On Mon, May 21, 2007 at 09:36:50 +0200, 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 "."?
That depends on what rules you use to compare versions. Under dpkg ones it
would. I don't know what eg. rpm uses. (Note: - is BEFORE . in asciibet).
-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH] Make sure an autogenerated version has at least four parts
  2007-05-21 19:57   ` Jan Hudec
@ 2007-05-21 20:06     ` Martin Waitz
  0 siblings, 0 replies; 7+ messages in thread
From: Martin Waitz @ 2007-05-21 20:06 UTC (permalink / raw)
  To: Jan Hudec; +Cc: Sam Vilain, Junio C Hamano, git
[-- Attachment #1: Type: text/plain, Size: 436 bytes --]
hoi :)
On Mon, May 21, 2007 at 09:57:45PM +0200, Jan Hudec wrote:
> That depends on what rules you use to compare versions. Under dpkg ones it
> would. I don't know what eg. rpm uses. (Note: - is BEFORE . in asciibet).
if rpm does not grok that then perhaps the version transformation should
be moved to the git.spec Makefile target.
That way at least  the real git version is in line with git-describe.
-- 
Martin Waitz
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH] Make sure an autogenerated version has at least four parts
  2007-05-21  7:36 ` Martin Waitz
  2007-05-21 19:57   ` Jan Hudec
@ 2007-05-25  1:33   ` Sam Vilain
  2007-05-25  1:42     ` Sam Vilain
  2007-05-25  9:47     ` Martin Waitz
  1 sibling, 2 replies; 7+ messages in thread
From: Sam Vilain @ 2007-05-25  1:33 UTC (permalink / raw)
  To: Martin Waitz; +Cc: Sam Vilain, Junio C Hamano, git
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
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [PATCH] Make sure an autogenerated version has at least four parts
  2007-05-25  1:33   ` Sam Vilain
@ 2007-05-25  1:42     ` Sam Vilain
  2007-05-25  9:47     ` Martin Waitz
  1 sibling, 0 replies; 7+ messages in thread
From: Sam Vilain @ 2007-05-25  1:42 UTC (permalink / raw)
  To: Martin Waitz; +Cc: Junio C Hamano, git
I wrote:
> 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
...and here's the corresponding GIT-VERSION-GEN patch:
Subject: [PATCH] Make sure an autogenerated version has at least four parts
Otherwise, a custom "v1.5.2.42.gd00b" is considered newer than a
"v1.5.2.1.69.gcafe".
Contains a workaround for the chicken-and-egg problem it would
otherwise introduce.
Signed-off-by: Sam Vilain <sam@vilain.net>
---
 GIT-VERSION-GEN |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 06c360b..91e8966 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -12,7 +12,8 @@ if test -f version
 then
 	VN=$(cat version) || VN="$DEF_VER"
 elif test -d .git &&
-	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+	VN=$(git describe --abbrev=4 --levels=4 HEAD 2>/dev/null ||
+		git describe --abbrev=4 HEAD 2>/dev/null) &&
 	case "$VN" in
 	*$LF*) (exit 1) ;;
 	v[0-9]*) : happy ;;
-- 
1.5.2.0.45.gfea6d-dirty
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [PATCH] Make sure an autogenerated version has at least four parts
  2007-05-25  1:33   ` Sam Vilain
  2007-05-25  1:42     ` Sam Vilain
@ 2007-05-25  9:47     ` Martin Waitz
  1 sibling, 0 replies; 7+ messages in thread
From: Martin Waitz @ 2007-05-25  9:47 UTC (permalink / raw)
  To: Sam Vilain; +Cc: Sam Vilain, Junio C Hamano, git
[-- Attachment #1: Type: text/plain, Size: 1210 bytes --]
hoi :)
On Fri, May 25, 2007 at 01:33:21PM +1200, Sam Vilain wrote:
> Martin Waitz wrote:
> > 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.
But you can also have "-" in the upstream version without problems.
Only the last "-" is used as deliminator and therefore the Debian
version part must not contain a "-"; it's no problem for the upstream
part.
> The change I posted keeps original behaviour - just fills out the
> .0's.
> Perhaps the munging should go in git-describe instead?
If we want to be able to separate the software version as it is defined
by the project maintainer from the additional Git information we should
do so with a clear separator, not by changing the software version.
Maybe have some Makefile magic which creates a nice version,
but interpreting and changing the tagged version in git-describe sounds
wrong to me.
-- 
Martin Waitz
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply	[flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-05-25  9:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2007-05-25  1:42     ` Sam Vilain
2007-05-25  9:47     ` Martin Waitz
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).