From: Junio C Hamano Date: Mon, 17 Sep 2018 20:53:50 +0000 (-0700) Subject: Merge branch 'jk/branch-l-1-repurpose' X-Git-Tag: v2.20.0-rc0~250 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7dc341cedb66746710ce51ac5f8416089445c448?ds=inline;hp=-c Merge branch 'jk/branch-l-1-repurpose' Updated plan to repurpose the "-l" option to "git branch". * jk/branch-l-1-repurpose: doc/git-branch: remove obsolete "-l" references branch: make "-l" a synonym for "--list" --- 7dc341cedb66746710ce51ac5f8416089445c448 diff --combined Documentation/git-branch.txt index 9767b2b483,73ca0532ea..bf5316ffa9 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@@ -14,7 -14,7 +14,7 @@@ SYNOPSI [(--merged | --no-merged) []] [--contains []] [--points-at ] [--format=] [...] - 'git branch' [--track | --no-track] [-l] [-f] [] + 'git branch' [--track | --no-track] [-f] [] 'git branch' (--set-upstream-to= | -u ) [] 'git branch' --unset-upstream [] 'git branch' (-m | -M) [] @@@ -100,8 -100,6 +100,6 @@@ OPTION The negated form `--no-create-reflog` only overrides an earlier `--create-reflog`, but currently does not negate the setting of `core.logAllRefUpdates`. - + - The `-l` option is a deprecated synonym for `--create-reflog`. -f:: --force:: @@@ -156,14 -154,11 +154,11 @@@ This option is only applicable in non-v --all:: List both remote-tracking branches and local branches. + -l:: --list:: List branches. With optional `...`, e.g. `git branch --list 'maint-*'`, list only the branches that match the pattern(s). - + - This should not be confused with `git branch -l `, - which creates a branch named `` with a reflog. - See `--create-reflog` above for details. -v:: -vv:: @@@ -268,11 -263,10 +263,11 @@@ start-point is either a local or remote order of the value. You may use the --sort= option multiple times, in which case the last key becomes the primary key. The keys supported are the same as those in `git - for-each-ref`. Sort order defaults to sorting based on the + for-each-ref`. Sort order defaults to the value configured for the + `branch.sort` variable if exists, or to sorting based on the full refname (including `refs/...` prefix). This lists detached HEAD (if present) first, then local branches and - finally remote-tracking branches. + finally remote-tracking branches. See linkgit:git-config[1]. --points-at :: diff --combined builtin/branch.c index bbd006aab4,c1662e3db3..5b4d883e1f --- a/builtin/branch.c +++ b/builtin/branch.c @@@ -22,7 -22,6 +22,7 @@@ #include "wt-status.h" #include "ref-filter.h" #include "worktree.h" +#include "help.h" static const char * const builtin_branch_usage[] = { N_("git branch [] [-r | -a] [--merged | --no-merged]"), @@@ -37,7 -36,6 +37,6 @@@ static const char *head; static struct object_id head_oid; - static int used_deprecated_reflog_option; static int branch_use_color = -1; static char branch_colors[][COLOR_MAXLEN] = { @@@ -57,31 -55,29 +56,31 @@@ enum color_branch BRANCH_COLOR_UPSTREAM = 5 }; +static const char *color_branch_slots[] = { + [BRANCH_COLOR_RESET] = "reset", + [BRANCH_COLOR_PLAIN] = "plain", + [BRANCH_COLOR_REMOTE] = "remote", + [BRANCH_COLOR_LOCAL] = "local", + [BRANCH_COLOR_CURRENT] = "current", + [BRANCH_COLOR_UPSTREAM] = "upstream", +}; + static struct string_list output = STRING_LIST_INIT_DUP; static unsigned int colopts; -static int parse_branch_color_slot(const char *slot) -{ - if (!strcasecmp(slot, "plain")) - return BRANCH_COLOR_PLAIN; - if (!strcasecmp(slot, "reset")) - return BRANCH_COLOR_RESET; - if (!strcasecmp(slot, "remote")) - return BRANCH_COLOR_REMOTE; - if (!strcasecmp(slot, "local")) - return BRANCH_COLOR_LOCAL; - if (!strcasecmp(slot, "current")) - return BRANCH_COLOR_CURRENT; - if (!strcasecmp(slot, "upstream")) - return BRANCH_COLOR_UPSTREAM; - return -1; -} +define_list_config_array(color_branch_slots); static int git_branch_config(const char *var, const char *value, void *cb) { const char *slot_name; + struct ref_sorting **sorting_tail = (struct ref_sorting **)cb; + + if (!strcmp(var, "branch.sort")) { + if (!value) + return config_error_nonbool(var); + parse_ref_sorting(sorting_tail, value); + return 0; + } if (starts_with(var, "column.")) return git_column_config(var, value, "branch", &colopts); @@@ -90,7 -86,7 +89,7 @@@ return 0; } if (skip_prefix(var, "color.branch.", &slot_name)) { - int slot = parse_branch_color_slot(slot_name); + int slot = LOOKUP_CONFIG(color_branch_slots, slot_name); if (slot < 0) return 0; if (!value) @@@ -130,8 -126,7 +129,8 @@@ static int branch_merged(int kind, cons (reference_name = reference_name_to_free = resolve_refdup(upstream, RESOLVE_REF_READING, &oid, NULL)) != NULL) - reference_rev = lookup_commit_reference(&oid); + reference_rev = lookup_commit_reference(the_repository, + &oid); } if (!reference_rev) reference_rev = head_rev; @@@ -164,7 -159,7 +163,7 @@@ static int check_branch_commit(const ch const struct object_id *oid, struct commit *head_rev, int kinds, int force) { - struct commit *rev = lookup_commit_reference(oid); + struct commit *rev = lookup_commit_reference(the_repository, oid); if (!rev) { error(_("Couldn't look up commit object for '%s'"), refname); return -1; @@@ -218,7 -213,7 +217,7 @@@ static int delete_branches(int argc, co } if (!force) { - head_rev = lookup_commit_reference(&head_oid); + head_rev = lookup_commit_reference(the_repository, &head_oid); if (!head_rev) die(_("Couldn't look up commit object for HEAD")); } @@@ -578,14 -573,6 +577,6 @@@ static int edit_branch_description(cons return 0; } - static int deprecated_reflog_option_cb(const struct option *opt, - const char *arg, int unset) - { - used_deprecated_reflog_option = 1; - *(int *)opt->value = !unset; - return 0; - } - int cmd_branch(int argc, const char **argv, const char *prefix) { int delete = 0, rename = 0, copy = 0, force = 0, list = 0; @@@ -627,14 -614,8 +618,8 @@@ OPT_BIT('M', NULL, &rename, N_("move/rename a branch, even if target exists"), 2), OPT_BIT('c', "copy", ©, N_("copy a branch and its reflog"), 1), OPT_BIT('C', NULL, ©, N_("copy a branch, even if target exists"), 2), - OPT_BOOL(0, "list", &list, N_("list branch names")), + OPT_BOOL('l', "list", &list, N_("list branch names")), OPT_BOOL(0, "create-reflog", &reflog, N_("create the branch's reflog")), - { - OPTION_CALLBACK, 'l', NULL, &reflog, NULL, - N_("deprecated synonym for --create-reflog"), - PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, - deprecated_reflog_option_cb - }, OPT_BOOL(0, "edit-description", &edit_description, N_("edit the description for the branch")), OPT__FORCE(&force, N_("force creation, move/rename, deletion"), PARSE_OPT_NOCOMPLETE), @@@ -661,7 -642,7 +646,7 @@@ if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_branch_usage, options); - git_config(git_branch_config, NULL); + git_config(git_branch_config, sorting_tail); track = git_branch_track; @@@ -707,11 -688,6 +692,6 @@@ if (list) setup_auto_pager("branch", 1); - if (used_deprecated_reflog_option && !list) { - warning("the '-l' alias for '--create-reflog' is deprecated;"); - warning("it will be removed in a future version of Git"); - } - if (delete) { if (!argc) die(_("branch name required"));