-get_vcs_info () {
- # Donne les infos sur le dépôt VCS courant.
- local LBRANCH LTYPE BRANCH TYPE DIR
- declare -a DIR
- declare -A TYPE
- declare -A BRANCH
- DIR[0]=".git"
- DIR[1]=".hg"
- DIR[2]="_darcs"
- DIR[3]=".svn"
- TYPE[.git]="git"
- TYPE[.hg]="mercurial"
- TYPE[_darcs]="darcs"
- TYPE[.svn]="svn"
- BRANCH[.git]='git branch 2>/dev/null | sed -r "s/^[^*].*$//" | paste -s -d "" | sed -r "s/^[*] //"'
- BRANCH[.hg]='hg branch 2>/dev/null'
- BRANCH[_darcs]="darcs show repo 2>/dev/null| egrep '^ *Cache' | sed 's@.*/\([^/]*\),.*@\1@'"
- BRANCH[.svn]="svn info 2>/dev/null | head -n 6 | tail -n 1"
-
- DIR=$(eval "find_up \"$PWD\" -name \"\"$(printf -- ' -o -name "%s"' "${DIR[@]}") | head -n 1")
- if [ -n "$DIR" ]; then
- DIR=$(basename "$DIR")
- LBRANCH=$(eval "${BRANCH[$DIR]}")
- LTYPE="${TYPE[$DIR]}"
- if [ "$color_prompt" = yes ]; then
- VCS_info="${nocolor_prompt}${vcs_symbols_color}(${vcs_type_color}$LTYPE${vcs_symbols_color})-${vcs_symbols_color}[${vcs_branch_color}$LBRANCH${vcs_symbols_color}]${nocolor_prompt}"
+# If name should be overwritten (eg for git-svn), do it.
+vcs_adjust(){
+ [[ -n ${vcs_comm[overwrite_name]} ]] && vcs=${vcs_comm[overwrite_name]}
+ return 0
+}
+
+# Formats two VCS_info messages, one with colors, and one without
+vcs_formats(){
+ local action=$1 branch=$2 base=$3 rev=$4
+ local msg
+ local -i i
+
+ # printf is for readability (it's easier to find %s)
+ msg="(%s)${MINUS_CHAR}[%s/%s"
+ msg=$(printf $msg $vcs ${base/*\/} $branch)
+
+ # If there is a revnumber, print it
+ if [ ! -z ${rev} ]; then
+ msg="${msg}:%s"
+ msg=$(printf $msg $rev)
+ fi
+
+ # Print the current cvs action state
+ if [ ! -z ${action} ] ; then
+ msg="${msg}|%s"
+ msg=$(printf $msg $action)
+ fi
+ msg="${msg}]${MINUS_CHAR}"
+
+ msgs[1]=$msg
+
+ # Same shit with colors
+ msg="${nocolor_prompt}${vcs_symbols_color}(${vcs_type_color}%s${vcs_symbols_color})${vcs_sep_color}${MINUS_CHAR}${vcs_symbols_color}[${vcs_repo_color}%s${vcs_sep_color}/${vcs_branch_color}%s"
+ msg=$(printf $msg $vcs ${base/*\/} $branch)
+ if [ ! -z ${rev} ]; then
+ msg="${msg}${vcs_colon_color}:${vcs_rev_color}%s"
+ msg=$(printf $msg $rev)
+ fi
+ if [[ ! -z ${action} ]] ; then
+ msg="${msg}${nocolor_prompt}|${vcs_action_color}%s"
+ msg=$(printf $msg $action)
+ fi
+ msg="${msg}${vcs_symbols_color}]${line_color_prompt}${MINUS_CHAR}"
+ msgs[0]=$msg
+
+ return 0
+}
+
+# Uses -P option for cd in order to resolve symlinks
+vcs_realpath(){
+ (
+ cd -P $1 2>/dev/null && pwd
+ )
+}
+
+# Feature to detect a special dir, at the top of
+# the current repo
+detect_by_dir(){
+ local dirname=$1
+ local basedir="." realbasedir
+
+ realbasedir="$(vcs_realpath ${basedir})"
+ while [[ ${realbasedir} != '/' ]]; do
+ [[ -r ${realbasedir} ]] || return 1
+
+ # Tries to find detect_need_file (eg formats) in the dir
+ if [[ -n ${vcs_comm[detect_need_file]} ]] ; then
+ [[ -d ${basedir}/${dirname} ]] && \
+ [[ -e ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
+ break