threads / patch / 7052

patch, 2 partsgit-branch: improve command line handling of --abbrev=

Subject: [PATCH 0/2] git-branch: improve command line handling of --abbrev=

## tl;dr

3 messages between Mar 3, 2007 and Mar 3, 2007. Diffs are folded; open one to read it.

replies: 2people: 1as markdown or json

Julian Phillips· Mar 3, 2007, 00:31 UTC · lore

When playing with git-branch I discovered that it handled the --abbrev= option differently to other commands, which surprised me.

This update the parsing code in builtin_branch.c to be the same as setup_revisions in revision.c, and documents the new --no-abbrev option.

-- 
Julian
Julian Phillips· Mar 3, 2007, 00:31 UTC · re: Julian Phillips · lore

[PATCH 1/2] 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>
---
 builtin-branch.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
Show changes to builtin-branch.c +10 −2
diff --git a/builtin-branch.c b/builtin-branch.c
index d0179b0..d371849 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -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
@@ -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")) {
-- 
1.5.0.2
Julian Phillips· Mar 3, 2007, 00:31 UTC · re: Julian Phillips · lore

[PATCH 2/2] git-branch: document new --no-abbrev option

Add the new --no-abbrev option to the man page for the git-branch command.
Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk>
---
 Documentation/git-branch.txt |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
Show changes to Documentation/git-branch.txt +5 −1
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index aa1fdd4..3ea3b80 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -8,7 +8,8 @@ git-branch - List, create, or delete branches
 SYNOPSIS
 --------
 [verse]
-'git-branch' [--color | --no-color] [-r | -a] [-v [--abbrev=<length>]]
+'git-branch' [--color | --no-color] [-r | -a]
+	   [-v [--abbrev=<length> | --no-abbrev]]
 'git-branch' [-l] [-f] <branchname> [<start-point>]
 'git-branch' (-m | -M) [<oldbranch>] <newbranch>
 'git-branch' (-d | -D) [-r] <branchname>...
@@ -80,6 +81,9 @@ OPTIONS
 	Alter minimum display length for sha1 in output listing,
 	default value is 7.
 
+--no-abbrev::
+	Display the full sha1s in output listing rather than abbreviating them.
+
 <branchname>::
 	The name of the branch to create or delete.
 	The new branch name must pass all checks defined by
-- 
1.5.0.2

← back to recent threads