Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Submitting vcs_info function



On 2008-09-17 at 22:18 +0200, Frank Terbeck wrote:
>               All functions named VCS_INFO_* are for internal use only.
> 
> 
>        Variable description
> 
>               ${VCS_INFO_message_N_} (Note the trailing underscore)

It's a rather confusing distinction that functions named VCS_INFO_* are
internal but variables named VCS_INFO_* are how you get access to the
results.

> Comments welcome. :)

In general, this looks great and I intend to use it.

> VCS_INFO_svn_get_data () { # {{{
>     setopt localoptions noksharrays extendedglob
>     local svnbase svnbranch
>     local -a svninfo
> 
>     svnbase="."
>     while [[ -d "${svnbase}/../.svn" ]]; do
>         svnbase="${svnbase}/.."
>     done

However, this is a deal-breaker for me at present, since it doesn't
handle svn:externals so will chase up to the top-level.  For many cases,
for personal development, on my server, that means getting up to my
home directory svn repo, as various other repositories, including some
dev ones, are things I automatically get (unless I use --no-externals).

I suspect that you're going to need to use svn info at each step up and
stop, using previous results, if .svn doesn't exist or the value of
"Repository UUID" differs in the new directory.

This might be another case where the simple branch option logic is
helpful?  Although "svn info" is a lightweight local operation, I'm not
so sure about calling it N times before every prompt.

>     svnbase="$(VCS_INFO_realpath ${svnbase})"
>     svninfo=( ${${${(M)${(f)"$( svn info )"}:#(#s)(URL|Revision)*}/*: /}/*\//} )
> 
>     rrn=${svnbase:t}
>     zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r"
>     zformat -f svnbranch "${svnbranch}" "b:${svninfo[1]}" "r:${svninfo[2]}"
>     VCS_INFO_formats '' "${svnbranch}" "${svnbase}"
>     return 0
> }

I note that svn info has the --non-interactive option, which you
probably want here.

Also, I don't believe that "svn info" makes any guarantees about output
ordering.

This appears to work for me:

----------------------------8< cut here >8------------------------------
VCS_INFO_svn_get_data () {
    setopt localoptions noksharrays extendedglob
    local svnbase svnbranch a b rrn
    local -A svninfo parentinfo

    svnbase=".";
    svninfo=()
    svn info --non-interactive | while IFS=: read a b; do svninfo[${a// /_}]="${b## #}"; done
    while [[ -d "${svnbase}/../.svn" ]]; do 
        parentinfo=()
        svn info --non-interactive "${svnbase}/.." | while IFS=: read a b; do parentinfo[${a// /_}]="${b## #}"; done
        [[ $parentinfo[Repository_UUID] != $svninfo[Repository_UUID] ]] && break
        svninfo=(${(kv)parentinfo})
        svnbase="${svnbase}/.."
    done

    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}"
    return 0
}   
----------------------------8< cut here >8------------------------------

Regards,
-Phil



Messages sorted by: Reverse Date, Date, Thread, Author