From: Junio C Hamano Date: Wed, 18 Oct 2017 05:20:43 +0000 (+0900) Subject: Merge branch 'jk/ref-filter-colors-fix' into maint X-Git-Tag: v2.15.0-rc2~5^2~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e3e3c6a43e7f36d507129909e49d54f1e8ad65e2?ds=inline;hp=-c Merge branch 'jk/ref-filter-colors-fix' into maint This is the "theoretically more correct" approach of simply stepping back to the state before plumbing commands started paying attention to "color.ui" configuration variable. * jk/ref-filter-colors-fix: tag: respect color.ui config Revert "color: check color.ui in git_default_config()" Revert "t6006: drop "always" color config tests" Revert "color: make "always" the same as "auto" in config" color: make "always" the same as "auto" in config provide --color option for all ref-filter users t3205: use --color instead of color.branch=always t3203: drop "always" color test t6006: drop "always" color config tests t7502: use diff.noprefix for --verbose test t7508: use test_terminal for color output t3701: use test-terminal to collect color output t4015: prefer --color to -c color.diff=always test-terminal: set TERM=vt100 --- e3e3c6a43e7f36d507129909e49d54f1e8ad65e2 diff --combined Documentation/git-for-each-ref.txt index 66b4e0a405,8bbeeba291..cbd0a6212a --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@@ -10,9 -10,8 +10,9 @@@ SYNOPSI [verse] 'git for-each-ref' [--count=] [--shell|--perl|--python|--tcl] [(--sort=)...] [--format=] [...] - [--points-at ] [(--merged | --no-merged) []] - [--contains []] [--no-contains []] + [--points-at=] + (--merged[=] | --no-merged[=]) + [--contains[=]] [--no-contains[=]] DESCRIPTION ----------- @@@ -26,25 -25,19 +26,25 @@@ host language allowing their direct eva OPTIONS ------- -:: +...:: + If one or more patterns are given, only refs are shown that + match against at least one pattern, either using fnmatch(3) or + literally, in the latter case matching completely or from the + beginning up to a slash. + +--count=:: By default the command shows all refs that match ``. This option makes it stop after showing that many refs. -:: +--sort=:: A field name to sort on. Prefix `-` to sort in descending order of the value. When unspecified, `refname` is used. You may use the --sort= option multiple times, in which case the last key becomes the primary key. -:: +--format=:: A string that interpolates `%(fieldname)` from a ref being shown and the object it points at. If `fieldname` is prefixed with an asterisk (`*`) and the ref points @@@ -57,6 -50,17 +57,11 @@@ `xx`; for example `%00` interpolates to `\0` (NUL), `%09` to `\t` (TAB) and `%0a` to `\n` (LF). -...:: - If one or more patterns are given, only refs are shown that - match against at least one pattern, either using fnmatch(3) or - literally, in the latter case matching completely or from the - beginning up to a slash. - + --color[=]: + Respect any colors specified in the `--format` option. The + `` field must be one of `always`, `never`, or `auto` (if + `` is absent, behave as if `always` was given). + --shell:: --perl:: --python:: @@@ -66,24 -70,24 +71,24 @@@ the specified host language. This is meant to produce a scriptlet that can directly be `eval`ed. ---points-at :: +--points-at=:: Only list refs which points at the given object. ---merged []:: +--merged[=]:: Only list refs whose tips are reachable from the specified commit (HEAD if not specified), incompatible with `--no-merged`. ---no-merged []:: +--no-merged[=]:: Only list refs whose tips are not reachable from the specified commit (HEAD if not specified), incompatible with `--merged`. ---contains []:: +--contains[=]:: Only list refs which contain the specified commit (HEAD if not specified). ---no-contains []:: +--no-contains[=]:: Only list refs which don't contain the specified commit (HEAD if not specified). diff --combined Documentation/git-tag.txt index 95e9f391d8,e130fa0f47..956fc019f9 --- a/Documentation/git-tag.txt +++ b/Documentation/git-tag.txt @@@ -115,6 -115,11 +115,11 @@@ options for details variable if it exists, or lexicographic order otherwise. See linkgit:git-config[1]. + --color[=]: + Respect any colors specified in the `--format` option. The + `` field must be one of `always`, `never`, or `auto` (if + `` is absent, behave as if `always` was given). + -i:: --ignore-case:: Sorting and filtering tags are case insensitive. @@@ -174,7 -179,7 +179,7 @@@ This option is only applicable when lis `core.logAllRefUpdates` in linkgit:git-config[1]. The negated form `--no-create-reflog` only overrides an earlier `--create-reflog`, but currently does not negate the setting of - `core.logallrefupdates`. + `core.logAllRefUpdates`. :: The name of the tag to create, delete, or describe. diff --combined builtin/branch.c index 2ea92a70b7,1969c7116c..8f779b02b5 --- a/builtin/branch.c +++ b/builtin/branch.c @@@ -92,7 -92,7 +92,7 @@@ static int git_branch_config(const cha return config_error_nonbool(var); return color_parse(value, branch_colors[slot]); } - return git_default_config(var, value, cb); + return git_color_default_config(var, value, cb); } static const char *branch_get_color(enum color_branch ix) @@@ -216,7 -216,7 +216,7 @@@ static int delete_branches(int argc, co if (!head_rev) die(_("Couldn't look up commit object for HEAD")); } - for (i = 0; i < argc; i++, strbuf_release(&bname)) { + for (i = 0; i < argc; i++, strbuf_reset(&bname)) { char *target = NULL; int flags = 0; @@@ -281,9 -281,8 +281,9 @@@ } free(name); + strbuf_release(&bname); - return(ret); + return ret; } static int calc_maxwidth(struct ref_array *refs, int remote_bonus) diff --combined config.c index c138c0ba05,231f9a750b..c6bc2ff715 --- a/config.c +++ b/config.c @@@ -16,7 -16,6 +16,6 @@@ #include "string-list.h" #include "utf8.h" #include "dir.h" - #include "color.h" struct config_source { struct config_source *prev; @@@ -1351,9 -1350,6 +1350,6 @@@ int git_default_config(const char *var if (starts_with(var, "advice.")) return git_default_advice_config(var, value); - if (git_color_config(var, value, dummy) < 0) - return -1; - if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { pager_use_color = git_config_bool(var,value); return 0; @@@ -2404,7 -2400,7 +2400,7 @@@ int git_config_set_multivar_in_file_gen { int fd = -1, in_fd = -1; int ret; - struct lock_file *lock = NULL; + static struct lock_file lock; char *filename_buf = NULL; char *contents = NULL; size_t contents_sz; @@@ -2423,7 -2419,8 +2419,7 @@@ * The lock serves a purpose in addition to locking: the new * contents of .git/config will be written into it. */ - lock = xcalloc(1, sizeof(struct lock_file)); - fd = hold_lock_file_for_update(lock, config_filename, 0); + fd = hold_lock_file_for_update(&lock, config_filename, 0); if (fd < 0) { error_errno("could not lock config file %s", config_filename); free(store.key); @@@ -2536,8 -2533,8 +2532,8 @@@ close(in_fd); in_fd = -1; - if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) { - error_errno("chmod on %s failed", get_lock_file_path(lock)); + if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) { + error_errno("chmod on %s failed", get_lock_file_path(&lock)); ret = CONFIG_NO_WRITE; goto out_free; } @@@ -2592,19 -2589,28 +2588,19 @@@ contents = NULL; } - if (commit_lock_file(lock) < 0) { + if (commit_lock_file(&lock) < 0) { error_errno("could not write config file %s", config_filename); ret = CONFIG_NO_WRITE; - lock = NULL; goto out_free; } - /* - * lock is committed, so don't try to roll it back below. - * NOTE: Since lockfile.c keeps a linked list of all created - * lock_file structures, it isn't safe to free(lock). It's - * better to just leave it hanging around. - */ - lock = NULL; ret = 0; /* Invalidate the config cache */ git_config_clear(); out_free: - if (lock) - rollback_lock_file(lock); + rollback_lock_file(&lock); free(filename_buf); if (contents) munmap(contents, contents_sz); @@@ -2613,7 -2619,7 +2609,7 @@@ return ret; write_err_out: - ret = write_error(get_lock_file_path(lock)); + ret = write_error(get_lock_file_path(&lock)); goto out_free; } diff --combined t/t6300-for-each-ref.sh index edc1bd8eab,09f2b7799d..d0ad902911 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@@ -51,7 -51,6 +51,7 @@@ test_atom() } test_atom head refname refs/heads/master +test_atom head refname: refs/heads/master test_atom head refname:short master test_atom head refname:lstrip=1 heads/master test_atom head refname:lstrip=2 master @@@ -426,8 -425,7 +426,7 @@@ test_expect_success 'set up color tests ' test_expect_success TTY '%(color) shows color with a tty' ' - test_terminal env TERM=vt100 \ - git for-each-ref --format="$color_format" >actual.raw && + test_terminal git for-each-ref --format="$color_format" >actual.raw && test_decode_color actual && test_cmp expected.color actual ' @@@ -437,12 -435,17 +436,17 @@@ test_expect_success '%(color) does not test_cmp expected.bare actual ' - test_expect_success 'color.ui=always can override tty check' ' - git -c color.ui=always for-each-ref --format="$color_format" >actual.raw && + test_expect_success '--color can override tty check' ' + git for-each-ref --color --format="$color_format" >actual.raw && test_decode_color actual && test_cmp expected.color actual ' + test_expect_success 'color.ui=always does not override tty check' ' + git -c color.ui=always for-each-ref --format="$color_format" >actual && + test_cmp expected.bare actual + ' + cat >expected <<\EOF heads/master tags/master