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

Re: multiple source file extensions

From
Duy Nguyen <pclouds@gmail.com>
Date
May 2, 2015, 02:04 UTC
Message-ID
<20150502020431.GA15775@lanh>
In-Reply-To
<20150502011100.GB5634@peff.net>
On Fri, May 01, 2015 at 09:11:01PM -0400, Jeff King wrote:
> Unfortunately there is no way to use curly braces with git's pathspec,
> so you have to write out three separate `*` arguments rather than using
> the shell-style {cc,cpp,h}.
Noted. Need to add curly brace support in pathspec :-)
Show 6 quoted lines
>   git grep pattern -- '*.cc' '*.cpp' '*.h'
> 
> Note that the "--" is important (it's what tells git "these are
> pathspecs and not revision names"; normally git will guess if you are
> passing literal pathnames, but the glob patterns fool the guessing
> machinery).

I'm having something like below to avoid the need for "--" in this case. Probably a good time to throw it out and get some feedback. I think it's a good change and does not compromise our ambiguity check..

This patch is modified just for reading so it may not build. The real series takes care of "--" for both wildcard and magic pathspec. But I don't think we need to see it now.

-- 8< --
Subject: [PATCH] Avoid the need of "--" when wildcard pathspec is used

When "--" is lacking from the command line and a command can take both revs and paths, the idea is if an argument can be seen as both an extended SHA-1 and a path, then "--" is required or git refuses to continue. It's currently implemented as:

 (1) if an argument is rev, then it must not exist in worktree
 (2) else, it must exist in worktree
 (3) else, "--" is required.

These rules work for literal paths, but when non-literal pathspec is involved, it almost always requires the user to add "--" because it fails (2) and (1) is really rarely met (take "*.c" for example, (1) is met if there is a ref named "*.c").

This patch modifies the rules a bit by considering any valid (*) wildcard pathspec "exist in worktree". The rules become:

 (1) if an arg is a rev, then it must either exist in worktree or not
     be a valid wildcard pathspec.
 (2) else, it either exists in worktree or is a wildcard pathspec
 (3) else, "--" is required.
With the new rules, "--" is not needed most of the time when wildcard
pathspec is involved.
---
 setup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/setup.c b/setup.c
index 979b13f..1055b82 100644
--- a/setup.c
+++ b/setup.c
@@ -140,7 +140,9 @@ int check_filename(const char *prefix, const char *arg)
 		if (arg[2] == '\0') /* ":/" is root dir, always exists */
 			return 1;
 		name = arg + 2;
-	} else if (prefix)
+	} else if (!no_wildcard(arg))
+		return 1;
+	else if (prefix)
 		name = prefix_filename(prefix, strlen(prefix), arg);
 	else
 		name = arg;
-- 
2.3.0.rc1.137.g477eb31

-- 8< --
 
Previous: Jeff KingNext: Duy Nguyen
Message 4 of 13 in “multiple source file extensions”
  1. Thiago FarinaMay 2, 2015
  2. Josh HaginsMay 2, 2015
  3. Jeff KingMay 2, 2015
  4. Duy NguyenMay 2, 2015
  5. Duy NguyenMay 2, 2015
  6. Jeff KingMay 2, 2015
  7. Eric SunshineMay 2, 2015
  8. Junio C HamanoMay 3, 2015
  9. Jeff KingMay 2, 2015
  10. Thiago FarinaMay 4, 2015
  11. Jeff KingMay 5, 2015
  12. Mikael MagnussonMay 5, 2015
  13. Jeff KingMay 5, 2015

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.