Merge branch 'jr/grep-en-config'
authorJunio C Hamano <gitster@pobox.com>
Sat, 2 Apr 2011 00:56:27 +0000 (17:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 2 Apr 2011 00:56:27 +0000 (17:56 -0700)
* jr/grep-en-config:
grep: allow -E and -n to be turned on by default via configuration

1  2 
Documentation/config.txt
builtin/grep.c
diff --combined Documentation/config.txt
index 52ffbf4efb8d17c22893112208c5864d4c19741d,01d5fabc4c4a84641c0d95c201949d4345905fe5..1d0d1b76772cf33bd6dba110fef614e2e87a5f09
@@@ -62,7 -62,7 +62,7 @@@ Internal whitespace within a variable v
  
  The values following the equals sign in variable assign are all either
  a string, an integer, or a boolean.  Boolean values may be given as yes/no,
 -0/1, true/false or on/off.  Case is not significant in boolean values, when
 +1/0, true/false or on/off.  Case is not significant in boolean values, when
  converting value to the canonical form using '--bool' type specifier;
  'git config' will ensure that the output is "true" or "false".
  
@@@ -1098,6 -1098,12 +1098,12 @@@ All gitcvs variables except for 'gitcvs
  is one of "ext" and "pserver") to make them apply only for the given
  access method.
  
+ grep.lineNumber::
+       If set to true, enable '-n' option by default.
+ grep.extendedRegexp::
+       If set to true, enable '--extended-regexp' option by default.
  gui.commitmsgwidth::
        Defines how wide the commit message window is in the
        linkgit:git-gui[1]. "75" is the default.
diff --combined builtin/grep.c
index 5b8f30d3ed472bb74f1b992b5098a08f5d5377a1,5743d920d49af64c310f1047b90dc326dcdce371..891e5eab3da4d835325e859bf8979664e2c112ae
@@@ -244,7 -244,7 +244,7 @@@ static void start_threads(struct grep_o
                err = pthread_create(&threads[i], NULL, run, o);
  
                if (err)
 -                      die("grep: failed to create thread: %s",
 +                      die(_("grep: failed to create thread: %s"),
                            strerror(err));
        }
  }
@@@ -302,6 -302,19 +302,19 @@@ static int grep_config(const char *var
        default: return 0;
        }
  
+       if (!strcmp(var, "grep.extendedregexp")) {
+               if (git_config_bool(var, value))
+                       opt->regflags |= REG_EXTENDED;
+               else
+                       opt->regflags &= ~REG_EXTENDED;
+               return 0;
+       }
+       if (!strcmp(var, "grep.linenumber")) {
+               opt->linenum = git_config_bool(var, value);
+               return 0;
+       }
        if (!strcmp(var, "color.grep"))
                opt->color = git_config_colorbool(var, value, -1);
        else if (!strcmp(var, "color.grep.context"))
@@@ -349,7 -362,7 +362,7 @@@ static void *load_sha1(const unsigned c
        void *data = lock_and_read_sha1_file(sha1, &type, size);
  
        if (!data)
 -              error("'%s': unable to read %s", name, sha1_to_hex(sha1));
 +              error(_("'%s': unable to read %s"), name, sha1_to_hex(sha1));
  
        return data;
  }
@@@ -400,7 -413,7 +413,7 @@@ static void *load_file(const char *file
        if (lstat(filename, &st) < 0) {
        err_ret:
                if (errno != ENOENT)
 -                      error("'%s': %s", filename, strerror(errno));
 +                      error(_("'%s': %s"), filename, strerror(errno));
                return 0;
        }
        if (!S_ISREG(st.st_mode))
                goto err_ret;
        data = xmalloc(*sz + 1);
        if (st.st_size != read_in_full(i, data, *sz)) {
 -              error("'%s': short read %s", filename, strerror(errno));
 +              error(_("'%s': short read %s"), filename, strerror(errno));
                close(i);
                free(data);
                return 0;
@@@ -473,7 -486,7 +486,7 @@@ static void run_pager(struct grep_opt *
        argv[path_list->nr] = NULL;
  
        if (prefix && chdir(prefix))
 -              die("Failed to chdir: %s", prefix);
 +              die(_("Failed to chdir: %s"), prefix);
        status = run_command_v_opt(argv, RUN_USING_SHELL);
        if (status)
                exit(status);
@@@ -548,7 -561,7 +561,7 @@@ static int grep_tree(struct grep_opt *o
  
                        data = lock_and_read_sha1_file(entry.sha1, &type, &size);
                        if (!data)
 -                              die("unable to read tree (%s)",
 +                              die(_("unable to read tree (%s)"),
                                    sha1_to_hex(entry.sha1));
  
                        strbuf_addch(base, '/');
@@@ -579,7 -592,7 +592,7 @@@ static int grep_object(struct grep_opt 
                data = read_object_with_reference(obj->sha1, tree_type,
                                                  &size, NULL);
                if (!data)
 -                      die("unable to read tree (%s)", sha1_to_hex(obj->sha1));
 +                      die(_("unable to read tree (%s)"), sha1_to_hex(obj->sha1));
  
                len = name ? strlen(name) : 0;
                strbuf_init(&base, PATH_MAX + len + 1);
                free(data);
                return hit;
        }
 -      die("unable to grep from object of type %s", typename(obj->type));
 +      die(_("unable to grep from object of type %s"), typename(obj->type));
  }
  
  static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
@@@ -649,7 -662,7 +662,7 @@@ static int context_callback(const struc
        }
        value = strtol(arg, (char **)&endp, 10);
        if (*endp) {
 -              return error("switch `%c' expects a numerical value",
 +              return error(_("switch `%c' expects a numerical value"),
                             opt->short_name);
        }
        grep_opt->pre_context = grep_opt->post_context = value;
@@@ -666,7 -679,7 +679,7 @@@ static int file_callback(const struct o
  
        patterns = from_stdin ? stdin : fopen(arg, "r");
        if (!patterns)
 -              die_errno("cannot open '%s'", arg);
 +              die_errno(_("cannot open '%s'"), arg);
        while (strbuf_getline(&sb, patterns, '\n') == 0) {
                char *s;
                size_t len;
@@@ -909,11 -922,11 +922,11 @@@ int cmd_grep(int argc, const char **arg
        }
  
        if (!opt.pattern_list)
 -              die("no pattern given.");
 +              die(_("no pattern given."));
        if (!opt.fixed && opt.ignore_case)
                opt.regflags |= REG_ICASE;
        if ((opt.regflags != REG_NEWLINE) && opt.fixed)
 -              die("cannot mix --fixed-strings and regexp");
 +              die(_("cannot mix --fixed-strings and regexp"));
  
  #ifndef NO_PTHREADS
        if (online_cpus() == 1 || !grep_threads_ok(&opt))
                if (!get_sha1(arg, sha1)) {
                        struct object *object = parse_object(sha1);
                        if (!object)
 -                              die("bad object %s", arg);
 +                              die(_("bad object %s"), arg);
                        add_object_array(object, arg, &list);
                        continue;
                }
        pathspec.recursive = 1;
  
        if (show_in_pager && (cached || list.nr))
 -              die("--open-files-in-pager only works on the worktree");
 +              die(_("--open-files-in-pager only works on the worktree"));
  
        if (show_in_pager && opt.pattern_list && !opt.pattern_list->next) {
                const char *pager = path_list.items[0].string;
  
        if (!use_index) {
                if (cached)
 -                      die("--cached cannot be used with --no-index.");
 +                      die(_("--cached cannot be used with --no-index."));
                if (list.nr)
 -                      die("--no-index cannot be used with revs.");
 +                      die(_("--no-index cannot be used with revs."));
                hit = grep_directory(&opt, &pathspec);
        } else if (!list.nr) {
                if (!cached)
                hit = grep_cache(&opt, &pathspec, cached);
        } else {
                if (cached)
 -                      die("both --cached and trees are given.");
 +                      die(_("both --cached and trees are given."));
                hit = grep_objects(&opt, &pathspec, &list);
        }