zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/3] vcs_info quilt: Pass the patches dir path to the gen-applied-string, gen-unapplied-string, and set-patch-format hooks
@ 2022-01-29 16:15 Daniel Shahaf
  2022-01-29 16:15 ` [PATCH 2/3] vcs_info hg mq: Don't include applied patches in the unapplied patches Daniel Shahaf
  2022-01-29 16:15 ` [PATCH 3/3] vcs_info hg mq: Extract patch subjects Daniel Shahaf
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Shahaf @ 2022-01-29 16:15 UTC (permalink / raw)
  To: zsh-workers

I use that in my gen-applied-string hook.
---
This answers my question from workers/49724.

 Doc/Zsh/contrib.yo                                | 12 ++++++++++++
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git |  2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg  |  2 +-
 Functions/VCS_Info/VCS_INFO_quilt                 |  7 ++++++-
 Functions/VCS_Info/VCS_INFO_set-patch-format      |  8 +++++++-
 5 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index eb5bbafb2..2cda891ec 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -1669,6 +1669,10 @@ available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles.
 This hook is, in concert with tt(set-patch-format), responsible for
 tt(%)-escaping that value for use in the prompt.
 (See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).)
+
+The tt(quilt) backend passes to this hook the inputs
+tt(${hook_com[quilt-patches-dir]}) and, if it has been
+determined, tt(${hook_com[quilt-pc-dir]}).
 )
 item(tt(gen-unapplied-string))(
 Called in the tt(git) (with tt(stgit) or during rebase), and tt(hg) (with
@@ -1687,6 +1691,10 @@ tt(patch-format) and tt(nopatch-format) styles.
 This hook is, in concert with tt(set-patch-format), responsible for
 tt(%)-escaping that value for use in the prompt.
 (See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).)
+
+The tt(quilt) backend passes to this hook the inputs
+tt(${hook_com[quilt-patches-dir]}) and, if it has been
+determined, tt(${hook_com[quilt-pc-dir]}).
 )
 item(tt(gen-mqguards-string))(
 Called in the tt(hg) backend when tt(guards-string) is generated; the
@@ -1769,6 +1777,10 @@ This hook is, in concert with the tt(gen-applied-string) or
 tt(gen-unapplied-string) hooks if they are defined, responsible for
 tt(%)-escaping the final tt(patch-format) value for use in the prompt.
 (See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).)
+
+The tt(quilt) backend passes to this hook the inputs
+tt(${hook_com[quilt-patches-dir]}) and, if it has been
+determined, tt(${hook_com[quilt-pc-dir]}).
 )
 item(tt(set-message))(
 Called each time before a `tt(vcs_info_msg_)var(N)tt(_)' message is set.
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index fe084dffb..e45eebc8e 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -132,7 +132,7 @@ VCS_INFO_git_handle_patches () {
     VCS_INFO_set-patch-format 'git_patches_applied' 'git_applied_s' \
                               'git_patches_unapplied' 'git_unapplied_s' \
                               ":vcs_info:${vcs}:${usercontext}:${rrn}" gitmsg \
-                              '' ''
+                              '' '' ''
     gitmisc=$REPLY
 }
 
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index b123e2270..0041a153c 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -225,7 +225,7 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
     VCS_INFO_set-patch-format 'mqpatches' 'applied_string' \
                               'mqunapplied' 'unapplied_string' \
                               ":vcs_info:${vcs}:${usercontext}:${rrn}" hgmqstring \
-                              extra_hook_com VCS_INFO_hg_extra_zformats
+                              extra_hook_com VCS_INFO_hg_extra_zformats ''
     hgmqstring=$REPLY
 fi
 
diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt
index ee242f552..ce5b41f24 100644
--- a/Functions/VCS_Info/VCS_INFO_quilt
+++ b/Functions/VCS_Info/VCS_INFO_quilt
@@ -179,10 +179,15 @@ function VCS_INFO_quilt-patch2subject() {
         done
     }
 
+    typeset -A quilt_extra_info=(
+        quilt-patches-dir ${patches}
+        ${pc:+"quilt-pc-dir"} $pc
+    )
+
     VCS_INFO_set-patch-format 'applied' 'applied_string' \
                               'unapplied' 'unapplied_string' \
                               ${context} qstring \
-                              '' ''
+                              quilt_extra_info '' quilt_extra_info
     qstring=$REPLY
 
     case ${mode} in
diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format
index c35b695c3..1c774a7f6 100644
--- a/Functions/VCS_Info/VCS_INFO_set-patch-format
+++ b/Functions/VCS_Info/VCS_INFO_set-patch-format
@@ -15,6 +15,8 @@
 # $7 - name of an assoc parameter with extra $hook_com key-value pairs for the
 #      set-patch-format hook invocation, or '' for none
 # $8 - name of a function that sets $reply to extra arguments for the patch-format zformat call, or '' for none
+# $9 - name of an assoc parameter with extra $hook_com key-value pairs for the
+#      gen-applied-string & gen-unapplied-string hook invocations, or '' for none
 #
 # The expanded patch-format string is returned in $REPLY.
 #
@@ -22,8 +24,10 @@
 # - $hook_com is overwritten and the keys 'applied', 'applied-n',
 #   'unapplied', 'unapplied-n', 'all-n' are set.
 {
+    hook_com=()
+
     local applied_needs_escaping='unknown'
-    local unapplied_needs_escaping='unknown'
+    hook_com+=( ${9:+"${(@kvP)9}"} )
     if VCS_INFO_hook 'gen-applied-string' "${(@P)1}"; then
         if (( ${(P)#1} )); then
             REPLY=${(P)1[1]}
@@ -37,6 +41,8 @@
     : ${(P)2::=$REPLY}
     hook_com=()
 
+    local unapplied_needs_escaping='unknown'
+    hook_com+=( ${9:+"${(@kvP)9}"} )
     if VCS_INFO_hook 'gen-unapplied-string' "${(@P)3}"; then
         REPLY=${(P)#3}
         unapplied_needs_escaping='yes'


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] vcs_info hg mq: Don't include applied patches in the unapplied patches
  2022-01-29 16:15 [PATCH 1/3] vcs_info quilt: Pass the patches dir path to the gen-applied-string, gen-unapplied-string, and set-patch-format hooks Daniel Shahaf
@ 2022-01-29 16:15 ` Daniel Shahaf
  2022-01-29 16:15 ` [PATCH 3/3] vcs_info hg mq: Extract patch subjects Daniel Shahaf
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2022-01-29 16:15 UTC (permalink / raw)
  To: zsh-workers

For instance, with 4 applied patches, 5 unapplied patches, and no guards
involved, the patch-format style would indicate 9 (= 4+5) unapplied patches
and 4 applied patches.
---
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index 0041a153c..d789d662a 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -183,6 +183,9 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
             # Skip commented lines
             [[ ${i_patch} == [[:space:]]#"#"* ]] && continue
 
+            # Skip applied patches
+            (( ${+mqpatches[(re)${i_patch}]} )) && continue
+
             # Separate negative and positive guards to more easily find the
             # intersection of active guards with patch guards
             i_patchguards=( ${(s: :)i_patchguards} )


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] vcs_info hg mq: Extract patch subjects
  2022-01-29 16:15 [PATCH 1/3] vcs_info quilt: Pass the patches dir path to the gen-applied-string, gen-unapplied-string, and set-patch-format hooks Daniel Shahaf
  2022-01-29 16:15 ` [PATCH 2/3] vcs_info hg mq: Don't include applied patches in the unapplied patches Daniel Shahaf
@ 2022-01-29 16:15 ` Daniel Shahaf
  2022-03-31  6:00   ` Lawrence Velázquez
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2022-01-29 16:15 UTC (permalink / raw)
  To: zsh-workers

Use a NUL separator just in case someone's hg mq patch names include
literal spaces.  That means gen-applied-string hooks have to split their
arguments one way in the hg mq case and another way in every other case.
---
 Doc/Zsh/contrib.yo                            | 18 +++++++++++-----
 .../VCS_Info/Backends/VCS_INFO_get_data_hg    | 21 +++++++++++++++++++
 README                                        |  7 +++++++
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 2cda891ec..c68fe33ef 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -1656,12 +1656,20 @@ 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
+Each argument contains both a patch name and, if possible, the first line of
+that patch's log message or description.  A literal `tt(?)' is substituted
+when the log message or description is empty or unable to be determined.
+
+In the tt(mq) backend, patch names may contain spaces, and each argument
+is of the form `var(patch name)tt($'\0')var(first line of the log message)',
+using a literal NUL as a separator.
+
+In the other backends, each argument is of the form
 `var(patch-name) var(first line of the log message)', where var(patch-name)
-contains no whitespace. The tt(mq) backend passes arguments of
-the form `var(patch name)', with possible embedded spaces, but without
-extracting the patch's log message.
+contains no whitespace.  Typically, one would use
+tt(${argv[1]#* }) and tt(${argv[1]%% *}) to separate the var(patch-name) and
+var(first line of the log message) parts.  (See the file
+tt(Misc/vcs_info-examples) in the source distribution for a complete example.)
 
 When setting tt(ret) to non-zero, the string in
 tt(${hook_com[applied-string]}) will be
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index d789d662a..cfaa3fe5e 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -211,6 +211,27 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
         done < ${mqseriesfile}
     fi
 
+    () {
+        local -a tmp
+        local i
+
+        tmp=()
+        for i in "${mqpatches[@]}" ; do
+            VCS_INFO_patch2subject "${patchdir}/$i"
+            [[ $REPLY == '# HG changeset patch' ]] && unset REPLY
+            tmp+=( "$i"$'\0'"${REPLY="?"}" )
+        done
+        mqpatches=( "${tmp[@]}" )
+
+        tmp=()
+        for i in "${mqunapplied[@]}" ; do
+            VCS_INFO_patch2subject "${patchdir}/$i"
+            [[ $REPLY == '# HG changeset patch' ]] && unset REPLY
+            tmp+=( "$i"$'\0'"${REPLY="?"}" )
+        done
+        mqunapplied=( "${tmp[@]}" )
+    }
+
     if VCS_INFO_hook 'gen-mqguards-string' "${mqguards[@]}"; then
         guards_string=${(j:,:)mqguards}
         # TODO: %-escape extra_zformats[g:...] value
diff --git a/README b/README
index 3ef8afcd1..25a61a4b8 100644
--- a/README
+++ b/README
@@ -102,6 +102,13 @@ consistent with most other sh implementations.
 getopts now calculates OPTIND in a similar manner to other shells when the
 POSIX_BUILTINS option is enabled.
 
+vcs_info hg: Arguments to the gen-applied-string and gen-unapplied-string hooks
+now contain not only the patch's name but also the first line of the patch's
+log message.  The two parts are separated by a NUL byte.
+.
+This only affects you if you have defined custom vcs_info hook functions (see
+the output of 'zstyle -L ":vcs_info:*" hooks' and 'which -m -- "+vi*"' [sic]).
+
 Incompatibilities between 5.7.1 and 5.8
 ---------------------------------------
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/3] vcs_info hg mq: Extract patch subjects
  2022-01-29 16:15 ` [PATCH 3/3] vcs_info hg mq: Extract patch subjects Daniel Shahaf
@ 2022-03-31  6:00   ` Lawrence Velázquez
  2022-04-01  0:21     ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Velázquez @ 2022-03-31  6:00 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

Hi Daniel,

On Sat, Jan 29, 2022, at 11:15 AM, Daniel Shahaf wrote:
> Use a NUL separator just in case someone's hg mq patch names include
> literal spaces.  That means gen-applied-string hooks have to split their
> arguments one way in the hg mq case and another way in every other case.
> ---
>  Doc/Zsh/contrib.yo                            | 18 +++++++++++-----
>  .../VCS_Info/Backends/VCS_INFO_get_data_hg    | 21 +++++++++++++++++++
>  README                                        |  7 +++++++
>  3 files changed, 41 insertions(+), 5 deletions(-)

Were you planning on pushing this?

-- 
vq


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/3] vcs_info hg mq: Extract patch subjects
  2022-03-31  6:00   ` Lawrence Velázquez
@ 2022-04-01  0:21     ` Daniel Shahaf
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2022-04-01  0:21 UTC (permalink / raw)
  To: zsh-workers

Lawrence Velázquez wrote on Thu, Mar 31, 2022 at 02:00:03 -0400:
> Hi Daniel,
> 
> On Sat, Jan 29, 2022, at 11:15 AM, Daniel Shahaf wrote:
> > Use a NUL separator just in case someone's hg mq patch names include
> > literal spaces.  That means gen-applied-string hooks have to split their
> > arguments one way in the hg mq case and another way in every other case.
> > ---
> >  Doc/Zsh/contrib.yo                            | 18 +++++++++++-----
> >  .../VCS_Info/Backends/VCS_INFO_get_data_hg    | 21 +++++++++++++++++++
> >  README                                        |  7 +++++++
> >  3 files changed, 41 insertions(+), 5 deletions(-)
> 
> Were you planning on pushing this?

I'm ambivalent, since it wasn't user-requested and makes the
gen-applied-string API inelegant (as explained in the log message).
Thanks for asking!  It has been on my todo list ever since it was
posted, so it's good to (UK)table it again.

Cheers,

Daniel
(Life goal $((++N)): get C-style casts into the OED)
(Life goal $((++N)): get C++-style casts into the OED)


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-01  0:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-29 16:15 [PATCH 1/3] vcs_info quilt: Pass the patches dir path to the gen-applied-string, gen-unapplied-string, and set-patch-format hooks Daniel Shahaf
2022-01-29 16:15 ` [PATCH 2/3] vcs_info hg mq: Don't include applied patches in the unapplied patches Daniel Shahaf
2022-01-29 16:15 ` [PATCH 3/3] vcs_info hg mq: Extract patch subjects Daniel Shahaf
2022-03-31  6:00   ` Lawrence Velázquez
2022-04-01  0:21     ` Daniel Shahaf

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