{"thread":{"id":"8260","subject":"[PATCH] Make sure an autogenerated version has at least four parts","startedAt":"2007-05-21T02:52:21Z","lastAt":"2007-05-25T09:47:43Z","messageCount":7,"participants":["Sam Vilain","Martin Waitz","Jan Hudec"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"42833","messageId":"11797159411969-git-send-email-sam.vilain@catalyst.net.nz","threadId":"8260","inReplyTo":null,"subject":"[PATCH] Make sure an autogenerated version has at least four parts","fromName":"Sam Vilain","fromEmail":"sam.vilain@catalyst.net.nz","sentAt":"2007-05-21T02:52:21Z","receivedAt":"2007-05-21T02:52:21Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Otherwise, a custom \"v1.5.2.42.gd00b\" is considered newer than a\n\"v1.5.2.1.69.gcafe\".\n\nWarning: contains awk.\n\nSigned-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>\n---\n GIT-VERSION-GEN |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 06c360b..5eb58c3 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -18,7 +18,7 @@ elif test -d .git &&\n \tv[0-9]*) : happy ;;\n \tesac\n then\n-\tVN=$(echo \"$VN\" | sed -e 's/-/./g');\n+\tVN=$(echo \"$VN\" | awk -F- 'X=$1 { Y=$2; Z=$3; while (!(X ~ /\\..*\\..*\\./)) { X = X \".0\" } print X ( Y ? \".\" Y : \"\" ) ( Z ? \".\" Z : \"\" ) }');\n else\n \tVN=\"$DEF_VER\"\n fi\n-- \n1.5.1.1.175.g31e4\n"},{"id":"42858","messageId":"20070521073650.GV5412@admingilde.org","threadId":"8260","inReplyTo":"11797159411969-git-send-email-sam.vilain@catalyst.net.nz","subject":"Re: [PATCH] Make sure an autogenerated version has at least four parts","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2007-05-21T07:36:50Z","receivedAt":"2007-05-21T07:36:50Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Mon, May 21, 2007 at 02:52:21PM +1200, Sam Vilain wrote:\n> Otherwise, a custom \"v1.5.2.42.gd00b\" is considered newer than a\n> \"v1.5.2.1.69.gcafe\".\n\nor just use git describe output without replacing \"-\" with \".\"?\n\n-- \nMartin Waitz\n"},{"id":"42920","messageId":"20070521195745.GD5082@efreet.light.src","threadId":"8260","inReplyTo":"20070521073650.GV5412@admingilde.org","subject":"Re: [PATCH] Make sure an autogenerated version has at least four parts","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2007-05-21T19:57:45Z","receivedAt":"2007-05-21T19:57:45Z","isPatch":true,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Mon, May 21, 2007 at 09:36:50 +0200, Martin Waitz wrote:\n> hoi :)\n> \n> On Mon, May 21, 2007 at 02:52:21PM +1200, Sam Vilain wrote:\n> > Otherwise, a custom \"v1.5.2.42.gd00b\" is considered newer than a\n> > \"v1.5.2.1.69.gcafe\".\n> \n> or just use git describe output without replacing \"-\" with \".\"?\n\nThat depends on what rules you use to compare versions. Under dpkg ones it\nwould. I don't know what eg. rpm uses. (Note: - is BEFORE . in asciibet).\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"42922","messageId":"20070521200635.GB5412@admingilde.org","threadId":"8260","inReplyTo":"20070521195745.GD5082@efreet.light.src","subject":"Re: [PATCH] Make sure an autogenerated version has at least four parts","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2007-05-21T20:06:36Z","receivedAt":"2007-05-21T20:06:36Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Mon, May 21, 2007 at 09:57:45PM +0200, Jan Hudec wrote:\n> That depends on what rules you use to compare versions. Under dpkg ones it\n> would. I don't know what eg. rpm uses. (Note: - is BEFORE . in asciibet).\n\nif rpm does not grok that then perhaps the version transformation should\nbe moved to the git.spec Makefile target.\nThat way at least  the real git version is in line with git-describe.\n\n-- \nMartin Waitz\n"},{"id":"43202","messageId":"46563CE1.9020007@vilain.net","threadId":"8260","inReplyTo":"20070521073650.GV5412@admingilde.org","subject":"Re: [PATCH] Make sure an autogenerated version has at least four parts","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2007-05-25T01:33:21Z","receivedAt":"2007-05-25T01:33:21Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Martin Waitz wrote:\n> hoi :)\n> \n> On Mon, May 21, 2007 at 02:52:21PM +1200, Sam Vilain wrote:\n>> Otherwise, a custom \"v1.5.2.42.gd00b\" is considered newer than a\n>> \"v1.5.2.1.69.gcafe\".\n> \n> or just use git describe output without replacing \"-\" with \".\"?\n> \n\ndpkg uses \"-\" in version numbers for its own uses - to delimit the\npackager's packaging version from the software version.  The change I\nposted keeps original behaviour - just fills out the .0's.\n\nPerhaps the munging should go in git-describe instead?\n\nSubject: [PATCH] describe: add --levels option\n\nSome projects might want git describe to always give a result that\nhas a given number of version levels.  ie, if you say --levels=4\nand describe finds a name like 'v1.5.2', the result will be 'v1.5.2.0'.\n\nThis does mean that on exact tag matches, the returned version\nis not a resolvable ref - but that is probably caveat emptor.\n\nSigned-off-by: Sam Vilain <sam@vilain.net>\n---\n builtin-describe.c  |   50 ++++++++++++++++++++++++++++++++++++++++++++++----\n t/t6120-describe.sh |    8 ++++++++\n 2 files changed, 54 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex 165917e..05eabc5 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -15,6 +15,7 @@ static int all;\t/* Default to annotated tags only */\n static int tags;\t/* But allow any tags if --tags is specified */\n static int abbrev = DEFAULT_ABBREV;\n static int max_candidates = 10;\n+static int num_levels = 0;\n \n struct commit_name {\n \tint prio; /* annotated tag = 2, tag = 1, head = 0 */\n@@ -134,6 +135,7 @@ static void describe(const char *arg, int last_one)\n \tstruct possible_tag all_matches[MAX_TAGS];\n \tunsigned int match_cnt = 0, annotated_cnt = 0, cur_match;\n \tunsigned long seen_commits = 0;\n+\tchar* chosen;\n \n \tif (get_sha1(arg, sha1))\n \t\tdie(\"Not a valid object name %s\", arg);\n@@ -148,8 +150,9 @@ static void describe(const char *arg, int last_one)\n \n \tn = cmit->util;\n \tif (n) {\n-\t\tprintf(\"%s\\n\", n->path);\n-\t\treturn;\n+\t\tchosen = n->path;\n+\t\tabbrev = 0;\n+\t\tgoto show;\n \t}\n \n \tif (debug)\n@@ -228,10 +231,44 @@ static void describe(const char *arg, int last_one)\n \t\t\t\tsha1_to_hex(gave_up_on->object.sha1));\n \t\t}\n \t}\n+\n+\tchosen = all_matches[0].name->path;\n+\n+\t/* make the described version have the desired number of\n+\t * levels in it */\n+ show:\n+\tif (num_levels) {\n+\t\tint found = 1;\n+\t\tchar* idx = chosen;\n+\t\tint i;\n+\t\twhile ((idx = index(idx, '.'))) {\n+\t\t\tfound++;\n+\t\t\tidx++;\n+\t\t}\n+\t\tif (found > num_levels) {\n+\t\t\tidx = chosen;\n+\t\t\tfor (i = 0; i < num_levels; i++) {\n+\t\t\t\tif (i)\n+\t\t\t\t\tidx++;\n+\t\t\t\tidx = index(idx, '.');\n+\t\t\t}\n+\t\t\t*idx = '\\0';\n+\t\t}\n+\t\telse if (found < num_levels) {\n+\t\t\tint extra = 2 * (num_levels - found);\n+\t\t\tchar* new = xmalloc(strlen(chosen) + extra + 1);\n+\t\t\tchosen = strcpy(new, chosen);\n+\t\t\twhile (found < num_levels) {\n+\t\t\t\tstrcat(chosen, \".0\");\n+\t\t\t\tfound++;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n \tif (abbrev == 0)\n-\t\tprintf(\"%s\\n\", all_matches[0].name->path );\n+\t\tprintf(\"%s\\n\", chosen);\n \telse\n-\t\tprintf(\"%s-%d-g%s\\n\", all_matches[0].name->path,\n+\t\tprintf(\"%s-%d-g%s\\n\", chosen,\n \t\t       all_matches[0].depth,\n \t\t       find_unique_abbrev(cmit->object.sha1, abbrev));\n \n@@ -266,6 +303,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\telse if (max_candidates > MAX_TAGS)\n \t\t\t\tmax_candidates = MAX_TAGS;\n \t\t}\n+\t\telse if (!prefixcmp(arg, \"--levels=\")) {\n+\t\t\tnum_levels = strtoul(arg + 9, NULL, 10);\n+\t\t\tif (num_levels < 0) \n+\t\t\t\tnum_levels = 0;\n+\t\t}\n \t\telse\n \t\t\tusage(describe_usage);\n \t}\ndiff --git a/t/t6120-describe.sh b/t/t6120-describe.sh\nindex 3e9edda..0336ddd 100755\n--- a/t/t6120-describe.sh\n+++ b/t/t6120-describe.sh\n@@ -33,6 +33,7 @@ test_expect_success setup '\n \n \ttest_tick &&\n \techo two >file && git-add file && git-commit -m second &&\n+\tgit-tag -a -m v1.1 v1.1 &&\n \ttwo=$(git-rev-parse HEAD) &&\n \n \ttest_tick &&\n@@ -94,4 +95,11 @@ check_describe D-* --tags HEAD^^\n check_describe A-* --tags HEAD^^2\n check_describe B --tags HEAD^^2^\n \n+check_describe A.0-* --tags --levels=2 HEAD\n+check_describe A.0.0-* --tags --levels=3 HEAD\n+check_describe v1 --tags --levels=1 v1.1\n+check_describe v1.1 --tags --levels=2 v1.1\n+check_describe v1.1.0 --tags --levels=3 v1.1\n+check_describe v1-* --tags --levels=1 A^1\n+\n test_done\n-- \n1.5.2.0.45.gfea6d-dirty\n"},{"id":"43201","messageId":"46563F21.2060107@vilain.net","threadId":"8260","inReplyTo":"46563CE1.9020007@vilain.net","subject":"Re: [PATCH] Make sure an autogenerated version has at least four parts","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2007-05-25T01:42:57Z","receivedAt":"2007-05-25T01:42:57Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"I wrote:\n> dpkg uses \"-\" in version numbers for its own uses - to delimit the\n> packager's packaging version from the software version.  The change I\n> posted keeps original behaviour - just fills out the .0's.\n> \n> Perhaps the munging should go in git-describe instead?\n> \n> Subject: [PATCH] describe: add --levels option\n\n...and here's the corresponding GIT-VERSION-GEN patch:\n\nSubject: [PATCH] Make sure an autogenerated version has at least four parts\n\nOtherwise, a custom \"v1.5.2.42.gd00b\" is considered newer than a\n\"v1.5.2.1.69.gcafe\".\n\nContains a workaround for the chicken-and-egg problem it would\notherwise introduce.\n\nSigned-off-by: Sam Vilain <sam@vilain.net>\n---\n GIT-VERSION-GEN |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN\nindex 06c360b..91e8966 100755\n--- a/GIT-VERSION-GEN\n+++ b/GIT-VERSION-GEN\n@@ -12,7 +12,8 @@ if test -f version\n then\n \tVN=$(cat version) || VN=\"$DEF_VER\"\n elif test -d .git &&\n-\tVN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&\n+\tVN=$(git describe --abbrev=4 --levels=4 HEAD 2>/dev/null ||\n+\t\tgit describe --abbrev=4 HEAD 2>/dev/null) &&\n \tcase \"$VN\" in\n \t*$LF*) (exit 1) ;;\n \tv[0-9]*) : happy ;;\n-- \n1.5.2.0.45.gfea6d-dirty\n"},{"id":"43223","messageId":"20070525094743.GO5412@admingilde.org","threadId":"8260","inReplyTo":"46563CE1.9020007@vilain.net","subject":"Re: [PATCH] Make sure an autogenerated version has at least four parts","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2007-05-25T09:47:43Z","receivedAt":"2007-05-25T09:47:43Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Fri, May 25, 2007 at 01:33:21PM +1200, Sam Vilain wrote:\n> Martin Waitz wrote:\n> > On Mon, May 21, 2007 at 02:52:21PM +1200, Sam Vilain wrote:\n> >> Otherwise, a custom \"v1.5.2.42.gd00b\" is considered newer than a\n> >> \"v1.5.2.1.69.gcafe\".\n> > \n> > or just use git describe output without replacing \"-\" with \".\"?\n> \n> dpkg uses \"-\" in version numbers for its own uses - to delimit the\n> packager's packaging version from the software version.\n\nBut you can also have \"-\" in the upstream version without problems.\nOnly the last \"-\" is used as deliminator and therefore the Debian\nversion part must not contain a \"-\"; it's no problem for the upstream\npart.\n\n\n> The change I posted keeps original behaviour - just fills out the\n> .0's.\n> Perhaps the munging should go in git-describe instead?\n\nIf we want to be able to separate the software version as it is defined\nby the project maintainer from the additional Git information we should\ndo so with a clear separator, not by changing the software version.\n\nMaybe have some Makefile magic which creates a nice version,\nbut interpreting and changing the tagged version in git-describe sounds\nwrong to me.\n\n-- \nMartin Waitz\n"}]}