From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH] vcs_info docs: applied-string/unapplied-string: Correct an omission in the documentation and add an example.
Date: Wed, 7 Apr 2021 20:22:58 +0000 [thread overview]
Message-ID: <20210407202257.4525-1-danielsh@tarpaulin.shahaf.local2> (raw)
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.)
---
Doc/Zsh/contrib.yo | 13 ++++++++---
Misc/vcs_info-examples | 51 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 586ac06f5..4c7443ffc 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -1652,10 +1652,15 @@ Called in the tt(git) (with tt(stgit) or during rebase or merge), and tt(hg)
is generated; the tt(use-quilt) zstyle must be true for tt(quilt) (the tt(mq)
and tt(stgit) backends are active by default).
-This hook gets the names of all applied patches which tt(vcs_info) collected
-so far in the opposite order, which means that the first argument is the
+The arguments to this hook describe applied patches
+in the opposite order, which means that the first argument is the
top-most patch and so forth.
+When the patches' log messages can be extracted, those are embedded
+within each argument after a space, so each argument is of the form
+`var(patch-name) var(first line of the log message)', where var(patch-name)
+contains no whitespace.
+
When setting tt(ret) to non-zero, the string in
tt(${hook_com[applied-string]}) will be
available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles.
@@ -1669,9 +1674,11 @@ tt(mq)) backend and in tt(quilt) support when the tt(unapplied-string) is
generated; the tt(get-unapplied) style must be true.
This hook gets the names of all unapplied patches which tt(vcs_info)
-collected so far in order, which means that the first argument is
+in order, which means that the first argument is
the patch next-in-line to be applied and so forth.
+The format of each argument is as for tt(gen-applied-string), above.
+
When setting tt(ret) to non-zero, the string in
tt(${hook_com[unapplied-string]}) will be available as tt(%u) in the
tt(patch-format) and tt(nopatch-format) styles.
diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index 94b8a7b5e..36b6fbc51 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -282,6 +282,54 @@ function +vi-hg-branchhead() {
}
+### Show information about patch series
+# This is used with with hg mq, quilt, and git rebases and conflicts.
+#
+# All these cases have a notion of a "series of patches/commits" that is being
+# applied. The following shows the information about the most recent patch to
+# have been applied:
+zstyle ':vcs_info:*+gen-applied-string:*' hooks gen-applied-string
+function +vi-gen-applied-string() {
+ # Separate the patch id from the patch log message.
+ if [[ $1 == *\ * ]]; then
+ local patch_name_or_filename="${1%% *}"
+ local patch_description="${1#* }"
+ else
+ local patch_name_or_filename="$1"
+ local patch_description=""
+ fi
+
+ # Apply escaping; see `Oddities' in the manual.
+ patch_name_or_filename=${patch_name_or_filename//'%'/%%}
+ patch_description=${patch_description//'%'/%%}
+
+ # Apply different colouring to the patch description.
+ if [[ -n ${patch_description} ]]; then
+ patch_description="%F{yellow}${patch_description}%f"
+ fi
+
+ # Re-assemble $1, escaped and coloured.
+ hook_com[applied-string]="${patch_name_or_filename} ${patch_description}"
+ ret=1
+}
+# The value of hook_com[applied-string] is incorporated into the %m expando
+# (see the 'patch-format' style for details), which is not included in the
+# 'formats' and 'actionformats' style by default, so to actually use this,
+# you'll need to add %m (or %Q under quilt in add-on mode) to your 'formats'
+# and 'actionformats' styles, as in:
+#
+# zstyle ':vcs_info:*' actionformats ' (%s)-[%b|%a]%u%c- %m'
+# zstyle ':vcs_info:*' formats ' (%s)-[%b]%u%c- %m'
+#
+# Or you could add it as a new word, as in:
+#
+# zstyle ':vcs_info:*' actionformats ' (%s)-[%b|%a]%u%c-' '%m'
+# zstyle ':vcs_info:*' formats ' (%s)-[%b]%u%c-' '%m'
+#
+# In the latter case, you will need to arrange to print ${vcs_info_msg_1_} in
+# addition to ${vcs_info_msg_0_}; see the top of this file for details.
+
+
### Run vcs_info selectively to increase speed in large repos ################
# The following example shows a possible setup for vcs_info which displays
@@ -544,6 +592,9 @@ function +vi-set-quilt-patches() {
# This would take care of all the dedicated-patches-directory-in-${HOME}
# from earlier examples, too.
+# Finally, the "Show information about patch series" example above this section
+# may also be useful.
+
### Using vcs_info from CVS ##################################################
reply other threads:[~2021-04-07 20:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210407202257.4525-1-danielsh@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=zsh-workers@zsh.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.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).