1## vim:ft=zsh
2## perforce support by: Phil Pennock
3## Distributed under the same BSD-ish license as zsh itself.
4
5# XXX: This soooo needs to be cached
6setopt localoptions extendedglob
7local p4base a b
8local -A p4info
9local -xA hook_com
10
11${vcs_comm[cmd]} info | while IFS=: read a b; do p4info[${a// /_}]="${b## #}"; done
12p4base=${vcs_comm[basedir]}
13
14# We'll use the client name as the branch; close enough.
15local p4branch change
16# We'll use the latest change number to which the hierarchy from
17# here down is synced as the revision.
18# I suppose the following might be slow on a tortuous client view.
19change="${${$(${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}"
20zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat p4branch || p4branch="%b:%r"
21hook_com=( branch "${p4info[Client_name]}" revision "${change}" )
22if VCS_INFO_hook 'set-branch-format' "${p4branch}"; then
23    zformat -f p4branch "${p4branch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
24else
25    p4branch=${hook_com[branch-replace]}
26fi
27hook_com=()
28VCS_INFO_formats '' "${p4branch}" "${p4base}" '' '' "$change" ''
29return 0
30