git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] git-branch: improve abbreviation of sha1s in verbose mode

From
Julian Phillips <julian@quantumfyre.co.uk>
Date
Mar 3, 2007, 00:31 UTC
Message-ID
<11728818771064-git-send-email-julian@quantumfyre.co.uk>
In-Reply-To
<11728818772136-git-send-email-julian@quantumfyre.co.uk>

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(-)
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
Previous: Julian PhillipsNext: Julian Phillips
Message 2 of 3 in “git-branch: improve command line handling of --abbrev=”
  1. 0/2 git-branch: improve command line handling of --abbrev=Julian Phillips, Mar 3, 2007
  2. 1/2 git-branch: improve abbreviation of sha1s in verbose modeJulian Phillips, Mar 3, 2007
  3. 2/2 git-branch: document new --no-abbrev optionJulian Phillips, Mar 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.