@matheusbsbs / matheus-bagliano / commits / 43bc820db7
Fork 0

git-branch: improve abbreviation of sha1s in verbose mode

git-branch has an --abbrev= command line option, but it does no checking of the input. Take the argument parsing code from setup_revisions in revisions.c, and also the code for parsing the --no-abbrev option. Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk> Signed-off-by: Junio C Hamano <junkio@cox.net>

Julian Phillips committed Mar 3, 2007 at 00:31 UTC 43bc820db78be5e3230ae675018a7a7af50ccc88
1 file changed +10 -2
builtin-branch.c
+10 -2
@@ -12,7 +12,7 @@
12 #include "builtin.h"
13
14 static const char builtin_branch_usage[] =
15 - "git-branch [-r] (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>] | (-m | -M) [<oldbranch>] <newbranch> | [--color | --no-color] [-r | -a] [-v [--abbrev=<length>]]";
15 + "git-branch [-r] (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>] | (-m | -M) [<oldbranch>] <newbranch> | [--color | --no-color] [-r | -a] [-v [--abbrev=<length> | --no-abbrev]]";
16
17 #define REF_UNKNOWN_TYPE 0x00
18 #define REF_LOCAL_BRANCH 0x01
@@ -446,8 +446,16 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
446 reflog = 1;
447 continue;
448 }
449 + if (!prefixcmp(arg, "--no-abbrev")) {
450 + abbrev = 0;
451 + continue;
452 + }
453 if (!prefixcmp(arg, "--abbrev=")) {
450 - abbrev = atoi(arg+9);
454 + abbrev = strtoul(arg + 9, NULL, 10);
455 + if (abbrev < MINIMUM_ABBREV)
456 + abbrev = MINIMUM_ABBREV;
457 + else if (abbrev > 40)
458 + abbrev = 40;
459 continue;
460 }
461 if (!strcmp(arg, "-v")) {