Thread (5 messages) flat view 5 messages, 2 authors, 2016-06-15

Re: git describe fails without tags

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:17
Subsystem: the rest · Maintainer: Linus Torvalds

Uwe Zeisberger [off-list ref] writes:
I see two things to fix in that patch:

 1) define DEFAULT_ABBREV (e.g. by moving it to cache.h, where
    find_unique_abbrev is defined.)
Sorry, the patch alone was not compilable since cleaning up the
definition of symbolic constants *_ABBREV comes before the patch
you quoted in the "pu" branch.
 2) describe.c allows only abbrev >= 4.  (Allowing values less than 2
    failes, because find_short_object_filename (and maybe others) assume
    len to be at least 2.)  I think 4 is sensible.
Thanks.  "rev-parse --abbrev=2" would have segfaulted without
your fix.  I suspect substituting with MINIMUM instead of
DEFAULT in such a case would be more sensible, so...

-- >8 --
[PATCH] rev-parse --abbrev: do not try abbrev shorter than minimum.

We do not allow abbreviation shorter than 4 letters in other
parts of the system so do not attempt to generate such.

Noticed by Uwe Zeisberger.

Signed-off-by: Junio C Hamano <redacted>

---

 rev-parse.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

030d25d271adb2671f560b410d77585d8744acbf
diff --git a/rev-parse.c b/rev-parse.c
index 42969a6..8bf316e 100644
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -206,8 +206,10 @@ int main(int argc, char **argv)
 				abbrev = DEFAULT_ABBREV;
 				if (arg[8] == '=')
 					abbrev = strtoul(arg + 9, NULL, 10);
-				if (abbrev < 0 || 40 <= abbrev)
-					abbrev = DEFAULT_ABBREV;
+				if (abbrev < MINIMUM_ABBREV)
+					abbrev = MINIMUM_ABBREV;
+				else if (40 <= abbrev)
+					abbrev = 40;
 				continue;
 			}
 			if (!strcmp(arg, "--sq")) {
-- 
1.1.4.g00a4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help