aboutsummaryrefslogtreecommitdiff
path: root/builtin-grep.c
Commit message (Collapse)AuthorAge
* Merge branch 'jc/grep-lookahead'Junio C Hamano2010-01-20
|\ | | | | | | | | | | | | | | | | | | | | | | | | * jc/grep-lookahead: grep --no-index: allow use of "git grep" outside a git repository grep: prepare to run outside of a work tree grep: rip out pessimization to use fixmatch() grep: rip out support for external grep grep: optimize built-in grep by skipping lines that do not hit Conflicts: builtin-grep.c t/t7002-grep.sh
| * grep --no-index: allow use of "git grep" outside a git repositoryJunio C Hamano2010-01-15
| | | | | | | | | | | | | | | | | | | | | | | | Just like some people wanted diff features that are not found in other people's diff implementations outside of a git repository and added --no-index mode to the command, this adds --no-index mode to the "git grep" command. Also, inside a git repository, --no-index mode allows you to grep in untracked (but not ignored) files. Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * grep: prepare to run outside of a work treeJunio C Hamano2010-01-15
| | | | | | | | | | | | | | | | | | | | | | This moves the call to setup_git_directory() for running "grep" from the "git" wrapper to the implementation of the "grep" subcommand. A new variable "use_index" is always true at this stage in the series, and when it is on, we require that we are in a directory that is under git control. To make sure we die the same way, we make a second call into setup_git_directory() when we detect this situation. Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * grep: rip out support for external grepJunio C Hamano2010-01-13
| | | | | | | | | | | | | | We still allow people to pass --[no-]ext-grep on the command line, but the option is ignored. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'maint'Junio C Hamano2010-01-18
|\ \ | | | | | | | | | | | | | | | | | | * maint: Update draft release notes to 1.6.6.1 grep: NUL terminate input from a file fast-import: tag may point to any object type
| * \ Merge branch 'jm/maint-1.6.5-grep-NUL-terminate' into maintJunio C Hamano2010-01-18
| |\ \ | | | | | | | | | | | | | | | | * jm/maint-1.6.5-grep-NUL-terminate: grep: NUL terminate input from a file
| | * | grep: NUL terminate input from a fileJim Meyering2010-01-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Internally "git grep" runs regexec(3) that expects its input string to be NUL terminated. When searching inside blob data, read_sha1_file() automatically gives such a buffer, but builtin-grep.c forgot to put the NUL at the end, even though it allocated enough space for it. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| | * | Merge branch 'bc/grep-i-F' into maintJunio C Hamano2009-12-03
| | |\ \ | | | | | | | | | | | | | | | | | | | | * bc/grep-i-F: grep: Allow case insensitive search of fixed-strings
* | | \ \ Merge branch 'nd/sparse'Junio C Hamano2010-01-13
|\ \ \ \ \ | |/ / / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * nd/sparse: (25 commits) t7002: test for not using external grep on skip-worktree paths t7002: set test prerequisite "external-grep" if supported grep: do not do external grep on skip-worktree entries commit: correctly respect skip-worktree bit ie_match_stat(): do not ignore skip-worktree bit with CE_MATCH_IGNORE_VALID tests: rename duplicate t1009 sparse checkout: inhibit empty worktree Add tests for sparse checkout read-tree: add --no-sparse-checkout to disable sparse checkout support unpack-trees(): ignore worktree check outside checkout area unpack_trees(): apply $GIT_DIR/info/sparse-checkout to the final index unpack-trees(): "enable" sparse checkout and load $GIT_DIR/info/sparse-checkout unpack-trees.c: generalize verify_* functions unpack-trees(): add CE_WT_REMOVE to remove on worktree alone Introduce "sparse checkout" dir.c: export excluded_1() and add_excludes_from_file_1() excluded_1(): support exclude files in index unpack-trees(): carry skip-worktree bit over in merged_entry() Read .gitignore from index if it is skip-worktree Avoid writing to buffer in add_excludes_from_file_1() ... Conflicts: .gitignore Documentation/config.txt Documentation/git-update-index.txt Makefile entry.c t/t7002-grep.sh
| * | | | t7002: test for not using external grep on skip-worktree pathsNguyễn Thái Ngọc Duy2010-01-06
| | | | | | | | | | | | | | | | | | | | | | | | | Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | | | grep: do not do external grep on skip-worktree entriesNguyễn Thái Ngọc Duy2009-12-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Skip-worktree entries are not on disk. We cannot use external grep in such cases. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | | | Teach Git to respect skip-worktree bit (reading part)Nguyễn Thái Ngọc Duy2009-08-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | grep: turn on --cached for files that is marked skip-worktree ls-files: do not check for deleted file that is marked skip-worktree update-index: ignore update request if it's skip-worktree, while still allows removing diff*: skip worktree version Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | | | grep: -L should show empty filesJunio C Hamano2010-01-12
| |_|_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The -L (--files-without-match) option is supposed to show paths that produced no matches. When running the internal grep on work tree files, however, we had an optimization to just return on zero-sized files, without doing anything. This optimization doesn't matter too much in practice (a tracked empty file must be rare, or there is something wrong with your project); to produce results consistent with GNU grep, we should stop the optimization and show empty files as not having the given pattern. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | | Merge branch 'bc/grep-i-F'Junio C Hamano2009-11-22
|\ \ \ \ | | |_|/ | |/| | | | | | | | | | * bc/grep-i-F: grep: Allow case insensitive search of fixed-strings
| * | | grep: Allow case insensitive search of fixed-stringsBrian Collins2009-11-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "git grep" currently an error when you combine the -F and -i flags. This isn't in line with how GNU grep handles it. This patch allows the simultaneous use of those flags. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Brian Collins <bricollins@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | | grep: unset GREP_OPTIONS before spawning external grepRené Scharfe2009-11-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While we're at it, also unset GREP_COLOR and GREP_COLORS in case colouring is not enabled, to be on the safe side. The presence of these variables alone is not sufficient to trigger coloured output with GNU grep, but other implementations may behave differently. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | | Show usage string for 'git grep -h'Jonathan Nieder2009-11-09
| |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clarification: the following description only talks about "git grep -h" without any other options and arguments. Such a change cannot be breaking backward compatibility. "grep -h" cannot be asking for suppressing filenames, as there is no match pattern specified. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Merge branch 'maint-1.6.4' into maintJunio C Hamano2009-10-16
|\ \ \ | |/ / |/| | | | | | | | * maint-1.6.4: grep: do not segfault when -f is used
| * | grep: do not segfault when -f is usedMatt Kraai2009-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "git grep" would segfault if its -f option was used because it would try to use an uninitialized strbuf, so initialize the strbuf. Thanks to Johannes Sixt <j.sixt@viscovery.net> for the help with the test cases. Signed-off-by: Matt Kraai <kraai@ftbfs.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Merge branch 'maint'Junio C Hamano2009-09-13
|\ \ \ | |/ / | | / | |/ |/| | | | | | | | | | | | | | | | | * maint: GIT 1.6.4.3 svn: properly escape arguments for authors-prog http.c: remove verification of remote packs grep: accept relative paths outside current working directory grep: fix exit status if external_grep() punts Conflicts: GIT-VERSION-GEN RelNotes
| * Merge branch 'cb/maint-1.6.3-grep-relative-up' into maintJunio C Hamano2009-09-13
| |\ | | | | | | | | | | | | | | | | | | | | | | | | * cb/maint-1.6.3-grep-relative-up: grep: accept relative paths outside current working directory grep: fix exit status if external_grep() punts Conflicts: t/t7002-grep.sh
| | * grep: accept relative paths outside current working directoryClemens Buchacher2009-09-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "git grep" would barf at relative paths pointing outside the current working directory (or subdirectories thereof). Use quote_path_relative(), which can handle such cases just fine. [jc: added tests.] Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| | * grep: fix exit status if external_grep() puntsClemens Buchacher2009-09-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | If external_grep() is called and punts, grep_cache() mistakenly reported a hit, even if there were none. The bug can be triggered by calling "git grep --no-color" from a subdirectory. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | grep: Add --max-depth option.Michał Kiedrowicz2009-07-22
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is useful to grep directories non-recursively, e.g. when one wants to look for all files in the toplevel directory, but not in any subdirectory, or in Documentation/, but not in Documentation/technical/. This patch adds support for --max-depth <depth> option to git-grep. If it is given, git-grep descends at most <depth> levels of directories below paths specified on the command line. Note that if path specified on command line contains wildcards, this option makes no sense, e.g. $ git grep -l --max-depth 0 GNU -- 'contrib/*' (note the quotes) will search all files in contrib/, even in subdirectories, because '*' matches all files. Documentation updates, bash-completion and simple test cases are also provided. Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'rs/grep-p'Junio C Hamano2009-07-09
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * rs/grep-p: grep: simplify -p output grep -p: support user defined regular expressions grep: add option -p/--show-function grep: handle pre context lines on demand grep: print context hunk marks between files grep: move context hunk mark handling into show_line() userdiff: add xdiff_clear_find_func()
| * | grep: simplify -p outputRené Scharfe2009-07-02
| | | | | | | | | | | | | | | | | | | | | | | | It was found a bit too loud to show == separators between the function headers. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | grep -p: support user defined regular expressionsRené Scharfe2009-07-01
| | | | | | | | | | | | | | | | | | | | | | | | Respect the userdiff attributes and config settings when looking for lines with function definitions in git grep -p. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | grep: add option -p/--show-functionRené Scharfe2009-07-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new option -p instructs git grep to print the previous function definition as a context line, similar to diff -p. Such context lines are marked with an equal sign instead of a dash. This option complements the existing context options -A, -B, -C. Function definitions are detected using the same heuristic that diff uses. User defined regular expressions are not supported, yet. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | grep: print context hunk marks between filesRené Scharfe2009-07-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Print a hunk mark before matches from a new file are shown, in addition to the current behaviour of printing them if lines have been skipped. The result is easier to read, as (presumably unrelated) matches from different files are separated by a hunk mark. GNU grep does the same. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Convert existing die(..., strerror(errno)) to die_errno()Thomas Rast2009-06-27
|/ / | | | | | | | | | | | | | | | | | | | | Change calls to die(..., strerror(errno)) to use the new die_errno(). In the process, also make slight style adjustments: at least state _something_ about the function that failed (instead of just printing the pathname), and put paths in single quotes. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | parse-opts: prepare for OPT_FILENAMEStephen Boyd2009-05-25
| | | | | | | | | | | | | | | | | | | | To give OPT_FILENAME the prefix, we pass the prefix to parse_options() which passes the prefix to parse_options_start() which sets the prefix member of parse_opts_ctx accordingly. If there isn't a prefix in the calling context, passing NULL will suffice. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | grep: make callback functions staticRené Scharfe2009-05-20
| | | | | | | | | | | | | | | | Suggested by Stephen Boyd: make the callback functions used for option parsing static. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | grep: use parseoptRené Scharfe2009-05-09
| | | | | | | | | | | | | | | | | | | | | | Convert git-grep to parseopt. The bitfields in struct grep_opt are converted to full ints, increasing its size. This shouldn't be a problem as there is only a single instance in memory. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | grep: remove global variable builtin_grepRené Scharfe2009-05-09
|/ | | | | | | | Replace the only global variable in builtin-grep.c, builtin_grep, by a local one and a function parameter with reversed meaning. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* grep: don't support "grep.color"-like config optionsMarkus Heidelberg2009-04-20
| | | | | | | | | | color.grep and color.grep.* is the official and documented way to highlight grep matches. Comparable options like diff.color.* and status.color.* exist for backward compatibility reasons only and are not documented any more. Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* grep: prefer builtin over external one when coloring resultsNguyễn Thái Ngọc Duy2009-03-17
| | | | | | | | | As far as I know, not all grep programs support coloring, so we should rely on builtin grep. If you want external grep, set color.grep.external to empty string. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* grep: add support for coloring with external grepsRené Scharfe2009-03-07
| | | | | | | | | | | | | | | | | | Add the config variable color.grep.external, which can be used to switch on coloring of external greps. To enable auto coloring with GNU grep, one needs to set color.grep.external to --color=always to defeat the pager started by git grep. The value of the config variable will be passed to the external grep only if it would colorize internal grep's output, so automatic terminal detected works. The default is to not pass any option, because the external grep command could be a program without color support. Also set the environment variables GREP_COLOR and GREP_COLORS to pass the configured color for matches to the external grep. This works with GNU grep; other variables could be added as needed. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* grep: color patterns in outputRené Scharfe2009-03-07
| | | | | | | | | | | | | | | | Coloring matches makes them easier to spot in the output. Add two options and two parameters: color.grep (to turn coloring on or off), color.grep.match (to set the color of matches), --color and --no-color (to turn coloring on or off, respectively). The output of external greps is not changed. This patch is based on earlier ones by Nguyễn Thái Ngọc Duy and Thiago Alves. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'maint-1.6.0' into maintJunio C Hamano2009-02-03
|\ | | | | | | | | * maint-1.6.0: grep: pass -I (ignore binary) down to external grep
| * grep: pass -I (ignore binary) down to external grepJunio C Hamano2009-02-02
| | | | | | | | | | | | We forgot to pass this option to the external grep process. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | grep: grep cache entries if they are "assume unchanged"Nguyễn Thái Ngọc Duy2008-12-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | "Assume unchanged" bit means "please pretend that I have never touched this file", so if user removes the file, we should not care. This patch teaches "git grep" to use cache version in such situations. External grep case has not been fixed yet. But given that on the platform that CE_VALID bit may be used like Windows, external grep is not available anyway, I would wait for people to raise their hands before touching it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | grep: support --no-ext-grep to test builtin grepNguyễn Thái Ngọc Duy2008-12-27
| | | | | | | | | | Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | git grep: Add "-z/--null" option as in GNU's grep.Raphael Zimmerer2008-10-01
|/ | | | | | | | | | | Here's a trivial patch that adds "-z" and "--null" options to "git grep". It was discussed on the mailing-list that git's "-z" convention should be used instead of GNU grep's "-Z". So things like 'git grep -l -z "$FOO" | xargs -0 sed -i "s/$FOO/$BOO/"' do work now. Signed-off-by: Raphael Zimmerer <killekulla@rdrz.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Merge branch 'nd/worktree' into maintJunio C Hamano2008-09-03
|\ | | | | | | | | | | | | | | | | * nd/worktree: setup_git_directory(): fix move to worktree toplevel directory update-index: fix worktree setup read-tree: setup worktree if merge is required grep: fix worktree setup diff*: fix worktree setup
| * grep: fix worktree setupNguyễn Thái Ngọc Duy2008-08-28
| | | | | | | | | | | | | | | | Unless used with --cached or grepping on a tree, "git grep" will search on working directory, so set up worktree properly Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | 'git foo' program identifies itself without dash in die() messagesJunio C Hamano2008-08-31
|/ | | | | | | | | | This is a mechanical conversion of all '*.c' files with: s/((?:die|error|warning)\("git)-(\S+:)/$1 $2/; The result was manually inspected and no false positive was found. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'maint'Junio C Hamano2008-07-20
|\ | | | | | | | | | | | | | | | | * maint: fix usage string for git grep refresh-index: fix bitmask assignment Conflicts: builtin-grep.c
| * fix usage string for git grepJonathan Nieder2008-07-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this patch, git-grep gives confusing usage information: $ git grep --confused usage: git grep <option>* <rev>* [-e] <pattern> [<path>...] $ git grep HEAD pattern fatal: ambiguous argument 'pattern': unknown revision or path no t in the working tree. Use '--' to separate paths from revisions So put <pattern> before the <rev>s, in accordance with actual correct usage. While we're changing the usage string, we might as well include the "--" separating revisions and paths, too. Signed-off-by: Jonathan Nieder <jrnieder@uchicago.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'sb/dashless'Junio C Hamano2008-07-16
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | * sb/dashless: Make usage strings dash-less t/: Use "test_must_fail git" instead of "! git" t/test-lib.sh: exit with small negagive int is ok with test_must_fail Conflicts: builtin-blame.c builtin-mailinfo.c builtin-mailsplit.c builtin-shortlog.c git-am.sh t/t4150-am.sh t/t4200-rerere.sh
| * Make usage strings dash-lessStephan Beyer2008-07-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>