about summary refs log tree commit diff
path: root/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
blob: d83521b143b5a62b5f8d67024256dc98211e9490 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## vim:ft=zsh
## mercurial support by: Frank Terbeck <ft@bewatermyfriend.org>
## Distributed under the same BSD-ish license as zsh itself.

setopt localoptions NO_shwordsplit
local file hgbranch hgbranch_name hgbase hghash hglrev r_branch r_info

hgbase=${vcs_comm[basedir]}
rrn=${hgbase:t}

file="${hgbase}/.hg/branch"
if [[ -r ${file} ]] ; then
    hgbranch_name=$(< ${file})
else
    hgbranch_name="default"
fi

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