Skip to content

Commit

Permalink
git-branch: improve abbreviation of sha1s in verbose mode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Julian Phillips authored and Junio C Hamano committed Mar 3, 2007
1 parent 6227382 commit 43bc820
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "builtin.h"

static const char builtin_branch_usage[] =
"git-branch [-r] (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>] | (-m | -M) [<oldbranch>] <newbranch> | [--color | --no-color] [-r | -a] [-v [--abbrev=<length>]]";
"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]]";

#define REF_UNKNOWN_TYPE 0x00
#define REF_LOCAL_BRANCH 0x01
Expand Down Expand Up @@ -446,8 +446,16 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
reflog = 1;
continue;
}
if (!prefixcmp(arg, "--no-abbrev")) {
abbrev = 0;
continue;
}
if (!prefixcmp(arg, "--abbrev=")) {
abbrev = atoi(arg+9);
abbrev = strtoul(arg + 9, NULL, 10);
if (abbrev < MINIMUM_ABBREV)
abbrev = MINIMUM_ABBREV;
else if (abbrev > 40)
abbrev = 40;
continue;
}
if (!strcmp(arg, "-v")) {
Expand Down

0 comments on commit 43bc820

Please sign in to comment.