Speed up the prompt on large and/or deep working directories by
stopping grep(1) as soon as it finds a single match, with `-q`.
Also, correct the regexp by adding a ^ anchor and increase its
specificity by accounting for the space in Porcelain Format v1.
Previously, +vi-git-untracked() waited for grep(1) to find all
matches of untracked files, redirecting them away to /dev/null,
before finally concluding that untracked files do indeed exist.
With this patch, I see 4x speedup on a large Git-enabled $HOME:
$ time (git status --porcelain | wc -l)
212
0.01s user 0.02s system 0% cpu 9.021 total
$ time (git status --porcelain | grep '??' &>/dev/null)
0.01s user 0.02s system 0% cpu 12.294 total
$ time (git status --porcelain | grep -q '^?? ' 2>/dev/null)
0.01s user 0.01s system 0% cpu 3.097 total
Note that `-q` for grep(1) is in POSIX (IEEE Std 1003.1-2017):
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
See discussion https://www.zsh.org/mla/workers/2021/msg01354.html
The example code is a reduced version of my function from workers/47519,
with one bug fixed. (In workers/47519, if $1 doesn't contain spaces -
which is the case under hg mq - then $H and $s will be set to the same
value.)
Tweaked: Extended the contrib.yo hunk with details about mq.
- Document that no code at all is necessary for Pareto correctness
- Remove a recommendation to rely on implementation details (${rrn});
instead, rely only on ${context}, which is a documented API.
Here's a diff-stat:
Doc/Zsh/contrib.yo | 506 ++++++++++++++-------
Functions/VCS_Info/.distfiles | 1 +
Functions/VCS_Info/Backends/VCS_INFO_detect_hg | 14 +-
Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 35 +-
Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 295 +++++++++----
Functions/VCS_Info/VCS_INFO_formats | 26 +-
Functions/VCS_Info/VCS_INFO_hook | 10 +-
Functions/VCS_Info/VCS_INFO_quilt | 190 ++++++++
Functions/VCS_Info/vcs_info | 30 +-
Misc/.distfiles | 1 +
Misc/vcs_info-examples | 496 ++++++++++++++++++++
11 files changed, 1303 insertions(+), 301 deletions(-)
The major changes are vast improvements for the mercurial (hg) backend
(which was done almost entirely by Seth); improved documentation (mostly
done by Simon and again Seth); quilt support (as an addon and stand
alone, see the manual for details); a number of new hooks and a fair
share of bugfixes.