From: Junio C Hamano Date: Sun, 16 Oct 2011 03:26:52 +0000 (-0700) Subject: Merge branch 'jc/maint-grep-untracked-exclude' into jc/grep-untracked-exclude X-Git-Tag: v1.7.8-rc0~71^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9fddaf78964a835160a0b27cdac724c27aab09bf;p=thirdparty%2Fgit.git Merge branch 'jc/maint-grep-untracked-exclude' into jc/grep-untracked-exclude * jc/maint-grep-untracked-exclude: grep: fix the error message that mentions --exclude Conflicts: builtin/grep.c --- 9fddaf78964a835160a0b27cdac724c27aab09bf diff --cc builtin/grep.c index 5e6d3c3352,45a23cfe64..14b05a43bc --- a/builtin/grep.c +++ b/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();