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

[PATCH 2/4] Makefile: exclude test cruft from FIND_SOURCE_FILES

From
Jeff King <peff@peff.net>
Date
Dec 14, 2016, 14:28 UTC
Message-ID
<20161214142804.b6q7enowcavagmam@sigill.intra.peff.net>
In-Reply-To
<20161214142533.svktxk63eiwaaeor@sigill.intra.peff.net>

The test directory may contain three types of files that match our patterns:

  1. Helper programs in t/helper.
  2. Sample data files (e.g., t/t4051/hello.c).
  3. Untracked cruft in trash directories and t/perf/build.

We want to match (1), but not the other two, as they just clutter up the list.

For the ls-files method, we can drop (2) with a negative pathspec. We do not have to care about (3), since ls-files will not list untracked files.

For `find`, we can match both cases with `-prune` patterns.
Signed-off-by: Jeff King <peff@peff.net>
---
I expected that:
  ':![tp][0-9][0-9][0-9][0-9]'

would work, but it doesn't. I think because we don't match intermediate directories against pathspecs. So you have to use wildcards to match the rest of the path.

 Makefile | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index f42b1953d..001126931 100644
--- a/Makefile
+++ b/Makefile
@@ -2150,9 +2150,15 @@ po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
 	$(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
 
 FIND_SOURCE_FILES = ( \
-	git ls-files '*.[hcS]' 2>/dev/null || \
+	git ls-files \
+		'*.[hcS]' \
+		':!*[tp][0-9][0-9][0-9][0-9]*' \
+		2>/dev/null || \
 	$(FIND) . \
 		\( -name .git -type d -prune \) \
+		-o \( -name '[tp][0-9][0-9][0-9][0-9]' -type d -prune \) \
+		-o \( -name build -type d -prune \) \
+		-o \( -name 'trash*' -type d -prune \) \
 		-o \( -name '*.[hcS]' -type f -print \) \
 	)
 
-- 
2.11.0.341.g202cd3142
Previous: Jeff KingNext: Jeff King
Message 3 of 5 in “"make tags" improvements”
  1. 0/4 "make tags" improvementsJeff King, Dec 14, 2016
  2. 1/4 Makefile: reformat FIND_SOURCE_FILESJeff King, Dec 14, 2016
  3. 2/4 Makefile: exclude test cruft from FIND_SOURCE_FILESJeff King, Dec 14, 2016
  4. 3/4 Makefile: match shell scripts in FIND_SOURCE_FILESJeff King, Dec 14, 2016
  5. 4/4 Makefile: exclude contrib from FIND_SOURCE_FILESJeff King, Dec 14, 2016

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.