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

Re: [PATCH 3/3] completion: match ctags symbol names in grep patterns

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 18, 2011, 17:14 UTC
Message-ID
<7vipnmgr2w.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20111018075521.GB20976@elie.hsd1.il.comcast.net>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 8 quoted lines
> In this new tags/cscope example, one could make an argument that
> running exactly once is similarly better than running as needed (as in
> (ii) above), by pointing out that
>
> 	make tags TAGS cscope
>
> would have to check for a working "git ls-files" once instead of three
> times.

I tend to agree that once instead of three times is not such an improvement, especially given how cheap builtin-invocation of ls-files is, but then once every invocation of $(MAKE) would also be negligible (it is not once every internal target evaluation).

In any case, here is what I'll queue. I like the fact that your suggestion avoids an extra "test invocation" that spends cycles to read the full index without contributing to the end result.

By the way, did anybody know that "git ls-files >/dev/null" is more expensive than "git ls-files '~/' >/dev/null" as a way to see if there is ls-files command available?

-- >8 --
Subject: [PATCH] Makefile: ask "ls-files" to list source files if available

The [ce]tags and cscope targets used to run "find" looking for any paths that match '*.[chS]' to feed the list of source files to downstream xargs.

Use "git ls-files" if it is already available to us, and otherwise use a tighter "find" expression that does not list directories and does not go into our .git directory.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Makefile |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 8d6d451..badfb77 100644
--- a/Makefile
+++ b/Makefile
@@ -2115,17 +2115,21 @@ po/git.pot: $(LOCALIZED_C)
 
 pot: po/git.pot
 
+FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
+			$(FIND) . \( -name .git -type d -prune \) \
+				-o \( -name '*.[hcS]' -type f -print \) )
+
 $(ETAGS_TARGET): FORCE
 	$(RM) $(ETAGS_TARGET)
-	$(FIND) . -name '*.[hcS]' -print | xargs etags -a -o $(ETAGS_TARGET)
+	$(FIND_SOURCE_FILES) | xargs etags -a -o $(ETAGS_TARGET)
 
 tags: FORCE
 	$(RM) tags
-	$(FIND) . -name '*.[hcS]' -print | xargs ctags -a
+	$(FIND_SOURCE_FILES) | xargs ctags -a
 
 cscope:
 	$(RM) cscope*
-	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
+	$(FIND_SOURCE_FILES) | xargs cscope -b
 
 ### Detect prefix changes
 TRACK_CFLAGS = $(CC):$(subst ','\'',$(ALL_CFLAGS)):\
-- 
1.7.7.388.g3a4b7
Previous: Jonathan NiederNext: Jeff King
Message 11 of 24 in “stupid git tricks”
  1. 0/3 stupid git tricksJeff King, Oct 18, 2011
  2. 1/3 contrib: add diff highlight scriptJeff King, Oct 18, 2011
  3. 2/3 contrib: add git-jump scriptJeff King, Oct 18, 2011
  4. 3/3 completion: match ctags symbol names in grep patternsJeff King, Oct 18, 2011
  5. Junio C HamanoOct 18, 2011
  6. Jonathan NiederOct 18, 2011
  7. Junio C HamanoOct 18, 2011
  8. Matthieu MoyOct 18, 2011
  9. Junio C HamanoOct 18, 2011
  10. Jonathan NiederOct 18, 2011
  11. Junio C HamanoOct 18, 2011
  12. Jeff KingOct 18, 2011
  13. SZEDER GáborOct 21, 2011
  14. Jeff KingOct 21, 2011
  15. 1/3 contrib: add diff highlight scriptJeff King, Oct 21, 2011
  16. 2/3 contrib: add git-jump scriptJeff King, Oct 21, 2011
  17. Jeff KingOct 21, 2011
  18. 3/3 completion: match ctags symbol names in grep patternsJeff King, Oct 21, 2011
  19. 4/3 completion: use __gitcomp_nl for ctag matchingJeff King, Oct 21, 2011
  20. SZEDER GáborOct 23, 2011
  21. Jeff KingOct 28, 2011
  22. SZEDER GáborOct 29, 2011
  23. Jeff KingNov 1, 2011
  24. Junio C HamanoNov 1, 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.