>From 03e5a2238baf8c38028e49bfe1ed9b63cfa36f18 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 4 Jun 2014 15:48:53 +0000 Subject: [PATCH 1/2] (Y) glob modifier defaults to no sorting --- Doc/Zsh/expn.yo | 7 ++++++- Src/glob.c | 2 +- Test/D02glob.ztst | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 2f91fec..ff9f2b1 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -2568,10 +2568,12 @@ item(tt(Y)var(n))( enables short-circuit mode: the pattern will expand to at most var(n) filenames. If more than var(n) matches exist, only the first var(n) matches in directory traversal order will be considered. + +Implies tt(oN) when no tt(o)var(c) qualifier is used. ) item(tt(o)var(c))( specifies how the names of the files should be sorted. If var(c) is -tt(n) they are sorted by name (the default); if it is tt(L) they +tt(n) they are sorted by name; if it is tt(L) they are sorted depending on the size (length) of the files; if tt(l) they are sorted by the number of links; if tt(a), tt(m), or tt(c) they are sorted by the time of the last access, modification, or @@ -2586,6 +2588,9 @@ so `tt(*(^-oL))' gives a list of all files sorted by file size in descending order, following any symbolic links. Unless tt(oN) is used, multiple order specifiers may occur to resolve ties. +The default sorting is tt(n) (by name) unless the tt(Y) glob qualifier is used, +in which case it is tt(N) (unsorted). + tt(oe) and tt(o+) are special cases; they are each followed by shell code, delimited as for the tt(e) glob qualifier and the tt(+) glob qualifier respectively (see above). The code is executed for each matched file with diff --git a/Src/glob.c b/Src/glob.c index c74a560..a62cfee 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -1779,7 +1779,7 @@ zglob(LinkList list, LinkNode np, int nountok) return; } if (!gf_nsorts) { - gf_sortlist[0].tp = gf_sorts = GS_NAME; + gf_sortlist[0].tp = gf_sorts = (shortcircuit ? GS_NONE : GS_NAME); gf_nsorts = 1; } /* Initialise receptacle for matched files, * diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst index c00bbe3..358c934 100644 --- a/Test/D02glob.ztst +++ b/Test/D02glob.ztst @@ -546,7 +546,7 @@ (){ print $#@ } glob.tmp/dir*(Y1) (){ print $#@ } glob.tmp/file*(NY1) (){ [[ "$*" == */dir?\ */dir? ]] && print Returns matching filenames } glob.tmp/dir*(Y2) - (){ print "Limit is upper bound:" $@:t } glob.tmp/dir*(Y5) + (){ print "Limit is upper bound:" ${(o)@:t} } glob.tmp/dir*(Y5) (){ print "Negated:" $@:t } glob.tmp/dir*(Y1^Y) (){ print "Sorting:" $@:t } glob.tmp/dir*(Y4On) (){ [[ $#@ -eq 1 ]] && print Globs before last path component } glob.tmp/dir?/subdir(NY1) -- 1.7.10.4