git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/5] grep: convert to use the new get_pathspec()

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 10, 2011, 00:56 UTC
Message-ID
<7v7hb2zzxp.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1302368060-23827-6-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 29 quoted lines
> ---
>  builtin/grep.c |   10 +---------
>  1 files changed, 1 insertions(+), 9 deletions(-)
>
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 2826ca8..af16deb 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -734,7 +734,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  	const char *show_in_pager = NULL, *default_pager = "dummy";
>  	struct grep_opt opt;
>  	struct object_array list = OBJECT_ARRAY_INIT;
> -	const char **paths = NULL;
>  	struct pathspec pathspec;
>  	struct string_list path_list = STRING_LIST_INIT_NODUP;
>  	int i;
> @@ -956,14 +955,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  			verify_filename(prefix, argv[j]);
>  	}
>  
> -	if (i < argc)
> -		paths = get_pathspec_old(prefix, argv + i);
> -	else if (prefix) {
> -		paths = xcalloc(2, sizeof(const char *));
> -		paths[0] = prefix;
> -		paths[1] = NULL;
> -	}
> -	init_pathspec(&pathspec, paths);
> +	get_pathspec(&pathspec, prefix, argc - i, argv + i);

This assumes that the new API function will default to "if run without pathspec, the calling command wants to limit to cwd", doesn't it?

That is why I mentioned that the caller would need to pass a hint as to what should happen in that case in my earlier message. Probably the new API function should be something like:

    setup_pathspec(&pathspec, prefix, argc, argv, opts)

where opts is a bitmask to carry that hint (or a pointer to a structure that caller to carry a set of hints richer than a bitmask can express), and "add -u" and "grep" should set PATHSPEC_DEFAULT_LOCAL in the bitmask. The call to setup_pathspec() from the log family would not want "no user specified pathspec means limited to local" semantics.

Then when somebody wants to flip the "add -u" default in future versions, the call from "add -u" codepath can instead use PATHSPEC_DEFAULT_TREEWIDE (or perhaps the lack of PATHSPEC_DEFAULT_LOCAL bit may mean tree-wide) there.

Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 9 of 11 in “New get_pathspec()”
  1. 0/5 New get_pathspec()Nguyễn Thái Ngọc Duy, Apr 9, 2011
  2. 1/5 Rename functions in preparation for get_pathspec() restructureNguyễn Thái Ngọc Duy, Apr 9, 2011
  3. 2/5 Replace has_wildcard with PATHSPEC_NOGLOBNguyễn Thái Ngọc Duy, Apr 9, 2011
  4. Junio C HamanoApr 10, 2011
  5. Nguyen Thai Ngoc DuyApr 10, 2011
  6. 3/5 Convert prefix_pathspec() to produce struct pathspec_itemNguyễn Thái Ngọc Duy, Apr 9, 2011
  7. 4/5 Implement new get_pathspec()Nguyễn Thái Ngọc Duy, Apr 9, 2011
  8. 5/5 grep: convert to use the new get_pathspec()Nguyễn Thái Ngọc Duy, Apr 9, 2011
  9. Junio C HamanoApr 10, 2011
  10. Nguyen Thai Ngoc DuyApr 10, 2011
  11. Junio C HamanoApr 9, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.