Merge branch 'jk/ref-filter-colors' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 21:33:42 +0000 (14:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Aug 2017 21:33:42 +0000 (14:33 -0700)
"%C(color name)" in the pretty print format always produced ANSI
color escape codes, which was an early design mistake. They now
honor the configuration (e.g. "color.ui = never") and also tty-ness
of the output medium.

* jk/ref-filter-colors:
ref-filter: consult want_color() before emitting colors
pretty: respect color settings for %C placeholders
rev-list: pass diffopt->use_colors through to pretty-print
for-each-ref: load config earlier
color: check color.ui in git_default_config()
ref-filter: pass ref_format struct to atom parsers
ref-filter: factor out the parsing of sorting atoms
ref-filter: make parse_ref_filter_atom a private function
ref-filter: provide a function for parsing sort options
ref-filter: move need_color_reset_at_eol into ref_format
ref-filter: abstract ref format into its own struct
ref-filter: simplify automatic color reset
t: use test_decode_color rather than literal ANSI codes
docs/for-each-ref: update pointer to color syntax
check return value of verify_ref_format()

1  2 
builtin/grep.c
config.c
t/test-lib-functions.sh
diff --combined builtin/grep.c
index 7e79eb1a754a5f604829e3e9e6d98d83712be9b6,a7157f56327c0a9b2d4cccbdb2ee47666902392d..42ff87065a0e72c999488d2844463f901fd73a5c
@@@ -284,7 -284,7 +284,7 @@@ static int wait_all(void
  static int grep_cmd_config(const char *var, const char *value, void *cb)
  {
        int st = grep_config(var, value, cb);
-       if (git_color_default_config(var, value, cb) < 0)
+       if (git_default_config(var, value, cb) < 0)
                st = -1;
  
        if (!strcmp(var, "grep.threads")) {
@@@ -1170,6 -1170,8 +1170,6 @@@ int cmd_grep(int argc, const char **arg
  
        if (!opt.pattern_list)
                die(_("no pattern given."));
 -      if (!opt.fixed && opt.ignore_case)
 -              opt.regflags |= REG_ICASE;
  
        /*
         * We have to find "--" in a separate pass, because its presence
diff --combined config.c
index 231f9a750b96deda8d62f5a5debb384f40481566,bc290e7563dc5be4c70a5660358e03da180351e9..acebc85d81372f15d3d490d84dc751f59bde26c4
+++ b/config.c
@@@ -16,6 -16,7 +16,7 @@@
  #include "string-list.h"
  #include "utf8.h"
  #include "dir.h"
+ #include "color.h"
  
  struct config_source {
        struct config_source *prev;
@@@ -1350,6 -1351,9 +1351,9 @@@ 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;
@@@ -1714,18 -1718,15 +1718,18 @@@ static int configset_add_value(struct c
        return 0;
  }
  
 -static int config_set_element_cmp(const struct config_set_element *e1,
 -                               const struct config_set_element *e2, const void *unused)
 +static int config_set_element_cmp(const void *unused_cmp_data,
 +                                const struct config_set_element *e1,
 +                                const struct config_set_element *e2,
 +                                const void *unused_keydata)
  {
        return strcmp(e1->key, e2->key);
  }
  
  void git_configset_init(struct config_set *cs)
  {
 -      hashmap_init(&cs->config_hash, (hashmap_cmp_fn)config_set_element_cmp, 0);
 +      hashmap_init(&cs->config_hash, (hashmap_cmp_fn)config_set_element_cmp,
 +                   NULL, 0);
        cs->hash_initialized = 1;
        cs->list.nr = 0;
        cs->list.alloc = 0;
diff --combined t/test-lib-functions.sh
index 50a9a1d1c49e719d0ee65435b05171747e065259,e09e93b38f869b1d2238b927966125b8c2daab6d..1701fe2a06057530d845b91b4fd4cce99b4521a2
@@@ -42,6 -42,7 +42,7 @@@ test_decode_color () 
                function name(n) {
                        if (n == 0) return "RESET";
                        if (n == 1) return "BOLD";
+                       if (n == 7) return "REVERSE";
                        if (n == 30) return "BLACK";
                        if (n == 31) return "RED";
                        if (n == 32) return "GREEN";
@@@ -999,7 -1000,6 +1000,7 @@@ test_copy_bytes () 
                        my $s;
                        my $nread = sysread(STDIN, $s, $len);
                        die "cannot read: $!" unless defined($nread);
 +                      last unless $nread;
                        print $s;
                        $len -= $nread;
                }