From: Junio C Hamano Date: Sun, 4 Oct 2009 21:48:44 +0000 (-0700) Subject: Merge branch 'jc/maint-1.6.4-show-branch-default' into maint X-Git-Tag: v1.6.5-rc3~6^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/04ce83e2b9a1f1512d3d0c873e8f13d06761620c?hp=-c 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 --- 04ce83e2b9a1f1512d3d0c873e8f13d06761620c diff --combined builtin-show-branch.c index 01bea3b583,5d85ab0cae..baec9ed56f --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@@ -565,7 -565,15 +565,15 @@@ static int git_show_branch_config(cons 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); } @@@ -657,7 -665,8 +665,7 @@@ int cmd_show_branch(int ac, const char "color '*!+-' corresponding to the branch"), { OPTION_INTEGER, 0, "more", &extra, "n", "show more commits after the common ancestor", - PARSE_OPT_OPTARG | PARSE_OPT_LASTARG_DEFAULT, - NULL, (intptr_t)1 }, + PARSE_OPT_OPTARG, NULL, (intptr_t)1 }, OPT_SET_INT(0, "list", &extra, "synonym to more=-1", -1), OPT_BOOLEAN(0, "no-name", &no_name, "suppress naming strings"), OPT_BOOLEAN(0, "current", &with_current_branch, @@@ -692,11 -701,11 +700,11 @@@ /* 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, builtin_show_branch_options, + ac = parse_options(ac, av, prefix, builtin_show_branch_options, show_branch_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (all_heads) all_remotes = 1;