Merge branch 'jc/maint-grep-untracked-exclude' into jc/grep-untracked-exclude
authorJunio C Hamano <gitster@pobox.com>
Sun, 16 Oct 2011 03:26:52 +0000 (20:26 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 16 Oct 2011 03:26:52 +0000 (20:26 -0700)
* jc/maint-grep-untracked-exclude:
  grep: fix the error message that mentions --exclude

Conflicts:
builtin/grep.c

1  2 
builtin/grep.c

diff --cc builtin/grep.c
@@@ -1024,45 -948,33 +1024,45 @@@ int cmd_grep(int argc, const char **arg
                        verify_filename(prefix, argv[j]);
        }
  
 -      if (i < argc)
 -              paths = get_pathspec(prefix, argv + i);
 -      else if (prefix) {
 -              paths = xcalloc(2, sizeof(const char *));
 -              paths[0] = prefix;
 -              paths[1] = NULL;
 +      paths = get_pathspec(prefix, argv + i);
 +      init_pathspec(&pathspec, paths);
 +      pathspec.max_depth = opt.max_depth;
 +      pathspec.recursive = 1;
 +
 +      if (show_in_pager && (cached || list.nr))
 +              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;
 +              int len = strlen(pager);
 +
 +              if (len > 4 && is_dir_sep(pager[len - 5]))
 +                      pager += len - 4;
 +
 +              if (!strcmp("less", pager) || !strcmp("vi", pager)) {
 +                      struct strbuf buf = STRBUF_INIT;
 +                      strbuf_addf(&buf, "+/%s%s",
 +                                      strcmp("less", pager) ? "" : "*",
 +                                      opt.pattern_list->pattern);
 +                      string_list_append(&path_list, buf.buf);
 +                      strbuf_detach(&buf, NULL);
 +              }
        }
  
 +      if (!show_in_pager)
 +              setup_pager();
 +
        if (!use_index && (untracked || cached))
 -              die("--cached or --untracked cannot be used with --no-index.");
 +              die(_("--cached or --untracked cannot be used with --no-index."));
  
        if (!use_index || untracked) {
 -              int hit;
                int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude;
                if (list.nr)
 -                      die("--no-index or --untracked cannot be used with revs.");
 -              hit = grep_directory(&opt, paths, use_exclude);
 -              if (use_threads)
 -                      hit |= wait_all();
 -              return !hit;
 -      }
 -
 -      if (0 <= opt_exclude)
 -              die("--[no-]exclude-standard cannot be used for tracked contents.");
 -
 -      if (!list.nr) {
 -              int hit;
 +                      die(_("--no-index or --untracked cannot be used with revs."));
 +              hit = grep_directory(&opt, &pathspec, use_exclude);
 +      } else if (0 <= opt_exclude) {
-               die(_("--exclude or --no-exclude cannot be used for tracked contents."));
++              die(_("--[no-]exclude-standard cannot be used for tracked contents."));
 +      } else if (!list.nr) {
                if (!cached)
                        setup_work_tree();