zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: (0/5) Updates for vcs_info
@ 2009-04-06 17:45 Frank Terbeck
  2009-04-06 17:45 ` PATCH: (1/5) vcs_info: add revision and "misc" argument to VCS_INFO_formats() Frank Terbeck
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Frank Terbeck @ 2009-04-06 17:45 UTC (permalink / raw)
  To: zsh-workers

This series adds features to the hg and git backends of vcs_info.
It also fixes a bug in the hg backend in connection with very recent
mercurial versions.

There are no changes in the default behaviour of any backend.


Frank Terbeck (5):
  vcs_info: add revision and "misc" argument to VCS_INFO_formats()
  Add git's sha1 hash as revision information
  Add information about hg's local revision number and the commit's hash
  contrib.yo: updates for get-revision, %i and %m

    The four patches above add features to the git and hg backends,
    including documentation.

  Make the hg backend work with new versions of mercurial

    This one fixes a problem with detecting hg freshly created hg
    repositories with very recent mercurial versions, which don't
    seem to create .hg/branch if there's only the 'default' branch.
    Reported by Andreas Korsten.

 Doc/Zsh/contrib.yo                                 |   17 +++++++++
 Functions/VCS_Info/Backends/VCS_INFO_detect_hg     |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_cdv  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs  |    2 +-
 .../VCS_Info/Backends/VCS_INFO_get_data_darcs      |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git  |   17 +++++++--
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg   |   39 ++++++++++++++++++--
 Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_p4   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_svk  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_svn  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_tla  |    2 +-
 Functions/VCS_Info/VCS_INFO_bydir_detect           |    2 +-
 Functions/VCS_Info/VCS_INFO_formats                |   21 ++++++++++-
 15 files changed, 97 insertions(+), 19 deletions(-)


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

* PATCH: (1/5) vcs_info: add revision and "misc" argument to VCS_INFO_formats()
  2009-04-06 17:45 PATCH: (0/5) Updates for vcs_info Frank Terbeck
@ 2009-04-06 17:45 ` Frank Terbeck
  2009-04-06 17:45 ` PATCH: (2/5) Add git's sha1 hash as revision information Frank Terbeck
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2009-04-06 17:45 UTC (permalink / raw)
  To: zsh-workers

There is no reason why the revision should only be available in
branchformat. This way it's in formats and actionformats, too.
As %i (think: identifier) as %r and %R where both taken already.

This also adds a "misc" parameter that currently nobody uses. But I'm
planning to make the hg backend use it.
---
 Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_cdv  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs  |    2 +-
 .../VCS_Info/Backends/VCS_INFO_get_data_darcs      |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_p4   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_svk  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_svn  |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_tla  |    2 +-
 Functions/VCS_Info/VCS_INFO_formats                |   21 +++++++++++++++++++-
 12 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
index 1030c06..e85de31 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
@@ -22,5 +22,5 @@ fi
 rrn=${bzrbase:t}
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat bzrbr || bzrbr="%b:%r"
 zformat -f bzrbr "${bzrbr}" "b:${bzrinfo[2]}" "r:${bzrinfo[1]}"
-VCS_INFO_formats '' "${bzrbr}" "${bzrbase}" '' ''
+VCS_INFO_formats '' "${bzrbr}" "${bzrbase}" '' '' "${bzrinfo[1]}" ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cdv b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cdv
index 2c516ea..4f81184 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cdv
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cdv
@@ -7,5 +7,5 @@ local cdvbase
 
 cdvbase=${vcs_comm[basedir]}
 rrn=${cdvbase:t}
-VCS_INFO_formats '' "${cdvbase:t}" "${cdvbase}" '' ''
+VCS_INFO_formats '' "${cdvbase:t}" "${cdvbase}" '' '' '' ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs
index 1c222ce..ed738b9 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs
@@ -14,5 +14,5 @@ cvsbranch=$(< ./CVS/Repository)
 rrn=${cvsbase:t}
 cvsbranch=${cvsbranch##${rrn}/}
 [[ -z ${cvsbranch} ]] && cvsbranch=${rrn}
-VCS_INFO_formats '' "${cvsbranch}" "${cvsbase}" '' ''
+VCS_INFO_formats '' "${cvsbranch}" "${cvsbase}" '' '' '' ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_darcs b/Functions/VCS_Info/Backends/VCS_INFO_get_data_darcs
index a1ebbb6..3f6a226 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_darcs
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_darcs
@@ -7,5 +7,5 @@ local darcsbase
 
 darcsbase=${vcs_comm[basedir]}
 rrn=${darcsbase:t}
-VCS_INFO_formats '' "${darcsbase:t}" "${darcsbase}" '' ''
+VCS_INFO_formats '' "${darcsbase:t}" "${darcsbase}" '' '' '' ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 75d39cc..745be34 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -108,5 +108,5 @@ VCS_INFO_adjust
 gitaction="$(VCS_INFO_git_getaction ${gitdir})"
 gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
 rrn=${gitbase:t}
-VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}"
+VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" '' ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index fb7c450..d70e03c 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -8,5 +8,5 @@ local hgbranch hgbase
 hgbase=${vcs_comm[basedir]}
 rrn=${hgbase:t}
 hgbranch=$(< ${hgbase}/.hg/branch)
-VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' ''
+VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' '' '' ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn
index 63f0601..0a8064c 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn
@@ -8,5 +8,5 @@ local mtnbranch mtnbase
 mtnbase=${vcs_comm[basedir]}
 rrn=${mtnbase:t}
 mtnbranch=${${(M)${(f)"$( ${vcs_comm[cmd]} status )"}:#(#s)Current branch:*}/*: /}
-VCS_INFO_formats '' "${mtnbranch}" "${mtnbase}" '' ''
+VCS_INFO_formats '' "${mtnbranch}" "${mtnbase}" '' '' '' ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
index ac87faf..e4bbb06 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
@@ -21,4 +21,4 @@ p4branch="%b:%r"
 zformat -f p4branch "${p4branch}" "b:${p4info[Client_name]}" \
 "r:$change"
 
-VCS_INFO_formats '' "${p4branch}" "${p4base}" '' ''
+VCS_INFO_formats '' "${p4branch}" "${p4base}" '' '' "$change" ''
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk
index 48e5edb..29cda81 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk
@@ -9,5 +9,5 @@ svkbase=${vcs_comm[basedir]}
 rrn=${svkbase:t}
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svkbranch || svkbranch="%b:%r"
 zformat -f svkbranch "${svkbranch}" "b:${vcs_comm[branch]}" "r:${vcs_comm[revision]}"
-VCS_INFO_formats '' "${svkbranch}" "${svkbase}" '' ''
+VCS_INFO_formats '' "${svkbranch}" "${svkbase}" '' '' "${${vcs_comm[revision]}" ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index e180805..75da22b 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -24,5 +24,5 @@ svnbase="$(VCS_INFO_realpath ${svnbase})"
 rrn=${svnbase:t}
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r"
 zformat -f svnbranch "${svnbranch}" "b:${svninfo[URL]##*/}" "r:${svninfo[Revision]}"
-VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' ''
+VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' '' "${svninfo[Revision]}" ''
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla b/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
index 69a82eb..f015e0c 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
@@ -9,5 +9,5 @@ tlabase="$(VCS_INFO_realpath ${vcs_comm[basedir]})"
 rrn=${tlabase:t}
 # tree-id gives us something like 'foo@example.com/demo--1.0--patch-4', so:
 tlabranch=${${"$( ${vcs_comm[cmd]} tree-id )"}/*\//}
-VCS_INFO_formats '' "${tlabranch}" "${tlabase}" '' ''
+VCS_INFO_formats '' "${tlabranch}" "${tlabase}" '' '' '' ''
 return 0
diff --git a/Functions/VCS_Info/VCS_INFO_formats b/Functions/VCS_Info/VCS_INFO_formats
index 72030cc..35b3b96 100644
--- a/Functions/VCS_Info/VCS_INFO_formats
+++ b/Functions/VCS_Info/VCS_INFO_formats
@@ -3,7 +3,24 @@
 ## Distributed under the same BSD-ish license as zsh itself.
 
 setopt localoptions noksharrays NO_shwordsplit
-local action=$1 branch=$2 base=$3 staged=$4 unstaged=$5
+local action=$1 branch=$2 base=$3 staged=$4 unstaged=$5 rev=$6 misc=$7
+
+## description:
+#   action:   a string that signals a certain non-default condition in the
+#             repository (like 'rebase-i' in git). If this in non-empty,
+#             the actionformats will be used, too.
+#   branch:   the name of the currently checked out branch.
+#   base:     the full name of the repository's root directory.
+#   staged:   non-empty if the repository contains staged changes.
+#   unstaged: non-empty if the repository contains unstaged changes.
+#   rev:      an identifier of the currently checked out revision.
+#   misc:     a string that may contain anything the author likes.
+#             the backends should document what they put in it and when.
+#
+# If an argument has no valid value for a given backend, an empty value
+# should be provided. eg:
+#   VCS_INFO_formats '' "${foobranch}" "${foobase}" '' '' '' "${foomisc}"
+
 local msg
 local -i i j
 
@@ -31,6 +48,8 @@ for i in {1..${#msgs}} ; do
                     a:${action}                     \
                     b:${branch}                     \
                     c:${staged}                     \
+                    i:${rev}                        \
+                    m:${misc}                       \
                     r:${base:t}                     \
                     s:${vcs}                        \
                     u:${unstaged}                   \
-- 
1.6.2.1.136.g8e24


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

* PATCH: (2/5) Add git's sha1 hash as revision information
  2009-04-06 17:45 PATCH: (0/5) Updates for vcs_info Frank Terbeck
  2009-04-06 17:45 ` PATCH: (1/5) vcs_info: add revision and "misc" argument to VCS_INFO_formats() Frank Terbeck
@ 2009-04-06 17:45 ` Frank Terbeck
  2009-04-06 17:45 ` PATCH: (3/5) Add information about hg's local revision number and the commit's hash Frank Terbeck
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2009-04-06 17:45 UTC (permalink / raw)
  To: zsh-workers

This does not mean, that the git backend supports a branchformat now.
Most people probably don't care about the sha1, so its retrieval is even
disabled by default. Still, I've seen people add such information to
their prompts, so vcs_info can do that now, too.

Example:
[snip]
autoload -Uz vcs_info; vcs_info

zstyle ':vcs_info:*'     max-exports    2
zstyle ':vcs_info:*'     formats        '(%s)-[%b]-'    '%i'
zstyle ':vcs_info:*'     actionformats  '(%s)-[%b|%a]-' '%i'
zstyle ':vcs_info:git:*' 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_[1,8]}"
}

PS1='%~%(1v. %1v.)%# '
RPS1='%(2v.[%2v].)'
[snap]
---
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 745be34..faab2b8 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -3,7 +3,7 @@
 ## Distributed under the same BSD-ish license as zsh itself.
 
 setopt localoptions extendedglob NO_shwordsplit
-local gitdir gitbase gitbranch gitaction gitunstaged gitstaged
+local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1
 
 VCS_INFO_git_getaction () {
     local gitaction='' gitdir=$1
@@ -77,7 +77,7 @@ VCS_INFO_git_getbranch () {
         gitbranch="$(${(z)gitsymref} 2> /dev/null)"
 
         if [[ $? -ne 0 ]] ; then
-            gitbranch="$(${vcs_comm[cmd]} describe --exact-match HEAD 2>/dev/null)"
+            gitbranch="refs/tags/$(${vcs_comm[cmd]} describe --exact-match HEAD 2>/dev/null)"
 
             if [[ $? -ne 0 ]] ; then
                 gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
@@ -85,12 +85,21 @@ VCS_INFO_git_getbranch () {
         fi
     fi
 
-    printf '%s' "${gitbranch##refs/heads/}"
+    printf '%s' "${gitbranch}"
     return 0
 }
 
 gitdir=${vcs_comm[gitdir]}
 gitbranch="$(VCS_INFO_git_getbranch ${gitdir})"
+if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision && \
+    [[ ${gitbranch} == refs/* ]] && \
+    [[ -r "${gitdir}/${gitbranch}" ]] ; then
+
+    gitsha1="${"$(< $gitdir/$gitbranch)"}"
+else
+    gitsha1=''
+fi
+gitbranch="${gitbranch##refs/[^/]##/}"
 
 if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then
     return 1
@@ -108,5 +117,5 @@ VCS_INFO_adjust
 gitaction="$(VCS_INFO_git_getaction ${gitdir})"
 gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
 rrn=${gitbase:t}
-VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" '' ''
+VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" "${gitsha1}" ''
 return 0
-- 
1.6.2.1.136.g8e24


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

* PATCH: (3/5) Add information about hg's local revision number and the commit's hash
  2009-04-06 17:45 PATCH: (0/5) Updates for vcs_info Frank Terbeck
  2009-04-06 17:45 ` PATCH: (1/5) vcs_info: add revision and "misc" argument to VCS_INFO_formats() Frank Terbeck
  2009-04-06 17:45 ` PATCH: (2/5) Add git's sha1 hash as revision information Frank Terbeck
@ 2009-04-06 17:45 ` Frank Terbeck
  2009-04-06 17:45 ` PATCH: (4/5) contrib.yo: updates for get-revision, %i and %m Frank Terbeck
  2009-04-06 17:45 ` PATCH: (5/5) Make the hg backend work with new versions of mercurial Frank Terbeck
  4 siblings, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2009-04-06 17:45 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.2.1.136.g8e24


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

* PATCH: (4/5) contrib.yo: updates for get-revision, %i and %m
  2009-04-06 17:45 PATCH: (0/5) Updates for vcs_info Frank Terbeck
                   ` (2 preceding siblings ...)
  2009-04-06 17:45 ` PATCH: (3/5) Add information about hg's local revision number and the commit's hash Frank Terbeck
@ 2009-04-06 17:45 ` Frank Terbeck
  2009-04-06 17:45 ` PATCH: (5/5) Make the hg backend work with new versions of mercurial Frank Terbeck
  4 siblings, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2009-04-06 17:45 UTC (permalink / raw)
  To: zsh-workers

---
 Doc/Zsh/contrib.yo |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 2eb26ab..7412f81 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -579,6 +579,17 @@ the default is to use the not-that-simple code, which is potentially a lot
 slower but might be more accurate in all possible cases. This style is only
 used by the tt(bzr) backend.
 )
+kindex(get-revision)
+item(tt(get-revision))(
+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
+hash value of the currently checked out commit is available via the tt(%i)
+expansion. With tt(hg), the local revision number is available via tt(%i)
+and the corresponding global hash is available via tt(%m).
+If this style is set in the tt(hg) context, the backend supports the
+branchformat style.
+)
 kindex(use-prompt-escapes)
 item(tt(use-prompt-escapes))(
 Determines if we assume that the assembled
@@ -604,6 +615,7 @@ sitem(tt(unstagedstr))((string: "U"))
 sitem(tt(command))((empty string))
 sitem(tt(use-server))(false)
 sitem(tt(use-simple))(false)
+sitem(tt(get-revision))(false)
 sitem(tt(use-prompt-escapes))(true)
 endsitem()
 
@@ -615,6 +627,7 @@ sitem(tt(%s))(The vcs in use (git, hg, svn etc.))
 sitem(tt(%b))(Information about the current branch.)
 sitem(tt(%a))(An identifier, that describes the action. Only makes sense in
 actionformats.)
+sitem(tt(%i))(The current revision number or identifier.)
 sitem(tt(%c))(The string from the var(stagedstr) style if there are staged
 changes in the repository.)
 sitem(tt(%u))(The string from the var(unstagedstr) style if there are unstaged
@@ -624,6 +637,10 @@ sitem(tt(%r))(repository name. If tt(%R) is var(/foo/bar/repoXY), tt(%r) is
 var(repoXY).)
 sitem(tt(%S))(subdirectory within a repository. If tt($PWD) is
 var(/foo/bar/reposXY/beer/tasty), tt(%S) is var(beer/tasty).)
+sitem(tt(%m))(A "misc" replacement. It is at the discretion of the backend
+to decide what this replacement expands to. It is currently used only by
+the tt(hg) backend. The hg backend replaces tt(%m) with the global hash
+value of the current revision.)
 endsitem()
 
 In tt(branchformat) these replacements are done:
-- 
1.6.2.1.136.g8e24


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

* PATCH: (5/5) Make the hg backend work with new versions of mercurial
  2009-04-06 17:45 PATCH: (0/5) Updates for vcs_info Frank Terbeck
                   ` (3 preceding siblings ...)
  2009-04-06 17:45 ` PATCH: (4/5) contrib.yo: updates for get-revision, %i and %m Frank Terbeck
@ 2009-04-06 17:45 ` Frank Terbeck
  4 siblings, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2009-04-06 17:45 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.2.1.136.g8e24


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

end of thread, other threads:[~2009-04-06 17:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-06 17:45 PATCH: (0/5) Updates for vcs_info Frank Terbeck
2009-04-06 17:45 ` PATCH: (1/5) vcs_info: add revision and "misc" argument to VCS_INFO_formats() Frank Terbeck
2009-04-06 17:45 ` PATCH: (2/5) Add git's sha1 hash as revision information Frank Terbeck
2009-04-06 17:45 ` PATCH: (3/5) Add information about hg's local revision number and the commit's hash Frank Terbeck
2009-04-06 17:45 ` PATCH: (4/5) contrib.yo: updates for get-revision, %i and %m Frank Terbeck
2009-04-06 17:45 ` PATCH: (5/5) 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).