zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: (0/2) Dropped mercurial related patches for vcs_info
@ 2009-06-19 14:36 Frank Terbeck
  2009-06-19 14:36 ` PATCH: (1/2) Add information about hg's local revision number and the commit's hash Frank Terbeck
  2009-06-19 14:36 ` PATCH: (2/2) Make the hg backend work with new versions of mercurial Frank Terbeck
  0 siblings, 2 replies; 3+ messages in thread
From: Frank Terbeck @ 2009-06-19 14:36 UTC (permalink / raw)
  To: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 708 bytes --]

It seems like the mercurial related patches from zsh-workers 26819¹
and 26820² have been dropped, although the Changelog claims they were
applied.

So, I'll resubmit them as replies to this message.

¹ http://www.zsh.org/mla/workers/2009/msg00605.html
² http://www.zsh.org/mla/workers/2009/msg00606.html

Frank Terbeck (2):
  Add information about hg's local revision number and the commit's hash
  Make the hg backend work with new versions of mercurial

 Functions/VCS_Info/Backends/VCS_INFO_detect_hg   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg |   39 ++++++++++++++++++++--
 Functions/VCS_Info/VCS_INFO_bydir_detect         |    2 +-
 3 files changed, 38 insertions(+), 5 deletions(-)


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

* PATCH: (1/2) Add information about hg's local revision number and the commit's hash
  2009-06-19 14:36 PATCH: (0/2) Dropped mercurial related patches for vcs_info Frank Terbeck
@ 2009-06-19 14:36 ` Frank Terbeck
  2009-06-19 14:36 ` PATCH: (2/2) Make the hg backend work with new versions of mercurial Frank Terbeck
  1 sibling, 0 replies; 3+ messages in thread
From: Frank Terbeck @ 2009-06-19 14:36 UTC (permalink / raw)
  To: zsh-workers

The local revision number is in %i and branchformat's %r (yes, the hg
backend has a branchformat now, but only if get-revision is set).

The commit's hash is in %m - the "misc" parameter to VCS_INFO_formats().

Example:
[snip]
autoload -Uz vcs_info; vcs_info

zstyle ':vcs_info:*'    max-exports   2
zstyle ':vcs_info:*'    formats       '(%s)-[%b]-'    '%m'
zstyle ':vcs_info:*'    actionformats '(%s)-[%b|%a]-' '%m'
zstyle ':vcs_info:hg:*' get-revision  true

function precmd() {
    psvar=()
    vcs_info
    [[ -n "${vcs_info_msg_0_}" ]] && psvar[1]="${vcs_info_msg_0_}"
    [[ -n "${vcs_info_msg_1_}" ]] && psvar[2]="${vcs_info_msg_1_}"
}

PS1='%~%(1v. %1v.)%# '
RPS1='%(2v.[%2v].)'
[snap]
---
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg |   33 ++++++++++++++++++++--
 1 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index d70e03c..f8e21a9 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -3,10 +3,37 @@
 ## Distributed under the same BSD-ish license as zsh itself.
 
 setopt localoptions NO_shwordsplit
-local hgbranch hgbase
+local hgbranch hgbranch_name hgbase hghash hglrev r_branch r_info
 
 hgbase=${vcs_comm[basedir]}
 rrn=${hgbase:t}
-hgbranch=$(< ${hgbase}/.hg/branch)
-VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' '' '' ''
+hgbranch_name=$(< ${hgbase}/.hg/branch)
+
+hghash=''
+hglrev=''
+if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
+    # Calling the 'hg' program is quite a bit too slow for prompts.
+    # If there's a way around that, I'd be interested.
+    # Disabled by default anyway, so no harm done.
+
+    HGRCPATH="/dev/null" ${vcs_comm[cmd]} branches \
+    | while read -r r_branch r_info ; do
+        if [[ ${r_branch} == ${hgbranch_name} ]] ; then
+            match=()
+            : ${r_info/(#b)([^:]##):(*)}
+            hglrev=${match[1]}
+            hghash=${match[2]}
+            break
+        fi
+    done
+
+    if [[ -n ${hglrev} ]] ; then
+        zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat hgbranch || hgbranch="%b:%r"
+        zformat -f hgbranch "${hgbranch}" "b:${hgbranch_name}" "r:${hglrev}"
+    fi
+else
+    hgbranch="${hgbranch_name}"
+fi
+
+VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' '' "${hglrev}" "${hghash}"
 return 0
-- 
1.6.3.1.169.g33fd


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

* PATCH: (2/2) Make the hg backend work with new versions of mercurial
  2009-06-19 14:36 PATCH: (0/2) Dropped mercurial related patches for vcs_info Frank Terbeck
  2009-06-19 14:36 ` PATCH: (1/2) Add information about hg's local revision number and the commit's hash Frank Terbeck
@ 2009-06-19 14:36 ` Frank Terbeck
  1 sibling, 0 replies; 3+ messages in thread
From: Frank Terbeck @ 2009-06-19 14:36 UTC (permalink / raw)
  To: zsh-workers

VCS_INFO_bydir_detect() now accepts every kind of file in
${vcs_comm[detect_need_file]} not just plain files.

The hg backend uses that by detecting via (paraphrased):
[[ -d .hg ]] && [[ -e .hg/store ]]
where .hg/store is a directory.

If .hg/branch is missing, the branch name defaults to 'default'.
---
 Functions/VCS_Info/Backends/VCS_INFO_detect_hg   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg |   10 ++++++++--
 Functions/VCS_Info/VCS_INFO_bydir_detect         |    2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_hg b/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
index 41fcc4b..36078b7 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
@@ -7,6 +7,6 @@ setopt localoptions NO_shwordsplit
 [[ $1 == '--flavours' ]] && return 1
 
 VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
-vcs_comm[detect_need_file]=branch
+vcs_comm[detect_need_file]=store
 VCS_INFO_bydir_detect '.hg'
 return $?
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index f8e21a9..d83521b 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -3,11 +3,17 @@
 ## Distributed under the same BSD-ish license as zsh itself.
 
 setopt localoptions NO_shwordsplit
-local hgbranch hgbranch_name hgbase hghash hglrev r_branch r_info
+local file hgbranch hgbranch_name hgbase hghash hglrev r_branch r_info
 
 hgbase=${vcs_comm[basedir]}
 rrn=${hgbase:t}
-hgbranch_name=$(< ${hgbase}/.hg/branch)
+
+file="${hgbase}/.hg/branch"
+if [[ -r ${file} ]] ; then
+    hgbranch_name=$(< ${file})
+else
+    hgbranch_name="default"
+fi
 
 hghash=''
 hglrev=''
diff --git a/Functions/VCS_Info/VCS_INFO_bydir_detect b/Functions/VCS_Info/VCS_INFO_bydir_detect
index aff59f3..7985b69 100644
--- a/Functions/VCS_Info/VCS_INFO_bydir_detect
+++ b/Functions/VCS_Info/VCS_INFO_bydir_detect
@@ -10,7 +10,7 @@ realbasedir="$(VCS_INFO_realpath ${basedir})"
 while [[ ${realbasedir} != '/' ]]; do
     if [[ -n ${vcs_comm[detect_need_file]} ]] ; then
         [[ -d ${basedir}/${dirname} ]] && \
-        [[ -f ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
+        [[ -e ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
             break
     else
         [[ -d ${basedir}/${dirname} ]] && break
-- 
1.6.3.1.169.g33fd


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

end of thread, other threads:[~2009-06-19 14:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-19 14:36 PATCH: (0/2) Dropped mercurial related patches for vcs_info Frank Terbeck
2009-06-19 14:36 ` PATCH: (1/2) Add information about hg's local revision number and the commit's hash Frank Terbeck
2009-06-19 14:36 ` PATCH: (2/2) Make the hg backend work with new versions of mercurial Frank Terbeck

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