Merge branch 'nd/icase'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Jul 2016 20:22:17 +0000 (13:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Jul 2016 20:22:17 +0000 (13:22 -0700)
"git grep -i" has been taught to fold case in non-ascii locales
correctly.

* nd/icase:
grep.c: reuse "icase" variable
diffcore-pickaxe: support case insensitive match on non-ascii
diffcore-pickaxe: Add regcomp_or_die()
grep/pcre: support utf-8
gettext: add is_utf8_locale()
grep/pcre: prepare locale-dependent tables for icase matching
grep: rewrite an if/else condition to avoid duplicate expression
grep/icase: avoid kwsset when -F is specified
grep/icase: avoid kwsset on literal non-ascii strings
test-regex: expose full regcomp() to the command line
test-regex: isolate the bug test code
grep: break down an "if" stmt in preparation for next changes

1  2 
grep.c
quote.c
quote.h
t/helper/test-regex.c
diff --cc grep.c
Simple merge
diff --cc quote.c
Simple merge
diff --cc quote.h
Simple merge
index 0dc598ecdc2696af956b1c517166f9e28b37dc68,0000000000000000000000000000000000000000..eff26f534fc21e3d77bc3d6cf76fce2b5a74e981
mode 100644,000000..100644
--- /dev/null
@@@ -1,20 -1,0 +1,75 @@@
- int main(int argc, char **argv)
 +#include "git-compat-util.h"
++#include "gettext.h"
 +
-       exit(0);
++struct reg_flag {
++      const char *name;
++      int flag;
++};
++
++static struct reg_flag reg_flags[] = {
++      { "EXTENDED",    REG_EXTENDED   },
++      { "NEWLINE",     REG_NEWLINE    },
++      { "ICASE",       REG_ICASE      },
++      { "NOTBOL",      REG_NOTBOL     },
++#ifdef REG_STARTEND
++      { "STARTEND",    REG_STARTEND   },
++#endif
++      { NULL, 0 }
++};
++
++static int test_regex_bug(void)
 +{
 +      char *pat = "[^={} \t]+";
 +      char *str = "={}\nfred";
 +      regex_t r;
 +      regmatch_t m[1];
 +
 +      if (regcomp(&r, pat, REG_EXTENDED | REG_NEWLINE))
 +              die("failed regcomp() for pattern '%s'", pat);
 +      if (regexec(&r, str, 1, m, 0))
 +              die("no match of pattern '%s' to string '%s'", pat, str);
 +
 +      /* http://sourceware.org/bugzilla/show_bug.cgi?id=3957  */
 +      if (m[0].rm_so == 3) /* matches '\n' when it should not */
 +              die("regex bug confirmed: re-build git with NO_REGEX=1");
 +
++      return 0;
++}
++
++int main(int argc, char **argv)
++{
++      const char *pat;
++      const char *str;
++      int flags = 0;
++      regex_t r;
++      regmatch_t m[1];
++
++      if (argc == 2 && !strcmp(argv[1], "--bug"))
++              return test_regex_bug();
++      else if (argc < 3)
++              usage("test-regex --bug\n"
++                    "test-regex <pattern> <string> [<options>]");
++
++      argv++;
++      pat = *argv++;
++      str = *argv++;
++      while (*argv) {
++              struct reg_flag *rf;
++              for (rf = reg_flags; rf->name; rf++)
++                      if (!strcmp(*argv, rf->name)) {
++                              flags |= rf->flag;
++                              break;
++                      }
++              if (!rf->name)
++                      die("do not recognize %s", *argv);
++              argv++;
++      }
++      git_setup_gettext();
++
++      if (regcomp(&r, pat, flags))
++              die("failed regcomp() for pattern '%s'", pat);
++      if (regexec(&r, str, 1, m, 0))
++              return 1;
++
++      return 0;
 +}