Code

Documentation: add git-mergetool to the command list.
[git.git] / builtin-branch.c
index d0179b00a2f78ddf875cf7ea98e712b152664e94..06d8a8ce0432134f994aa30ac4133baf4ba7fef5 100644 (file)
@@ -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
@@ -289,12 +289,13 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev)
        detached = (detached && (kinds & REF_LOCAL_BRANCH));
        if (detached) {
                struct ref_item item;
-               item.name = "(no branch)";
+               item.name = xstrdup("(no branch)");
                item.kind = REF_LOCAL_BRANCH;
                hashcpy(item.sha1, head_sha1);
                if (strlen(item.name) > ref_list.maxwidth)
                              ref_list.maxwidth = strlen(item.name);
                print_ref_item(&item, ref_list.maxwidth, verbose, abbrev, 1);
+               free(item.name);
        }
 
        for (i = 0; i < ref_list.index; i++) {
@@ -446,8 +447,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")) {