@matheusbsbs / matheus-bagliano / commits / f127404c45
Fork 0

If abbrev is set to zero in git-describe, don't add the unique suffix

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: Junio C Hamano <junkio@cox.net>

Andy Parkins committed Jan 26, 2007 at 14:28 UTC f127404c45eff139037834a6464b68fbe1798e16
1 file changed +6 -3
builtin-describe.c
+6 -3
@@ -188,8 +188,11 @@ static void describe(const char *arg, int last_one)
188 sha1_to_hex(gave_up_on->object.sha1));
189 }
190 }
191 - printf("%s-g%s\n", all_matches[0].name->path,
192 - find_unique_abbrev(cmit->object.sha1, abbrev));
191 + if (abbrev == 0)
192 + printf("%s\n", all_matches[0].name->path );
193 + else
194 + printf("%s-g%s\n", all_matches[0].name->path,
195 + find_unique_abbrev(cmit->object.sha1, abbrev));
196
197 if (!last_one)
198 clear_commit_marks(cmit, -1);
@@ -212,7 +215,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
215 tags = 1;
216 else if (!strncmp(arg, "--abbrev=", 9)) {
217 abbrev = strtoul(arg + 9, NULL, 10);
215 - if (abbrev < MINIMUM_ABBREV || 40 < abbrev)
218 + if (abbrev != 0 && (abbrev < MINIMUM_ABBREV || 40 < abbrev))
219 abbrev = DEFAULT_ABBREV;
220 }
221 else if (!strncmp(arg, "--candidates=", 13)) {