mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <>
Subject: [PATCH/RFC] Makefile: dedup list of files obtained from ls-files
Date: Sun, 21 Apr 2019 22:19:04 +0900	[thread overview]
Message-ID: <> (raw)

Since 33533975 ("Makefile: ask "ls-files" to list source files if
available", 2011-10-18), we optionally asked "ls-files" to list the
source files that ought to exist, as a faster approximation for
"find" on working tree files.

This works reasonably well, except that it ends up listing the same
path multiple times if the index is unmerged.  Because the original
use of this construct was to name files to run etags over, and the
etags command happily takes the same filename multiple times without
causing any harm, there was no problem (other than perhaps spending
slightly more cycles, but who cares how fast the TAGS file gets

We however recently added a similar call to "ls-files" to list *.h
files, instead of using "find", in 92b88eba ("Makefile: use `git
ls-files` to list header files, if possible", 2019-03-04).  In this
new use of "ls-files", the resulting list $(LIB_H) is used for,
among other things, generating the header files to run hdr-check
target, and the duplicate unfortunately becomes a true problem.  It
causes $(MAKE) to notice that there are multiple %.hco targets and

Feed the resulting list to "| sort -u" before using it as a list of
files to fix this.


 * I very often have to (1) perform a merge, which conflicts, (2)
   manually resolve new conflicts that are yet unknown to the rerere
   database, (3) before running "git add", run a trial build and
   optionally test, and then (4) commit the result (or just say "git
   rerere" and then "git reset --hard").

   In the step (3), we have (hopefully) good *.h files that are the
   result of conflict resolution in the working tree, over which we
   do want to run header check, but the whole point of running a
   trial build is to validate the result, the resolution is not yet
   registered to the index (or to the rerere database).  These paths
   have multiple stages in the index, and that is when $(MAKE)
   complained to make me notice this buglet.

   I am not fan of adding the "| sort -u" of the whole thing,
   because there is no need to dedup the output of the $(FIND) side
   of the alternative, but "(ls-files | sort -u) || (find)" would
   obviously not work.  If we truly care, perhaps we should add a
   new option to ls-files to show each path only once, unless it is
   showing the stage number (i.e. "ls-files -s" or "ls-files -u"),
   but this gets the problem go away without code change, hence this
   RFC ;-)

diff --git a/Makefile b/Makefile
index 9f1b6e8926..40716c0f81 100644
--- a/Makefile
+++ b/Makefile
@@ -822,12 +822,12 @@ VCSSVN_LIB = vcs-svn/lib.a
 GENERATED_H += command-list.h
-LIB_H := $(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \
+LIB_H := $(shell (git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \
 	$(FIND) . \
 	-name .git -prune -o \
 	-name t -prune -o \
 	-name Documentation -prune -o \
-	-name '*.h' -print)
+	-name '*.h' -print) | sort -u)
 LIB_OBJS += abspath.o
 LIB_OBJS += advice.o
@@ -2588,7 +2588,7 @@ FIND_SOURCE_FILES = ( \
 		-o \( -name 'trash*' -type d -prune \) \
 		-o \( -name '*.[hcS]' -type f -print \) \
 		-o \( -name '*.sh' -type f -print \) \
-	)
+	| sort -u )

             reply	other threads:[~2019-04-21 13:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-21 13:19 Junio C Hamano [this message]
2019-04-22  3:23 ` [PATCH/RFC] Makefile: dedup list of files obtained from ls-files Eric Sunshine
2019-04-22  6:11   ` Junio C Hamano
2019-04-22 14:49 ` Jeff King
2019-04-22 17:15   ` Ramsay Jones
2019-04-23  1:18     ` Junio C Hamano
2019-04-23 20:21   ` SZEDER Gábor
2019-04-24  1:03     ` Junio C Hamano
2019-04-24 11:25       ` SZEDER Gábor
2019-04-24 17:19         ` Eric Sunshine
2019-04-25  0:59           ` Junio C Hamano

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:

  List information:

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

  git send-email \ \ \ \

* 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.
Code repositories for project(s) associated with this public inbox

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 read-only IMAP folder(s) and NNTP newsgroup(s).