Merge branch 'jk/ref-filter-colors-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2017 05:20:43 +0000 (14:20 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2017 05:20:43 +0000 (14:20 +0900)
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

1  2 
Documentation/git-for-each-ref.txt
Documentation/git-tag.txt
builtin/branch.c
config.c
t/t6300-for-each-ref.sh
index 66b4e0a4050655e7fab27a6fe72af03d6c99f3b2,8bbeeba2913d6ae79b9b5a88cd7e619baf7b9653..cbd0a6212a62a618252e7b56397239d4066dcbd7
@@@ -10,9 -10,8 +10,9 @@@ SYNOPSI
  [verse]
  'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
                   [(--sort=<key>)...] [--format=<format>] [<pattern>...]
 -                 [--points-at <object>] [(--merged | --no-merged) [<object>]]
 -                 [--contains [<object>]] [--no-contains [<object>]]
 +                 [--points-at=<object>]
 +                 (--merged[=<object>] | --no-merged[=<object>])
 +                 [--contains[=<object>]] [--no-contains[=<object>]]
  
  DESCRIPTION
  -----------
@@@ -26,25 -25,19 +26,25 @@@ host language allowing their direct eva
  
  OPTIONS
  -------
 -<count>::
 +<pattern>...::
 +      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=<count>::
        By default the command shows all refs that match
        `<pattern>`.  This option makes it stop after showing
        that many refs.
  
 -<key>::
 +--sort=<key>::
        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=<key> option
        multiple times, in which case the last key becomes the primary
        key.
  
 -<format>::
 +--format=<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
        `xx`; for example `%00` interpolates to `\0` (NUL),
        `%09` to `\t` (TAB) and `%0a` to `\n` (LF).
  
 -<pattern>...::
 -      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[=<when>]:
+       Respect any colors specified in the `--format` option. The
+       `<when>` field must be one of `always`, `never`, or `auto` (if
+       `<when>` is absent, behave as if `always` was given).
  --shell::
  --perl::
  --python::
        the specified host language.  This is meant to produce
        a scriptlet that can directly be `eval`ed.
  
 ---points-at <object>::
 +--points-at=<object>::
        Only list refs which points at the given object.
  
 ---merged [<object>]::
 +--merged[=<object>]::
        Only list refs whose tips are reachable from the
        specified commit (HEAD if not specified),
        incompatible with `--no-merged`.
  
 ---no-merged [<object>]::
 +--no-merged[=<object>]::
        Only list refs whose tips are not reachable from the
        specified commit (HEAD if not specified),
        incompatible with `--merged`.
  
 ---contains [<object>]::
 +--contains[=<object>]::
        Only list refs which contain the specified commit (HEAD if not
        specified).
  
 ---no-contains [<object>]::
 +--no-contains[=<object>]::
        Only list refs which don't contain the specified commit (HEAD
        if not specified).
  
index 95e9f391d88fc434df6bc3f0483c9b3c80983021,e130fa0f47eee38ca9e75d09782812663439464e..956fc019f984bca1754a72dc0d7308b39a28445d
@@@ -115,6 -115,11 +115,11 @@@ options for details
        variable if it exists, or lexicographic order otherwise. See
        linkgit:git-config[1].
  
+ --color[=<when>]:
+       Respect any colors specified in the `--format` option. The
+       `<when>` field must be one of `always`, `never`, or `auto` (if
+       `<when>` 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`.
  
  <tagname>::
        The name of the tag to create, delete, or describe.
diff --combined builtin/branch.c
index 2ea92a70b7b6e7589df92a42c2c3ea46a9dab709,1969c7116cd1ae7cf3cf0f84eaf6ed333170113b..8f779b02b5f09907e0984dfb27024778026f0b4f
@@@ -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;
  
        }
  
        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 c138c0ba055bcec33f3a78a5a2227d2ce6cfa4e3,231f9a750b96deda8d62f5a5debb384f40481566..c6bc2ff715147d16734e3b997c18fdd49642fd00
+++ 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;
         * 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);
                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;
                }
                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);
        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 edc1bd8eabd6df02e49646930ee5eb56bf1b77f9,09f2b7799d5f6126d3b52cee17e52f9cf5a0b1e3..d0ad90291131a3a714a58f6a867fe4322a08e1c5
@@@ -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.raw >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.raw >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