unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Glenn Morris <rgm@gnu.org>
Cc: 36110@debbugs.gnu.org
Subject: bug#36110: find-dired not sorted on any field nor provides a way
Date: Fri, 14 Jun 2019 22:09:10 +0300	[thread overview]
Message-ID: <878su40ysp.fsf@mail.linkov.net> (raw)
In-Reply-To: <lyd0jh6n4x.fsf@fencepost.gnu.org> (Glenn Morris's message of "Thu, 13 Jun 2019 20:12:14 -0400")

[-- Attachment #1: Type: text/plain, Size: 2295 bytes --]

>>> +@code{'("-exec ls -ld @{@} +" . "-ld")}
>>
>> Oh, I see you've changed it to the "+" form.

I've changed it to the same value as in `find-exec-terminator'.
So instead of documenting a command with a terminator that depends
on the value of `find-exec-terminator', better would be to provide
different customizable options like in the patch below.

>> It looks like this does give sorted output, but I find it surprising.
>> Is it assured?
>
> I verified on a directory with a large number of files that the output
> is not sorted. (I didn't see how it could be, given how find works.)
> But it does appear as if individual "chunks" are sorted, which can give
> the appearance of the whole output being sorted if you don't have a lot
> of files.

I tried to run different commands on all files in the Emacs source tree:

1. find . -ls

It produces completely unsorted output.

2. find . -exec ls -ld {} +

It splits the output into sizeable chunks and sorts files
inside every chunk, so the boundary between chunks
is clearly visible, e.g.:

-rw-rw-r--  1 juri juri     6191 May  1 23:49 ./test/src/timefns-tests.el
-rw-r--r--  1 juri juri    13623 Jan  2 22:43 ./test/src/undo-tests.el
-rw-r--r--  1 juri juri     2915 Jan  2 22:43 ./test/src/xml-tests.el
drwxr-xr-x   2 juri juri      4096 Jun 11 00:09 ./autom4te.cache
-rw-rw-r--   1 juri juri    945417 Jun 11 00:09 ./autom4te.cache/output.0
-rw-r--r--   1 juri juri      3431 Jun 11 00:09 ./autom4te.cache/requests

3. find . -print0 | sort -z | xargs -0 -e ls -ld

It splits files into chinks, but maintains the sorting order
among all files.   Its only drawback is misaligned chunks, e.g.:

-rw-rw-r--   1 juri juri     62707 May 21 00:04 ./info/forms.info
-rw-rw-r--   1 juri juri   1476691 Jun 11 00:16 ./info/gnus.info
-rw-rw-r--   1 juri juri     74148 May 21 00:04 ./info/htmlfontify.info
-rw-rw-r--  1 juri juri   234730 May 21 00:04 ./info/idlwave.info
-rw-rw-r--  1 juri juri    51892 May 21 00:04 ./info/ido.info
-rw-rw-r--  1 juri juri    84948 May 21 00:04 ./info/info.info

Since an output with more than 5000 files (an approx amount in each chuck
in this experiment) is unmanageable by human users, any of the last 2 options
is sufficiently good.  So here is the patch that allows the user
to choose among these options:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: find-ls-option-default.patch --]
[-- Type: text/x-diff, Size: 2290 bytes --]

diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index 2c76179da0..c563ae533a 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -51,19 +51,23 @@ find-exec-terminator
   :group 'find-dired
   :type 'string)
 
+(defvar find-ls-option-default-ls
+  (cons "-ls" (if (eq system-type 'berkeley-unix) "-gilsb" "-dilsb")))
+
+(defvar find-ls-option-default-exec
+  (cons (format "-exec ls -ld {} %s" find-exec-terminator) "-ld"))
+
+(defvar find-ls-option-default-xargs
+  (cons "-print0 | sort -z | xargs -0 -e ls -ld" "-ld"))
+
 ;; find's -ls corresponds to these switches.
 ;; Note -b, at least GNU find quotes spaces etc. in filenames
 (defcustom find-ls-option
   (if (eq 0
 	  (ignore-errors
 	    (process-file find-program nil nil nil null-device "-ls")))
-      (cons "-ls"
-	    (if (eq system-type 'berkeley-unix)
-		"-gilsb"
-	      "-dilsb"))
-    (cons
-     (format "-exec ls -ld {} %s" find-exec-terminator)
-     "-ld"))
+      find-ls-option-default-ls
+    find-ls-option-default-exec)
   "A pair of options to produce and parse an `ls -l'-type list from `find'.
 This is a cons of two strings (FIND-OPTION . LS-SWITCHES).
 FIND-OPTION is the option (or options) passed to `find' to produce
@@ -78,9 +82,20 @@ find-ls-option
    (\"-ls\" . \"-dilsb\")
 since GNU find's output has the same format as using GNU ls with
 the options \"-dilsb\"."
-  :version "24.1"	       ; add tests for -ls and -exec + support
-  :type '(cons (string :tag "Find Option")
-	       (string :tag "Ls Switches"))
+  :version "27.1"            ; add choice of predefined set of options
+  :type `(choice
+          (cons :tag "find -ls"
+                (string ,(car find-ls-option-default-ls))
+                (string ,(cdr find-ls-option-default-ls)))
+          (cons :tag "find -exec ls -ld"
+                (string ,(car find-ls-option-default-exec))
+                (string ,(cdr find-ls-option-default-exec)))
+          (cons :tag "find -print | sort | xargs"
+                (string ,(car find-ls-option-default-xargs))
+                (string ,(cdr find-ls-option-default-xargs)))
+          (cons :tag "Other values"
+                (string :tag "Find Option")
+                (string :tag "Ls Switches")))
   :group 'find-dired)
 
 (defcustom find-ls-subdir-switches

  parent reply	other threads:[~2019-06-14 19:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05 23:27 bug#36110: find-dired not sorted on any field nor provides a way 積丹尼 Dan Jacobson
2019-06-06 20:28 ` Juri Linkov
2019-06-06 21:21   ` Drew Adams
2019-06-07  0:25     ` 積丹尼 Dan Jacobson
2019-06-13 21:30       ` Juri Linkov
2019-06-13 23:40         ` Glenn Morris
2019-06-14  0:12           ` Glenn Morris
2019-06-14  6:26             ` Andreas Schwab
2019-06-14 19:09             ` Juri Linkov [this message]
2019-06-14 19:10             ` Juri Linkov
2019-06-14  6:18           ` Eli Zaretskii
2019-06-14 19:12             ` Juri Linkov
2019-06-14  6:06         ` Eli Zaretskii
2019-06-15 22:36           ` Juri Linkov
2019-06-16  2:39             ` Eli Zaretskii
2019-06-16  8:37               ` Andreas Schwab
2019-06-16 14:02                 ` Eli Zaretskii

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=878su40ysp.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=36110@debbugs.gnu.org \
    --cc=rgm@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

	https://git.savannah.gnu.org/cgit/emacs.git

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).