diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-10-05 01:48:44 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-10-05 01:48:44 +0400 |
commit | 04ce83e2b9a1f1512d3d0c873e8f13d06761620c (patch) | |
tree | 2ac6b140088072d7b01f44b86a36490f2dc318e0 | |
parent | bb8cccd01762d26c832b85d3b09798650e294c5f (diff) | |
parent | 3af1cae469555485cd3ef003aa2a55bd2a4f544f (diff) |
Merge branch 'jc/maint-1.6.4-show-branch-default' into maint
* jc/maint-1.6.4-show-branch-default:
show-branch: fix segfault when showbranch.default exists
-rw-r--r-- | builtin-show-branch.c | 14 | ||||
-rwxr-xr-x | t/t3202-show-branch-octopus.sh | 8 |
2 files changed, 19 insertions, 3 deletions
diff --git a/builtin-show-branch.c b/builtin-show-branch.c index 01bea3b583..baec9ed56f 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -565,7 +565,15 @@ static int git_show_branch_config(const char *var, const char *value, void *cb) if (!strcmp(var, "showbranch.default")) { if (!value) return config_error_nonbool(var); - if (default_alloc <= default_num + 1) { + /* + * default_arg is now passed to parse_options(), so we need to + * mimick the real argv a bit better. + */ + if (!default_num) { + default_alloc = 20; + default_arg = xcalloc(default_alloc, sizeof(*default_arg)); + default_arg[default_num++] = "show-branch"; + } else if (default_alloc <= default_num + 1) { default_alloc = default_alloc * 3 / 2 + 20; default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc); } @@ -692,8 +700,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) /* If nothing is specified, try the default first */ if (ac == 1 && default_num) { - ac = default_num + 1; - av = default_arg - 1; /* ick; we would not address av[0] */ + ac = default_num; + av = default_arg; } ac = parse_options(ac, av, prefix, builtin_show_branch_options, diff --git a/t/t3202-show-branch-octopus.sh b/t/t3202-show-branch-octopus.sh index 7fe4a6ecb0..0a5d5e669f 100755 --- a/t/t3202-show-branch-octopus.sh +++ b/t/t3202-show-branch-octopus.sh @@ -56,4 +56,12 @@ test_expect_success 'show-branch with more than 8 branches' ' ' +test_expect_success 'show-branch with showbranch.default' ' + for i in $numbers; do + git config --add showbranch.default branch$i + done && + git show-branch >out && + test_cmp expect out +' + test_done |