git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] t7002: test git grep --no-index from a bare repository
Date: Thu, 22 Jul 2010 02:02:19 -0500	[thread overview]
Message-ID: <20100722070219.GA6577@burratino> (raw)
In-Reply-To: <1279715018-24225-1-git-send-email-pclouds@gmail.com>

Hi Duy,

Nguyễn Thái Ngọc Duy wrote:

> Subject: [PATCH] t7002: test git grep --no-index from a bare repository

It’s t7810 now (to keep t7811 company).

>  There is an interesting thing about this command. Back in tp/setup
>  series, there is a patch that changes the current behavior,
>  "calculate prefix even if no worktree is found". grep is interesting
>  because it depends on the current behavior, i.e. prefix being NULL
>  in bare repo, while it still needs true prefix to do chdir()
>  stuff in run_pager().

Yes, sorry to let this hang for so long.  I liked your setup series
for many reasons and am happy to see pieces of it coming back to life.

> +++ b/Documentation/git-grep.txt
> @@ -28,8 +28,9 @@ SYNOPSIS
>  DESCRIPTION
>  -----------
>  Look for specified patterns in the tracked files in the work tree, blobs
> -registered in the index file, or blobs in given tree objects.
> -
> +registered in the index file, or blobs in given tree objects. By default
> +it will only search tracked files within the current directory (or full
> +tree if in bare repository).

Probably deserves more detail.

	Searches for lines matching the specified patterns in the
	work tree, the index, or a specified tree.

	By default, 'git grep' only examines tracked files in the
	subtree of the work tree rooted at the current working
	directory.  Output consists of matching lines preceded with
	the corresponding filename and a colon.

	With `--cached`, 'git grep' does the same search in the
	version scheduled for the next commit in the index.

	With `--no-index`, 'git grep' pays no mind to the index
	file and reports *all* matching files under the working
	directory.

	Given a commit name, 'git grep' does the same search in that
	historical version.  More generally, given a tree name, 'git
	grep' searches the subtree of that tree object corresponding
	to the path to the current directory from the root of the work
	tree (or the entire tree if there is no work tree, as in a
	bare repository).

>  
>  OPTIONS
>  -------
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 597f76b..e8abdc7 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -1109,6 +1109,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  
>  	if (use_threads)
>  		hit |= wait_all();
> +
> +	/* FIXME prefix is NULL in bare repo, no matter where cwd is */
>  	if (hit && show_in_pager)
>  		run_pager(&opt, prefix);

This comment seems kind of unhelpful.  Maybe something like

	/*
	 * NOTE NOTE NOTE: Even in a bare repository, the user
	 * probably expected the command specified with -O to run in
	 * the current directory, but when --no-index is supplied, we
	 * are passing it paths relative to the .git directory.
	 * Until that changes, this needs not to chdir() in that case.
	 */

Do I understand correctly?

-- 8< --
Subject: grep documentation: flesh out description

As Duy noticed, it is not always obvious what directory ‘git grep’
is going to search in.  Add some other details to the description,
too.

Inspired by http://gitster.livejournal.com/27674.html

Cc: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/git-grep.txt |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index 5474dd7..d6cfbc6 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -27,9 +27,26 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-Look for specified patterns in the tracked files in the work tree, blobs
-registered in the index file, or blobs in given tree objects.
-
+Searches for lines matching the specified patterns in the work
+tree, the index, or the specified tree objects.
+
+By default, 'git grep' only examines tracked files in the subtree
+of the work tree rooted at the current working directory.  Output
+consists of matching lines preceded with the corresponding
+filename and a colon.
+
+With `--cached`, 'git grep' does the same search in the version
+scheduled for the next commit in the index.
+
+With `--no-index`, 'git grep' pays no mind to the index file and
+reports *all* matching files under the working directory.
+
+When passed a commit name, 'git grep' does the same search but in
+that historical version.  More generally, given a tree name,
+'git grep' searches the subtree of that tree object corresponding
+to the path to the current directory from the root of the work tree
+(or the entire tree if there is no work tree, as in a bare
+repository).
 
 OPTIONS
 -------
-- 
1.7.2.rc3

  reply	other threads:[~2010-07-22  7:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-21 12:23 [PATCH] t7002: test git grep --no-index from a bare repository Nguyễn Thái Ngọc Duy
2010-07-22  7:02 ` Jonathan Nieder [this message]
2010-07-22 22:36   ` Nguyen Thai Ngoc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100722070219.GA6577@burratino \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).