findutils-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] find: doc: Fix -prune SCM example directories and make it more e


From: raf
Subject: [PATCH] find: doc: Fix -prune SCM example directories and make it more efficient
Date: Sat, 19 Nov 2022 09:48:28 +1100

* find/find.1 - Fix -prune SCM example directories and make it more efficient
* doc/find.texi - Make -prune SCM example more efficient (two ways)
* NEWS - Mention the above
---
 NEWS          |  3 +++
 doc/find.texi | 25 +++++++++++++++++++++----
 find/find.1   | 13 ++++++++++++-
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 1fff34f8..7c6fcfb3 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,9 @@ GNU findutils NEWS - User visible changes.      -*- outline 
-*- (allout)
   When generating the Texinfo manual, `makeinfo` is invoked with the --no-split
   option for all output formats now; this avoids files like find.info-[12].
 
+  The find.1 manual's -prune SCM example directories/output have been fixed, 
and
+  the example itself has been made more efficient (find.1 and find.texi) 
[#62259]
+  Also fixed a typo in find.texi.
 
 * Noteworthy changes in release 4.9.0 (2022-02-22) [stable]
 
diff --git a/doc/find.texi b/doc/find.texi
index 379fe646..1a36e243 100644
--- a/doc/find.texi
+++ b/doc/find.texi
@@ -5138,13 +5138,15 @@ already found.
 
 @smallexample
 find repo/ \
--exec test -d @{@}/.svn \; -or \
--exec test -d @{@}/.git \; -or \
--exec test -d @{@}/CVS \; -print -prune
+-type d \
+\( -exec test -d @{@}/.svn \; \
+-or -exec test -d @{@}/.git \; \
+-or -exec test -d @{@}/CVS \; \
+\) -print -prune
 @end smallexample
 
 In this example, @command{test} is used to tell if we are currently
-examining a directory which appears to the a project's root directory
+examining a directory which appears to be a project's root directory
 (because it has an SCM subdirectory).  When we find a project root,
 there is no need to search inside it, and @code{-prune} makes sure
 that we descend no further.
@@ -5153,6 +5155,21 @@ For large, complex trees like the Linux kernel, this 
will prevent
 searching a large portion of the structure, saving a good deal of
 time.
 
+The @samp{-type d} clause causes the three @samp{test} shell
+processes to only be executed for directories. This can be made even
+more efficient by combining the three @samp{test} shell processes
+into a single process:
+
+@smallexample
+find repo/ \
+-type d \
+-exec sh -c 'test -d "$1"/.svn || test -d "$1"/.git || test -d "$1"/CVS' . {} 
\; \
+-print -prune
+@end smallexample
+
+Note that the @samp{.} argument is just a placeholder for the unused
+@samp{$0} environment variable in the @samp{sh -c} command. The
+@samp{@{@}} argument is the @samp{$1} environment variable.
 
 @node Security Considerations
 @chapter Security Considerations
diff --git a/find/find.1 b/find/find.1
index 429aa2f0..4faaa23b 100644
--- a/find/find.1
+++ b/find/find.1
@@ -2494,6 +2494,7 @@ projects' roots:
 .in +4m
 .B $ find repo/ \e
 .in +4m
+.B \-type d \e
 .B \e( \-exec test \-d \(aq{}/.svn\(aq \e; \e
 .B \-or \-exec test \-d \(aq{}/.git\(aq \e; \e
 .B \-or \-exec test \-d \(aq{}/CVS\(aq \e; \e
@@ -2502,7 +2503,7 @@ projects' roots:
 .in -4m
 \&
 .fi
-Sample output:
+Sample directories:
 .nf
 \&
 .in +4m
@@ -2513,6 +2514,16 @@ Sample output:
 .B repo/project4/.git
 .in
 \&
+Sample output:
+.nf
+\&
+.in +4m
+.B repo/project1
+.B repo/gnu/project2
+.B repo/gnu/project3
+.B repo/project4
+.in
+\&
 .fi
 In this example,
 .B \-prune
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]