* [WIP PATCH] vcs_info svn support for 'svnversion'
@ 2019-12-01 0:52 Daniel Shahaf
2019-12-10 5:17 ` Daniel Shahaf
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2019-12-01 0:52 UTC (permalink / raw)
To: zsh-users
I hacked up 'svnversion' support into vcs_info, to enable vcs_info to indicate
non-uniform revisions and local mods in Subversion working copies.
As it stands, I feel it's too hacky — see log message for details — so I don't
intend to commit it as-is. However, I'm posting it here in case it's useful to
anyone.
Cheers,
Daniel
[[[
From: Daniel Shahaf <danielsh@apache.org>
Subject: [PATCH]
WIP: vcs_info svn: Use svnversion to show uniform revisions and local mods
The 'staged' expando, %c, will now be set if there's an 'M' in the output of `svnversion`.
The 'revision number' expando, %i, will now show the full output of svnversion.
svnversion will only be used if the check-for-changes and get-revision styles are both set.
TODO: derive the svnversion command name robustly
TODO: write docs
---
Doc/Zsh/contrib.yo | 2 ++
Functions/VCS_Info/Backends/VCS_INFO_get_data_svn | 21 +++++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index d32ba018d..a20bf0c19 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -1095,6 +1095,7 @@ is used as the command name.
)
kindex(check-for-changes)
item(tt(check-for-changes))(
+TODO(svn)
If enabled, this style causes the tt(%c) and tt(%u) format escapes to show
when the working directory has uncommitted changes. The strings displayed by
these escapes can be controlled via the tt(stagedstr) and tt(unstagedstr)
@@ -1183,6 +1184,7 @@ method will not return the local revision number.
)
kindex(get-revision)
item(tt(get-revision))(
+TODO(svn)
If set to true, vcs_info goes the extra mile to figure out the revision of
a repository's work tree (currently for the tt(git) and tt(hg) backends,
where this kind of information is not always vital). For tt(git), the
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index c1547950f..dd5ce1b0f 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -6,6 +6,7 @@
setopt localoptions noksharrays extendedglob NO_shwordsplit
local svnbase svnbranch a b rrn
+local non_uniform_revision modified
local -i rc
local -A svninfo parentinfo cwdinfo
local -A hook_com
@@ -60,11 +61,27 @@ svnbase=${svnbase:P}
rrn=${svnbase:t}
zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r"
hook_com=( branch "${svninfo[URL]##*/}" revision "${cwdinfo[Revision]}" )
+if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" &&
+ zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "get-revision" ; then
+ local svnversion_cmd
+ if [[ $vcs_comm[cmd] == */* ]]; then
+ svnversion_cmd=${vcs_comm[cmd]:h}/${${vcs_comm[cmd]:t}/svn/svnversion}
+ else
+ svnversion_cmd=${vcs_comm[cmd]/svn/svnversion}
+ fi
+ hook_com[svnversion]=$($svnversion_cmd 2>/dev/null)
+ if [[ ${hook_com[svnversion]} == *M* ]]; then
+ modified=${hook_com[svnversion]}
+ fi
+ if [[ ${hook_com[svnversion]} == *:* ]]; then
+ non_uniform_revision=${hook_com[svnversion]}
+ fi
+fi
if VCS_INFO_hook 'set-branch-format' "${svnbranch}"; then
- zformat -f svnbranch "${svnbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
+ zformat -f svnbranch "${svnbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}" "v:${hook_com[svnversion]}"
else
svnbranch=${hook_com[branch-replace]}
fi
hook_com=()
-VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' '' "${cwdinfo[Revision]}" ''
+VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' "$modified" "${non_uniform_revision:-${cwdinfo[Revision]}}" ''
return 0
]]]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [WIP PATCH] vcs_info svn support for 'svnversion'
2019-12-01 0:52 [WIP PATCH] vcs_info svn support for 'svnversion' Daniel Shahaf
@ 2019-12-10 5:17 ` Daniel Shahaf
2019-12-10 5:55 ` Daniel Shahaf
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2019-12-10 5:17 UTC (permalink / raw)
To: zsh-users
Daniel Shahaf wrote on Sun, Dec 01, 2019 at 00:52:17 +0000:
> [[[
> From: Daniel Shahaf <danielsh@apache.org>
> Subject: [PATCH]
> WIP: vcs_info svn: Use svnversion to show uniform revisions and local mods
>
> The 'staged' expando, %c, will now be set if there's an 'M' in the output of `svnversion`.
>
> The 'revision number' expando, %i, will now show the full output of svnversion.
>
> svnversion will only be used if the check-for-changes and get-revision styles are both set.
>
> TODO: derive the svnversion command name robustly
> TODO: write docs
Here's another version. Differences:
- It's not a patch now, but configuration to be added to zshrc.
- It uses only public APIs, but takes advantage of an implementation detail to
avoid svnversion doing a (potentially expensive) tree crawl. The trade-off is
that it's not read-only any more.
[[[
zstyle -e ':vcs_info:svn+post-backend:*' hooks 'reply=( ${${(k)functions[(I)[+]vi-svn-post-backend*]}#+vi-} )'
## svn: indicate mixed-revision working copies in the %i (revision) expando
zstyle -e ':vcs_info:svn:*:*' "zshrc:make-temporary-changes" '[[ $PWD == ~/* ]] && reply=(true)'
+vi-svn-post-backend-mixed-revision() {
local non_uniform_revision modified
if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" ; then
local output="$(svnversion 2>/dev/null)"
if [[ ${output} == *M* ]]; then
hook_com[unstaged]='yes' # value is ignored
fi
if [[ ${output} == *:* ]]; then
non_uniform_revision=${output}
fi
elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "zshrc:make-temporary-changes" \
&& [[ -w ${hook_com[base_orig]}/.svn/wc.db ]]; then
{
# Make a dummy propmod to prevent svnversion(1) from doing a worktree stat() crawl.
#
# This relies on an implementation detail of svn_wc_revision_status2():
# It will not do a tree crawl if it detected a propery mod (or a tree mod).
${vcs_comm[cmd]} propset --quiet vcs_info:dummy yes -- ${hook_com[base_orig]}
local output="${$(svnversion 2>/dev/null)/M/}" # remove 'M' caused by the dummy propmod
if [[ ${output} == *:* ]]; then
non_uniform_revision=${output}
fi
} always {
${vcs_comm[cmd]} propdel --quiet vcs_info:dummy -- ${hook_com[base_orig]}
}
fi
if [[ $non_uniform_revision == *:* ]]; then
integer min=${non_uniform_revision%%:*} max=${${non_uniform_revision#*:}%%[^0-9]*}
hook_com[revision]="r${min}:r${max}${non_uniform_revision//[0-9:]##}"
hook_com[revision]+=" (+$((max-min)))"
fi
return 0
}
]]]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [WIP PATCH] vcs_info svn support for 'svnversion'
2019-12-10 5:17 ` Daniel Shahaf
@ 2019-12-10 5:55 ` Daniel Shahaf
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2019-12-10 5:55 UTC (permalink / raw)
To: zsh-users
Sorry for the double post but I found a minor bug just after sending.
Daniel Shahaf wrote on Tue, Dec 10, 2019 at 05:17:34 +0000:
> if [[ ${output} == *:* ]]; then
Change «*:*» to «*[^0-9]*».
> if [[ $non_uniform_revision == *:* ]]; then
> integer min=${non_uniform_revision%%:*} max=${${non_uniform_revision#*:}%%[^0-9]*}
> hook_com[revision]="r${min}:r${max}${non_uniform_revision//[0-9:]##}"
> hook_com[revision]+=" (+$((max-min)))"
Add:
else
hook_com[revision]+="${non_uniform_revision//[0-9]##}"
> fi
>
> return 0
> }
(The bug was that the 'S' and 'P' indication wouldn't show on uniform-revision
wc's, but only on mixed-revision ones.)
Cheers,
Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-10 5:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-01 0:52 [WIP PATCH] vcs_info svn support for 'svnversion' Daniel Shahaf
2019-12-10 5:17 ` Daniel Shahaf
2019-12-10 5:55 ` 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).