setup: install some useful data files.
authorDan Villiom Podlaski Christiansen <danchr@gmail.com>
Mon, 30 Nov 2009 21:54:34 +0100
changeset 10005 68964567e406
parent 10004 af04a3dea4cd
child 10006 9c142ed9c405
setup: install some useful data files. The selection is somewhat arbitrary. In the case of the Zsh completion file, it will not conflict with the builtin Zsh completions: they are in a file named `_mercurial', not `_hg'.
contrib/bash/hg
contrib/bash_completion
contrib/zsh/_hg
contrib/zsh_completion
setup.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/bash/hg	Mon Nov 30 21:54:34 2009 +0100
@@ -0,0 +1,573 @@
+# bash completion for the Mercurial distributed SCM
+
+# Docs:
+#
+# If you source this file from your .bashrc, bash should be able to
+# complete a command line that uses hg with all the available commands
+# and options and sometimes even arguments.
+#
+# Mercurial allows you to define additional commands through extensions.
+# Bash should be able to automatically figure out the name of these new
+# commands and their options.  See below for how to define _hg_opt_foo
+# and _hg_cmd_foo functions to fine-tune the completion for option and
+# non-option arguments, respectively.
+#
+#
+# Notes about completion for specific commands:
+#
+# - the completion function for the email command from the patchbomb
+#   extension will try to call _hg_emails to get a list of e-mail
+#   addresses.  It's up to the user to define this function.  For
+#   example, put the addresses of the lists that you usually patchbomb
+#   in ~/.patchbomb-to and the addresses that you usually use to send
+#   the patchbombs in ~/.patchbomb-from and use something like this:
+#
+#      _hg_emails()
+#      {
+#          if [ -r ~/.patchbomb-$1 ]; then
+#              cat ~/.patchbomb-$1
+#          fi
+#      }
+#
+#
+# Writing completion functions for additional commands:
+#
+# If it exists, the function _hg_cmd_foo will be called without
+# arguments to generate the completion candidates for the hg command
+# "foo".  If the command receives some arguments that aren't options
+# even though they start with a "-", you can define a function called
+# _hg_opt_foo to generate the completion candidates.  If _hg_opt_foo
+# doesn't return 0, regular completion for options is attempted.
+#
+# In addition to the regular completion variables provided by bash,
+# the following variables are also set:
+# - $hg - the hg program being used (e.g. /usr/bin/hg)
+# - $cmd - the name of the hg command being completed
+# - $cmd_index - the index of $cmd in $COMP_WORDS
+# - $cur - the current argument being completed
+# - $prev - the argument before $cur
+# - $global_args - "|"-separated list of global options that accept
+#                  an argument (e.g. '--cwd|-R|--repository')
+# - $canonical - 1 if we canonicalized $cmd before calling the function
+#                0 otherwise
+#
+
+shopt -s extglob
+
+_hg_commands()
+{
+    local commands
+    commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands=""
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
+}
+
+_hg_paths()
+{
+    local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
+}
+
+_hg_repos()
+{
+    local i
+    for i in $(compgen -d -- "$cur"); do
+	test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
+    done
+}
+
+_hg_status()
+{
+    local files="$("$hg" status -n$1 . 2>/dev/null)"
+    local IFS=$'\n'
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
+}
+
+_hg_tags()
+{
+    local tags="$("$hg" tags -q 2>/dev/null)"
+    local IFS=$'\n'
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
+}
+
+_hg_branches()
+{
+    local branches="$("$hg" branches -q 2>/dev/null)"
+    local IFS=$'\n'
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur"))
+}
+
+# this is "kind of" ugly...
+_hg_count_non_option()
+{
+    local i count=0
+    local filters="$1"
+
+    for ((i=1; $i<=$COMP_CWORD; i++)); do
+	if [[ "${COMP_WORDS[i]}" != -* ]]; then
+	    if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
+		continue
+	    fi
+	    count=$(($count + 1))
+	fi
+    done
+
+    echo $(($count - 1))
+}
+
+_hg()
+{
+    local cur prev cmd cmd_index opts i
+    # global options that receive an argument
+    local global_args='--cwd|-R|--repository'
+    local hg="$1"
+    local canonical=0
+
+    COMPREPLY=()
+    cur="$2"
+    prev="$3"
+
+    # searching for the command
+    # (first non-option argument that doesn't follow a global option that
+    #  receives an argument)
+    for ((i=1; $i<=$COMP_CWORD; i++)); do
+	if [[ ${COMP_WORDS[i]} != -* ]]; then
+	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
+		cmd="${COMP_WORDS[i]}"
+		cmd_index=$i
+		break
+	    fi
+	fi
+    done
+
+    if [[ "$cur" == -* ]]; then
+	if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
+	    return
+	fi
+
+	opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null)
+
+	COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
+	return
+    fi
+
+    # global options
+    case "$prev" in
+	-R|--repository)
+	    _hg_paths
+	    _hg_repos
+	    return
+	;;
+	--cwd)
+	    # Stick with default bash completion
+	    return
+	;;
+    esac
+
+    if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
+	_hg_commands
+	return
+    fi
+
+    # try to generate completion candidates for whatever command the user typed
+    local help
+    if _hg_command_specific; then
+	return
+    fi
+
+    # canonicalize the command name and try again
+    help=$("$hg" help "$cmd" 2>/dev/null)
+    if [ $? -ne 0 ]; then
+	# Probably either the command doesn't exist or it's ambiguous
+	return
+    fi
+    cmd=${help#hg }
+    cmd=${cmd%%[$' \n']*}
+    canonical=1
+    _hg_command_specific
+}
+
+_hg_command_specific()
+{
+    if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
+	"_hg_cmd_$cmd"
+	return 0
+    fi
+
+    if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
+	if [ $canonical = 1 ]; then
+	    _hg_tags
+	    _hg_branches
+	    return 0
+	elif [[ status != "$cmd"* ]]; then
+	    _hg_tags
+	    _hg_branches
+	    return 0
+	else
+	    return 1
+	fi
+    fi
+
+    case "$cmd" in
+	help)
+	    _hg_commands
+	;;
+	export)
+	    if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
+		return 0
+	    fi
+	    _hg_tags
+	    _hg_branches
+	;;
+	manifest|update)
+	    _hg_tags
+	    _hg_branches
+	;;
+	pull|push|outgoing|incoming)
+	    _hg_paths
+	    _hg_repos
+	;;
+	paths)
+	    _hg_paths
+	;;
+	add)
+	    _hg_status "u"
+	;;
+	merge)
+	    _hg_tags
+	    _hg_branches
+	;;
+	commit)
+	    _hg_status "mar"
+	;;
+	remove)
+	    _hg_status "d"
+	;;
+	forget)
+	    _hg_status "a"
+	;;
+	diff)
+	    _hg_status "mar"
+	;;
+	revert)
+	    _hg_status "mard"
+	;;
+	clone)
+	    local count=$(_hg_count_non_option)
+	    if [ $count = 1 ]; then
+		_hg_paths
+	    fi
+	    _hg_repos
+	;;
+	debugindex|debugindexdot)
+	    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
+	;;
+	debugdata)
+	    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
+	;;
+	*)
+	    return 1
+	;;
+    esac
+
+    return 0
+}
+
+complete -o bashdefault -o default -F _hg hg 2>/dev/null \
+    || complete -o default -F _hg hg
+
+
+# Completion for commands provided by extensions
+
+# bookmarks
+_hg_bookmarks()
+{
+    local bookmarks="$("$hg" bookmarks --quiet 2>/dev/null )"
+    local IFS=$'\n'
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur"))
+}
+
+_hg_cmd_bookmarks()
+{
+    if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then
+        _hg_bookmarks
+        return
+    fi
+}
+
+# mq
+_hg_ext_mq_patchlist()
+{
+    local patches
+    patches=$("$hg" $1 2>/dev/null)
+    if [ $? -eq 0 ] && [ "$patches" ]; then
+	COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
+	return 0
+    fi
+    return 1
+}
+
+_hg_ext_mq_queues()
+{
+    local root=$("$hg" root 2>/dev/null)
+    local n
+    for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
+	# I think we're usually not interested in the regular "patches" queue
+	# so just filter it.
+	if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
+	    COMPREPLY=(${COMPREPLY[@]:-} "$n")
+	fi
+    done
+}
+
+_hg_cmd_qpop()
+{
+    if [[ "$prev" = @(-n|--name) ]]; then
+	_hg_ext_mq_queues
+	return
+    fi
+    _hg_ext_mq_patchlist qapplied
+}
+
+_hg_cmd_qpush()
+{
+    if [[ "$prev" = @(-n|--name) ]]; then
+	_hg_ext_mq_queues
+	return
+    fi
+    _hg_ext_mq_patchlist qunapplied
+}
+
+_hg_cmd_qgoto()
+{
+    if [[ "$prev" = @(-n|--name) ]]; then
+	_hg_ext_mq_queues
+	return
+    fi
+    _hg_ext_mq_patchlist qseries
+}
+
+_hg_cmd_qdelete()
+{
+    local qcmd=qunapplied
+    if [[ "$prev" = @(-r|--rev) ]]; then
+	qcmd=qapplied
+    fi
+    _hg_ext_mq_patchlist $qcmd
+}
+
+_hg_cmd_qfinish()
+{
+    if [[ "$prev" = @(-a|--applied) ]]; then
+	return
+    fi
+    _hg_ext_mq_patchlist qapplied
+}
+
+_hg_cmd_qsave()
+{
+    if [[ "$prev" = @(-n|--name) ]]; then
+	_hg_ext_mq_queues
+	return
+    fi
+}
+
+_hg_cmd_strip()
+{
+    _hg_tags
+    _hg_branches
+}
+
+_hg_cmd_qcommit()
+{
+    local root=$("$hg" root 2>/dev/null)
+    # this is run in a sub-shell, so we can't use _hg_status
+    local files=$(cd "$root/.hg/patches" 2>/dev/null &&
+                  "$hg" status -nmar 2>/dev/null)
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
+}
+
+_hg_cmd_qfold()
+{
+    _hg_ext_mq_patchlist qunapplied
+}
+
+_hg_cmd_qrename()
+{
+    _hg_ext_mq_patchlist qseries
+}
+
+_hg_cmd_qheader()
+{
+    _hg_ext_mq_patchlist qseries
+}
+
+_hg_cmd_qclone()
+{
+    local count=$(_hg_count_non_option)
+    if [ $count = 1 ]; then
+	_hg_paths
+    fi
+    _hg_repos
+}
+
+_hg_ext_mq_guards()
+{
+    "$hg" qselect --series 2>/dev/null | sed -e 's/^.//'
+}
+
+_hg_cmd_qselect()
+{
+    local guards=$(_hg_ext_mq_guards)
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
+}
+
+_hg_cmd_qguard()
+{
+    local prefix=''
+
+    if [[ "$cur" == +* ]]; then
+	prefix=+
+    elif [[ "$cur" == -* ]]; then
+	prefix=-
+    fi
+    local ncur=${cur#[-+]}
+
+    if ! [ "$prefix" ]; then
+	_hg_ext_mq_patchlist qseries
+	return
+    fi
+
+    local guards=$(_hg_ext_mq_guards)
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
+}
+
+_hg_opt_qguard()
+{
+    local i
+    for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
+	if [[ ${COMP_WORDS[i]} != -* ]]; then
+	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
+		_hg_cmd_qguard
+		return 0
+	    fi
+	elif [ "${COMP_WORDS[i]}" = -- ]; then
+	    _hg_cmd_qguard
+	    return 0
+	fi
+    done
+    return 1
+}
+
+
+# hbisect
+_hg_cmd_bisect()
+{
+    local i subcmd
+
+    # find the sub-command
+    for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
+	if [[ ${COMP_WORDS[i]} != -* ]]; then
+	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
+		subcmd="${COMP_WORDS[i]}"
+		break
+	    fi
+	fi
+    done
+
+    if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
+	COMPREPLY=(${COMPREPLY[@]:-}
+		   $(compgen -W 'bad good help init next reset' -- "$cur"))
+	return
+    fi
+
+    case "$subcmd" in
+	good|bad)
+	    _hg_tags
+	    _hg_branches
+	    ;;
+    esac
+
+    return
+}
+
+
+# patchbomb
+_hg_cmd_email()
+{
+    case "$prev" in
+	-c|--cc|-t|--to|-f|--from|--bcc)
+	    # we need an e-mail address. let the user provide a function
+	    # to get them
+	    if [ "$(type -t _hg_emails)" = function ]; then
+		local arg=to
+		if [[ "$prev" == @(-f|--from) ]]; then
+		    arg=from
+		fi
+		local addresses=$(_hg_emails $arg)
+		COMPREPLY=(${COMPREPLY[@]:-}
+			   $(compgen -W '$addresses' -- "$cur"))
+	    fi
+	    return
+	    ;;
+	-m|--mbox)
+	    # fallback to standard filename completion
+	    return
+	    ;;
+	-s|--subject)
+	    # free form string
+	    return
+	    ;;
+    esac
+
+    _hg_tags
+    _hg_branches
+    return
+}
+
+
+# gpg
+_hg_cmd_sign()
+{
+    _hg_tags
+    _hg_branches
+}
+
+
+# transplant
+_hg_cmd_transplant()
+{
+    case "$prev" in
+	-s|--source)
+	    _hg_paths
+	    _hg_repos
+	    return
+	    ;;
+	--filter)
+	    # standard filename completion
+	    return
+	    ;;
+    esac
+
+    # all other transplant options values and command parameters are revisions
+    _hg_tags
+    _hg_branches
+    return
+}
+
+# shelve
+_hg_shelves()
+{
+    local shelves="$("$hg" unshelve -l . 2>/dev/null)"
+    local IFS=$'\n'
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur"))
+}
+
+_hg_cmd_shelve()
+{
+    _hg_status "mard"
+}
+
+_hg_cmd_unshelve()
+{
+    _hg_shelves
+}
--- a/contrib/bash_completion	Mon Nov 30 23:10:21 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,573 +0,0 @@
-# bash completion for the Mercurial distributed SCM
-
-# Docs:
-#
-# If you source this file from your .bashrc, bash should be able to
-# complete a command line that uses hg with all the available commands
-# and options and sometimes even arguments.
-#
-# Mercurial allows you to define additional commands through extensions.
-# Bash should be able to automatically figure out the name of these new
-# commands and their options.  See below for how to define _hg_opt_foo
-# and _hg_cmd_foo functions to fine-tune the completion for option and
-# non-option arguments, respectively.
-#
-#
-# Notes about completion for specific commands:
-#
-# - the completion function for the email command from the patchbomb
-#   extension will try to call _hg_emails to get a list of e-mail
-#   addresses.  It's up to the user to define this function.  For
-#   example, put the addresses of the lists that you usually patchbomb
-#   in ~/.patchbomb-to and the addresses that you usually use to send
-#   the patchbombs in ~/.patchbomb-from and use something like this:
-#
-#      _hg_emails()
-#      {
-#          if [ -r ~/.patchbomb-$1 ]; then
-#              cat ~/.patchbomb-$1
-#          fi
-#      }
-#
-#
-# Writing completion functions for additional commands:
-#
-# If it exists, the function _hg_cmd_foo will be called without
-# arguments to generate the completion candidates for the hg command
-# "foo".  If the command receives some arguments that aren't options
-# even though they start with a "-", you can define a function called
-# _hg_opt_foo to generate the completion candidates.  If _hg_opt_foo
-# doesn't return 0, regular completion for options is attempted.
-#
-# In addition to the regular completion variables provided by bash,
-# the following variables are also set:
-# - $hg - the hg program being used (e.g. /usr/bin/hg)
-# - $cmd - the name of the hg command being completed
-# - $cmd_index - the index of $cmd in $COMP_WORDS
-# - $cur - the current argument being completed
-# - $prev - the argument before $cur
-# - $global_args - "|"-separated list of global options that accept
-#                  an argument (e.g. '--cwd|-R|--repository')
-# - $canonical - 1 if we canonicalized $cmd before calling the function
-#                0 otherwise
-#
-
-shopt -s extglob
-
-_hg_commands()
-{
-    local commands
-    commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands=""
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
-}
-
-_hg_paths()
-{
-    local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
-}
-
-_hg_repos()
-{
-    local i
-    for i in $(compgen -d -- "$cur"); do
-	test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
-    done
-}
-
-_hg_status()
-{
-    local files="$("$hg" status -n$1 . 2>/dev/null)"
-    local IFS=$'\n'
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
-}
-
-_hg_tags()
-{
-    local tags="$("$hg" tags -q 2>/dev/null)"
-    local IFS=$'\n'
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
-}
-
-_hg_branches()
-{
-    local branches="$("$hg" branches -q 2>/dev/null)"
-    local IFS=$'\n'
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur"))
-}
-
-# this is "kind of" ugly...
-_hg_count_non_option()
-{
-    local i count=0
-    local filters="$1"
-
-    for ((i=1; $i<=$COMP_CWORD; i++)); do
-	if [[ "${COMP_WORDS[i]}" != -* ]]; then
-	    if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
-		continue
-	    fi
-	    count=$(($count + 1))
-	fi
-    done
-
-    echo $(($count - 1))
-}
-
-_hg()
-{
-    local cur prev cmd cmd_index opts i
-    # global options that receive an argument
-    local global_args='--cwd|-R|--repository'
-    local hg="$1"
-    local canonical=0
-
-    COMPREPLY=()
-    cur="$2"
-    prev="$3"
-
-    # searching for the command
-    # (first non-option argument that doesn't follow a global option that
-    #  receives an argument)
-    for ((i=1; $i<=$COMP_CWORD; i++)); do
-	if [[ ${COMP_WORDS[i]} != -* ]]; then
-	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
-		cmd="${COMP_WORDS[i]}"
-		cmd_index=$i
-		break
-	    fi
-	fi
-    done
-
-    if [[ "$cur" == -* ]]; then
-	if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
-	    return
-	fi
-
-	opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null)
-
-	COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
-	return
-    fi
-
-    # global options
-    case "$prev" in
-	-R|--repository)
-	    _hg_paths
-	    _hg_repos
-	    return
-	;;
-	--cwd)
-	    # Stick with default bash completion
-	    return
-	;;
-    esac
-
-    if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
-	_hg_commands
-	return
-    fi
-
-    # try to generate completion candidates for whatever command the user typed
-    local help
-    if _hg_command_specific; then
-	return
-    fi
-
-    # canonicalize the command name and try again
-    help=$("$hg" help "$cmd" 2>/dev/null)
-    if [ $? -ne 0 ]; then
-	# Probably either the command doesn't exist or it's ambiguous
-	return
-    fi
-    cmd=${help#hg }
-    cmd=${cmd%%[$' \n']*}
-    canonical=1
-    _hg_command_specific
-}
-
-_hg_command_specific()
-{
-    if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
-	"_hg_cmd_$cmd"
-	return 0
-    fi
-
-    if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
-	if [ $canonical = 1 ]; then
-	    _hg_tags
-	    _hg_branches
-	    return 0
-	elif [[ status != "$cmd"* ]]; then
-	    _hg_tags
-	    _hg_branches
-	    return 0
-	else
-	    return 1
-	fi
-    fi
-
-    case "$cmd" in
-	help)
-	    _hg_commands
-	;;
-	export)
-	    if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
-		return 0
-	    fi
-	    _hg_tags
-	    _hg_branches
-	;;
-	manifest|update)
-	    _hg_tags
-	    _hg_branches
-	;;
-	pull|push|outgoing|incoming)
-	    _hg_paths
-	    _hg_repos
-	;;
-	paths)
-	    _hg_paths
-	;;
-	add)
-	    _hg_status "u"
-	;;
-	merge)
-	    _hg_tags
-	    _hg_branches
-	;;
-	commit)
-	    _hg_status "mar"
-	;;
-	remove)
-	    _hg_status "d"
-	;;
-	forget)
-	    _hg_status "a"
-	;;
-	diff)
-	    _hg_status "mar"
-	;;
-	revert)
-	    _hg_status "mard"
-	;;
-	clone)
-	    local count=$(_hg_count_non_option)
-	    if [ $count = 1 ]; then
-		_hg_paths
-	    fi
-	    _hg_repos
-	;;
-	debugindex|debugindexdot)
-	    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
-	;;
-	debugdata)
-	    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
-	;;
-	*)
-	    return 1
-	;;
-    esac
-
-    return 0
-}
-
-complete -o bashdefault -o default -F _hg hg 2>/dev/null \
-    || complete -o default -F _hg hg
-
-
-# Completion for commands provided by extensions
-
-# bookmarks
-_hg_bookmarks()
-{
-    local bookmarks="$("$hg" bookmarks --quiet 2>/dev/null )"
-    local IFS=$'\n'
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur"))
-}
-
-_hg_cmd_bookmarks()
-{
-    if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then
-        _hg_bookmarks
-        return
-    fi
-}
-
-# mq
-_hg_ext_mq_patchlist()
-{
-    local patches
-    patches=$("$hg" $1 2>/dev/null)
-    if [ $? -eq 0 ] && [ "$patches" ]; then
-	COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
-	return 0
-    fi
-    return 1
-}
-
-_hg_ext_mq_queues()
-{
-    local root=$("$hg" root 2>/dev/null)
-    local n
-    for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
-	# I think we're usually not interested in the regular "patches" queue
-	# so just filter it.
-	if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
-	    COMPREPLY=(${COMPREPLY[@]:-} "$n")
-	fi
-    done
-}
-
-_hg_cmd_qpop()
-{
-    if [[ "$prev" = @(-n|--name) ]]; then
-	_hg_ext_mq_queues
-	return
-    fi
-    _hg_ext_mq_patchlist qapplied
-}
-
-_hg_cmd_qpush()
-{
-    if [[ "$prev" = @(-n|--name) ]]; then
-	_hg_ext_mq_queues
-	return
-    fi
-    _hg_ext_mq_patchlist qunapplied
-}
-
-_hg_cmd_qgoto()
-{
-    if [[ "$prev" = @(-n|--name) ]]; then
-	_hg_ext_mq_queues
-	return
-    fi
-    _hg_ext_mq_patchlist qseries
-}
-
-_hg_cmd_qdelete()
-{
-    local qcmd=qunapplied
-    if [[ "$prev" = @(-r|--rev) ]]; then
-	qcmd=qapplied
-    fi
-    _hg_ext_mq_patchlist $qcmd
-}
-
-_hg_cmd_qfinish()
-{
-    if [[ "$prev" = @(-a|--applied) ]]; then
-	return
-    fi
-    _hg_ext_mq_patchlist qapplied
-}
-
-_hg_cmd_qsave()
-{
-    if [[ "$prev" = @(-n|--name) ]]; then
-	_hg_ext_mq_queues
-	return
-    fi
-}
-
-_hg_cmd_strip()
-{
-    _hg_tags
-    _hg_branches
-}
-
-_hg_cmd_qcommit()
-{
-    local root=$("$hg" root 2>/dev/null)
-    # this is run in a sub-shell, so we can't use _hg_status
-    local files=$(cd "$root/.hg/patches" 2>/dev/null &&
-                  "$hg" status -nmar 2>/dev/null)
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
-}
-
-_hg_cmd_qfold()
-{
-    _hg_ext_mq_patchlist qunapplied
-}
-
-_hg_cmd_qrename()
-{
-    _hg_ext_mq_patchlist qseries
-}
-
-_hg_cmd_qheader()
-{
-    _hg_ext_mq_patchlist qseries
-}
-
-_hg_cmd_qclone()
-{
-    local count=$(_hg_count_non_option)
-    if [ $count = 1 ]; then
-	_hg_paths
-    fi
-    _hg_repos
-}
-
-_hg_ext_mq_guards()
-{
-    "$hg" qselect --series 2>/dev/null | sed -e 's/^.//'
-}
-
-_hg_cmd_qselect()
-{
-    local guards=$(_hg_ext_mq_guards)
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
-}
-
-_hg_cmd_qguard()
-{
-    local prefix=''
-
-    if [[ "$cur" == +* ]]; then
-	prefix=+
-    elif [[ "$cur" == -* ]]; then
-	prefix=-
-    fi
-    local ncur=${cur#[-+]}
-
-    if ! [ "$prefix" ]; then
-	_hg_ext_mq_patchlist qseries
-	return
-    fi
-
-    local guards=$(_hg_ext_mq_guards)
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
-}
-
-_hg_opt_qguard()
-{
-    local i
-    for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
-	if [[ ${COMP_WORDS[i]} != -* ]]; then
-	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
-		_hg_cmd_qguard
-		return 0
-	    fi
-	elif [ "${COMP_WORDS[i]}" = -- ]; then
-	    _hg_cmd_qguard
-	    return 0
-	fi
-    done
-    return 1
-}
-
-
-# hbisect
-_hg_cmd_bisect()
-{
-    local i subcmd
-
-    # find the sub-command
-    for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
-	if [[ ${COMP_WORDS[i]} != -* ]]; then
-	    if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
-		subcmd="${COMP_WORDS[i]}"
-		break
-	    fi
-	fi
-    done
-
-    if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
-	COMPREPLY=(${COMPREPLY[@]:-}
-		   $(compgen -W 'bad good help init next reset' -- "$cur"))
-	return
-    fi
-
-    case "$subcmd" in
-	good|bad)
-	    _hg_tags
-	    _hg_branches
-	    ;;
-    esac
-
-    return
-}
-
-
-# patchbomb
-_hg_cmd_email()
-{
-    case "$prev" in
-	-c|--cc|-t|--to|-f|--from|--bcc)
-	    # we need an e-mail address. let the user provide a function
-	    # to get them
-	    if [ "$(type -t _hg_emails)" = function ]; then
-		local arg=to
-		if [[ "$prev" == @(-f|--from) ]]; then
-		    arg=from
-		fi
-		local addresses=$(_hg_emails $arg)
-		COMPREPLY=(${COMPREPLY[@]:-}
-			   $(compgen -W '$addresses' -- "$cur"))
-	    fi
-	    return
-	    ;;
-	-m|--mbox)
-	    # fallback to standard filename completion
-	    return
-	    ;;
-	-s|--subject)
-	    # free form string
-	    return
-	    ;;
-    esac
-
-    _hg_tags
-    _hg_branches
-    return
-}
-
-
-# gpg
-_hg_cmd_sign()
-{
-    _hg_tags
-    _hg_branches
-}
-
-
-# transplant
-_hg_cmd_transplant()
-{
-    case "$prev" in
-	-s|--source)
-	    _hg_paths
-	    _hg_repos
-	    return
-	    ;;
-	--filter)
-	    # standard filename completion
-	    return
-	    ;;
-    esac
-
-    # all other transplant options values and command parameters are revisions
-    _hg_tags
-    _hg_branches
-    return
-}
-
-# shelve
-_hg_shelves()
-{
-    local shelves="$("$hg" unshelve -l . 2>/dev/null)"
-    local IFS=$'\n'
-    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur"))
-}
-
-_hg_cmd_shelve()
-{
-    _hg_status "mard"
-}
-
-_hg_cmd_unshelve()
-{
-    _hg_shelves
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/zsh/_hg	Mon Nov 30 21:54:34 2009 +0100
@@ -0,0 +1,951 @@
+#compdef hg
+
+# Zsh completion script for mercurial.  Rename this file to _hg and copy
+# it into your zsh function path (/usr/share/zsh/site-functions for
+# instance)
+#
+# If you do not want to install it globally, you can copy it somewhere
+# else and add that directory to $fpath. This must be done before
+# compinit is called. If the file is copied to ~/.zsh.d, your ~/.zshrc
+# file could look like this:
+#
+# fpath=("$HOME/.zsh.d" $fpath)
+# autoload -U compinit
+# compinit
+#
+# Copyright (C) 2005, 2006 Steve Borho <steve@borho.org>
+# Copyright (C) 2006-9 Brendan Cully <brendan@kublai.com>
+#
+# Permission is hereby granted, without written agreement and without
+# licence or royalty fees, to use, copy, modify, and distribute this
+# software and to distribute modified versions of this software for any
+# purpose, provided that the above copyright notice and the following
+# two paragraphs appear in all copies of this software.
+#
+# In no event shall the authors be liable to any party for direct,
+# indirect, special, incidental, or consequential damages arising out of
+# the use of this software and its documentation, even if the authors
+# have been advised of the possibility of such damage.
+#
+# The authors specifically disclaim any warranties, including, but not
+# limited to, the implied warranties of merchantability and fitness for
+# a particular purpose.  The software provided hereunder is on an "as
+# is" basis, and the authors have no obligation to provide maintenance,
+# support, updates, enhancements, or modifications.
+
+emulate -LR zsh
+setopt extendedglob
+
+local curcontext="$curcontext" state line
+typeset -A _hg_cmd_globals
+
+_hg() {
+  local cmd _hg_root
+  integer i=2
+  _hg_cmd_globals=()
+
+  while (( i < $#words ))
+  do
+    case "$words[$i]" in
+      -R|--repository)
+        eval _hg_root="$words[$i+1]"
+        _hg_cmd_globals+=("$words[$i]" "$_hg_root")
+        (( i += 2 ))
+        continue
+      ;;
+      -R*)
+        _hg_cmd_globals+="$words[$i]"
+        eval _hg_root="${words[$i]#-R}"
+       (( i++ ))
+       continue
+      ;;
+      --cwd|--config)
+        # pass along arguments to hg completer
+        _hg_cmd_globals+=("$words[$i]" "$words[$i+1]")
+        (( i += 2 ))
+        continue
+      ;;
+      -*)
+        # skip option
+        (( i++ ))
+        continue
+      ;;
+    esac
+    if [[ -z "$cmd" ]]
+    then
+      cmd="$words[$i]"
+      words[$i]=()
+      (( CURRENT-- ))
+    fi
+    (( i++ ))
+  done
+
+  if [[ -z "$cmd" ]]
+  then
+    _arguments -s -w : $_hg_global_opts \
+    ':mercurial command:_hg_commands'
+    return
+  fi
+
+  # resolve abbreviations and aliases
+  if ! (( $+functions[_hg_cmd_${cmd}] ))
+  then
+    local cmdexp
+    (( $#_hg_cmd_list )) || _hg_get_commands
+
+    cmdexp=$_hg_cmd_list[(r)${cmd}*]
+    if [[ $cmdexp == $_hg_cmd_list[(R)${cmd}*] ]]
+    then
+      # might be nice to rewrite the command line with the expansion
+      cmd="$cmdexp"
+    fi
+    if [[ -n $_hg_alias_list[$cmd] ]]
+    then
+      cmd=$_hg_alias_list[$cmd]
+    fi
+  fi
+
+  curcontext="${curcontext%:*:*}:hg-${cmd}:"
+
+  zstyle -s ":completion:$curcontext:" cache-policy update_policy
+
+  if [[ -z "$update_policy" ]]
+  then
+    zstyle ":completion:$curcontext:" cache-policy _hg_cache_policy
+  fi
+
+  if (( $+functions[_hg_cmd_${cmd}] ))
+  then
+    _hg_cmd_${cmd}
+  else
+    # complete unknown commands normally
+    _arguments -s -w : $_hg_global_opts \
+      '*:files:_hg_files'
+  fi
+}
+
+_hg_cache_policy() {
+  typeset -a old
+
+  # cache for a minute
+  old=( "$1"(mm+10) )
+  (( $#old )) && return 0
+
+  return 1
+}
+
+_hg_get_commands() {
+  typeset -ga _hg_cmd_list
+  typeset -gA _hg_alias_list
+  local hline cmd cmdalias
+
+  _call_program hg hg debugcomplete -v | while read -A hline
+  do
+    cmd=$hline[1]
+    _hg_cmd_list+=($cmd)
+
+    for cmdalias in $hline[2,-1]
+    do
+      _hg_cmd_list+=($cmdalias)
+      _hg_alias_list+=($cmdalias $cmd)
+    done
+  done
+}
+
+_hg_commands() {
+  (( $#_hg_cmd_list )) || _hg_get_commands
+  _describe -t commands 'mercurial command' _hg_cmd_list
+}
+
+_hg_revrange() {
+  compset -P 1 '*:'
+  _hg_tags "$@"
+}
+
+_hg_tags() {
+  typeset -a tags
+  local tag rev
+
+  _hg_cmd tags | while read tag
+  do
+    tags+=(${tag/ #    [0-9]#:*})
+  done
+  (( $#tags )) && _describe -t tags 'tags' tags
+}
+
+# likely merge candidates
+_hg_mergerevs() {
+  typeset -a heads
+  local myrev
+
+  heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"})
+  # exclude own revision
+  myrev=$(_hg_cmd log -r . --template '{rev}\\n')
+  heads=(${heads:#$myrev})
+
+  (( $#heads )) && _describe -t heads 'heads' heads
+}
+
+_hg_files() {
+  if [[ -n "$_hg_root" ]]
+  then
+    [[ -d "$_hg_root/.hg" ]] || return
+    case "$_hg_root" in
+      /*)
+        _files -W $_hg_root
+      ;;
+      *)
+        _files -W $PWD/$_hg_root
+      ;;
+    esac
+  else
+    _files
+  fi
+}
+
+_hg_status() {
+  [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
+  status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"})
+}
+
+_hg_unknown() {
+  typeset -a status_files
+  _hg_status u
+  _wanted files expl 'unknown files' _multi_parts / status_files
+}
+
+_hg_missing() {
+  typeset -a status_files
+  _hg_status d
+  _wanted files expl 'missing files' _multi_parts / status_files
+}
+
+_hg_modified() {
+  typeset -a status_files
+  _hg_status m
+  _wanted files expl 'modified files' _multi_parts / status_files
+}
+
+_hg_resolve() {
+  local rstate rpath
+
+  [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
+
+  _hg_cmd resolve -l ./$PREFIX | while read rstate rpath
+  do
+    [[ $rstate == 'R' ]] && resolved_files+=($rpath)
+    [[ $rstate == 'U' ]] && unresolved_files+=($rpath)
+  done
+}
+
+_hg_resolved() {
+  typeset -a resolved_files unresolved_files
+  _hg_resolve
+  _wanted files expl 'resolved files' _multi_parts / resolved_files
+}
+
+_hg_unresolved() {
+  typeset -a resolved_files unresolved_files
+  _hg_resolve
+  _wanted files expl 'unresolved files' _multi_parts / unresolved_files
+}
+
+_hg_config() {
+    typeset -a items
+    items=(${${(%f)"$(_call_program hg hg showconfig)"}%%\=*})
+    (( $#items )) && _describe -t config 'config item' items
+}
+
+_hg_addremove() {
+  _alternative 'files:unknown files:_hg_unknown' \
+    'files:missing files:_hg_missing'
+}
+
+_hg_ssh_urls() {
+  if [[ -prefix */ ]]
+  then
+    if zstyle -T ":completion:${curcontext}:files" remote-access
+    then
+      local host=${PREFIX%%/*}
+      typeset -a remdirs
+      compset -p $(( $#host + 1 ))
+      local rempath=${(M)PREFIX##*/}
+      local cacheid="hg:${host}-${rempath//\//_}"
+      cacheid=${cacheid%[-_]}
+      compset -P '*/'
+      if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
+      then
+        remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}")"}##*/}%/})
+        _store_cache "$cacheid" remdirs
+      fi
+      _describe -t directories 'remote directory' remdirs -S/
+    else
+      _message 'remote directory'
+    fi
+  else
+    if compset -P '*@'
+    then
+      _hosts -S/
+    else
+      _alternative 'hosts:remote host name:_hosts -S/' \
+        'users:user:_users -S@'
+    fi
+  fi
+}
+
+_hg_urls() {
+  if compset -P bundle://
+  then
+    _files
+  elif compset -P ssh://
+  then
+    _hg_ssh_urls
+  elif [[ -prefix *: ]]
+  then
+    _urls
+  else
+    local expl
+    compset -S '[^:]*'
+    _wanted url-schemas expl 'URL schema' compadd -S '' - \
+      http:// https:// ssh:// bundle://
+  fi
+}
+
+_hg_paths() {
+  typeset -a paths pnames
+  _hg_cmd paths | while read -A pnames
+  do
+    paths+=($pnames[1])
+  done
+  (( $#paths )) && _describe -t path-aliases 'repository alias' paths
+}
+
+_hg_remote() {
+  _alternative 'path-aliases:repository alias:_hg_paths' \
+    'directories:directory:_files -/' \
+    'urls:URL:_hg_urls'
+}
+
+_hg_clone_dest() {
+  _alternative 'directories:directory:_files -/' \
+    'urls:URL:_hg_urls'
+}
+
+# Common options
+_hg_global_opts=(
+    '(--repository -R)'{-R+,--repository}'[repository root directory]:repository:_files -/'
+    '--cwd[change working directory]:new working directory:_files -/'
+    '(--noninteractive -y)'{-y,--noninteractive}'[do not prompt, assume yes for any required answers]'
+    '(--verbose -v)'{-v,--verbose}'[enable additional output]'
+    '*--config[set/override config option]:defined config items:_hg_config'
+    '(--quiet -q)'{-q,--quiet}'[suppress output]'
+    '(--help -h)'{-h,--help}'[display help and exit]'
+    '--debug[debug mode]'
+    '--debugger[start debugger]'
+    '--encoding[set the charset encoding (default: UTF8)]'
+    '--encodingmode[set the charset encoding mode (default: strict)]'
+    '--lsprof[print improved command execution profile]'
+    '--traceback[print traceback on exception]'
+    '--time[time how long the command takes]'
+    '--profile[profile]'
+    '--version[output version information and exit]'
+)
+
+_hg_pat_opts=(
+  '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
+  '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
+
+_hg_diff_opts=(
+  '(--text -a)'{-a,--text}'[treat all files as text]'
+  '(--git -g)'{-g,--git}'[use git extended diff format]'
+  "--nodates[don't include dates in diff headers]")
+
+_hg_dryrun_opts=(
+  '(--dry-run -n)'{-n,--dry-run}'[do not perform actions, just print output]')
+
+_hg_style_opts=(
+  '--style[display using template map file]:'
+  '--template[display with template]:')
+
+_hg_commit_opts=(
+  '(-m --message -l --logfile --edit -e)'{-e,--edit}'[edit commit message]'
+  '(-e --edit -l --logfile --message -m)'{-m+,--message}'[use <text> as commit message]:message:'
+  '(-e --edit -m --message --logfile -l)'{-l+,--logfile}'[read the commit message from <file>]:log file:_files')
+
+_hg_remote_opts=(
+  '(--ssh -e)'{-e+,--ssh}'[specify ssh command to use]:'
+  '--remotecmd[specify hg command to run on the remote side]:')
+
+_hg_cmd() {
+  _call_program hg hg --config ui.verbose=0 --config defaults."$1"= \
+    "$_hg_cmd_globals[@]" "$@" 2> /dev/null
+}
+
+_hg_cmd_add() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
+  '*:unknown files:_hg_unknown'
+}
+
+_hg_cmd_addremove() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
+  '(--similarity -s)'{-s+,--similarity}'[guess renamed files by similarity (0<=s<=100)]:' \
+  '*:unknown or missing files:_hg_addremove'
+}
+
+_hg_cmd_annotate() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '(--rev -r)'{-r+,--rev}'[annotate the specified revision]:revision:_hg_tags' \
+  '(--follow -f)'{-f,--follow}'[follow file copies and renames]' \
+  '(--text -a)'{-a,--text}'[treat all files as text]' \
+  '(--user -u)'{-u,--user}'[list the author]' \
+  '(--date -d)'{-d,--date}'[list the date]' \
+  '(--number -n)'{-n,--number}'[list the revision number (default)]' \
+  '(--changeset -c)'{-c,--changeset}'[list the changeset]' \
+  '*:files:_hg_files'
+}
+
+_hg_cmd_archive() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '--no-decode[do not pass files through decoders]' \
+  '(--prefix -p)'{-p+,--prefix}'[directory prefix for files in archive]:' \
+  '(--rev -r)'{-r+,--rev}'[revision to distribute]:revision:_hg_tags' \
+  '(--type -t)'{-t+,--type}'[type of distribution to create]:archive type:(files tar tbz2 tgz uzip zip)' \
+  '*:destination:_files'
+}
+
+_hg_cmd_backout() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+    '--merge[merge with old dirstate parent after backout]' \
+    '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
+    '--parent[parent to choose when backing out merge]' \
+    '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
+    '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
+    '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
+    '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt'
+}
+
+_hg_cmd_bisect() {
+  _arguments -s -w : $_hg_global_opts \
+  '(-)'{-r,--reset}'[reset bisect state]' \
+  '(--good -g --bad -b --skip -s --reset -r)'{-g,--good}'[mark changeset good]'::revision:_hg_tags \
+  '(--good -g --bad -b --skip -s --reset -r)'{-b,--bad}'[mark changeset bad]'::revision:_hg_tags \
+  '(--good -g --bad -b --skip -s --reset -r)'{-s,--skip}'[skip testing changeset]' \
+  '(--command -c --noupdate -U)'{-c+,--command}'[use command to check changeset state]':commands:_command_names \
+  '(--command -c --noupdate -U)'{-U,--noupdate}'[do not update to target]'
+}
+
+_hg_cmd_branch() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--force -f)'{-f,--force}'[set branch name even if it shadows an existing branch]' \
+  '(--clean -C)'{-C,--clean}'[reset branch name to parent branch name]'
+}
+
+_hg_cmd_branches() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--active -a)'{-a,--active}'[show only branches that have unmerge heads]'
+}
+
+_hg_cmd_bundle() {
+  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
+  '(--force -f)'{-f,--force}'[run even when remote repository is unrelated]' \
+  '(2)*--base[a base changeset to specify instead of a destination]:revision:_hg_tags' \
+  ':output file:_files' \
+  ':destination repository:_files -/'
+}
+
+_hg_cmd_cat() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '(--output -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
+  '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
+  '*:file:_hg_files'
+}
+
+_hg_cmd_clone() {
+  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
+  '(--noupdate -U)'{-U,--noupdate}'[do not update the new working directory]' \
+  '(--rev -r)'{-r+,--rev}'[a changeset you would like to have after cloning]:' \
+  '--uncompressed[use uncompressed transfer (fast over LAN)]' \
+  ':source repository:_hg_remote' \
+  ':destination:_hg_clone_dest'
+}
+
+_hg_cmd_commit() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]' \
+  '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
+  '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt' \
+  '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
+  '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
+  '*:file:_hg_files'
+}
+
+_hg_cmd_copy() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
+  '(--after -A)'{-A,--after}'[record a copy that has already occurred]' \
+  '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
+  '*:file:_hg_files'
+}
+
+_hg_cmd_diff() {
+  typeset -A opt_args
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_diff_opts \
+  '*'{-r,--rev}'+[revision]:revision:_hg_revrange' \
+  '(--show-function -p)'{-p,--show-function}'[show which function each change is in]' \
+  '(--ignore-all-space -w)'{-w,--ignore-all-space}'[ignore white space when comparing lines]' \
+  '(--ignore-space-change -b)'{-b,--ignore-space-change}'[ignore changes in the amount of white space]' \
+  '(--ignore-blank-lines -B)'{-B,--ignore-blank-lines}'[ignore changes whose lines are all blank]' \
+  '*:file:->diff_files'
+
+  if [[ $state == 'diff_files' ]]
+  then
+    if [[ -n $opt_args[-r] ]]
+    then
+      _hg_files
+    else
+      _hg_modified
+    fi
+  fi
+}
+
+_hg_cmd_export() {
+  _arguments -s -w : $_hg_global_opts $_hg_diff_opts \
+  '(--outout -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
+  '--switch-parent[diff against the second parent]' \
+  '*:revision:_hg_tags'
+}
+
+_hg_cmd_grep() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '(--print0 -0)'{-0,--print0}'[end filenames with NUL]' \
+  '--all[print all revisions with matches]' \
+  '(--follow -f)'{-f,--follow}'[follow changeset or file history]' \
+  '(--ignore-case -i)'{-i,--ignore-case}'[ignore case when matching]' \
+  '(--files-with-matches -l)'{-l,--files-with-matches}'[print only filenames and revs that match]' \
+  '(--line-number -n)'{-n,--line-number}'[print matching line numbers]' \
+  '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \
+  '(--user -u)'{-u,--user}'[print user who committed change]' \
+  '1:search pattern:' \
+  '*:files:_hg_files'
+}
+
+_hg_cmd_heads() {
+  _arguments -s -w : $_hg_global_opts $_hg_style_opts \
+  '(--rev -r)'{-r+,--rev}'[show only heads which are descendants of rev]:revision:_hg_tags'
+}
+
+_hg_cmd_help() {
+  _arguments -s -w : $_hg_global_opts \
+  '*:mercurial command:_hg_commands'
+}
+
+_hg_cmd_identify() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--rev -r)'{-r+,--rev}'[identify the specified rev]:revision:_hg_tags' \
+  '(--num -n)'{-n+,--num}'[show local revision number]' \
+  '(--id -i)'{-i+,--id}'[show global revision id]' \
+  '(--branch -b)'{-b+,--branch}'[show branch]' \
+  '(--tags -t)'{-t+,--tags}'[show tags]'
+}
+
+_hg_cmd_import() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--strip -p)'{-p+,--strip}'[directory strip option for patch (default: 1)]:count:' \
+  '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
+  '(--force -f)'{-f,--force}'[skip check for outstanding uncommitted changes]' \
+  '*:patch:_files'
+}
+
+_hg_cmd_incoming() {
+  _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
+  '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
+  '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
+  '(--patch -p)'{-p,--patch}'[show patch]' \
+  '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:_hg_tags' \
+  '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
+  '--bundle[file to store the bundles into]:bundle file:_files' \
+  ':source:_hg_remote'
+}
+
+_hg_cmd_init() {
+  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
+  ':dir:_files -/'
+}
+
+_hg_cmd_locate() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '(--rev -r)'{-r+,--rev}'[search repository as it stood at revision]:revision:_hg_tags' \
+  '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
+  '(--fullpath -f)'{-f,--fullpath}'[print complete paths]' \
+  '*:search pattern:_hg_files'
+}
+
+_hg_cmd_log() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_style_opts \
+  '(--follow --follow-first -f)'{-f,--follow}'[follow changeset or history]' \
+  '(-f --follow)--follow-first[only follow the first parent of merge changesets]' \
+  '(--copies -C)'{-C,--copies}'[show copied files]' \
+  '(--keyword -k)'{-k+,--keyword}'[search for a keyword]:' \
+  '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
+  '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
+  '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
+  '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
+  '(--patch -p)'{-p,--patch}'[show patch]' \
+  '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_tags' \
+  '*:files:_hg_files'
+}
+
+_hg_cmd_manifest() {
+  _arguments -s -w : $_hg_global_opts \
+  ':revision:_hg_tags'
+}
+
+_hg_cmd_merge() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--force -f)'{-f,--force}'[force a merge with outstanding changes]' \
+  '(--rev -r 1)'{-r,--rev}'[revision to merge]:revision:_hg_mergerevs' \
+  '(--preview -P)'{-P,--preview}'[review revisions to merge (no merge is performed)]' \
+  ':revision:_hg_mergerevs'
+}
+
+_hg_cmd_outgoing() {
+  _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
+  '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
+  '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
+  '(--patch -p)'{-p,--patch}'[show patch]' \
+  '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]' \
+  '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
+  ':destination:_hg_remote'
+}
+
+_hg_cmd_parents() {
+  _arguments -s -w : $_hg_global_opts $_hg_style_opts \
+  '(--rev -r)'{-r+,--rev}'[show parents of the specified rev]:revision:_hg_tags' \
+  ':last modified file:_hg_files'
+}
+
+_hg_cmd_paths() {
+  _arguments -s -w : $_hg_global_opts \
+  ':path:_hg_paths'
+}
+
+_hg_cmd_pull() {
+  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
+  '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
+  '(--update -u)'{-u,--update}'[update to new tip if changesets were pulled]' \
+  '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:' \
+  ':source:_hg_remote'
+}
+
+_hg_cmd_push() {
+  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
+  '(--force -f)'{-f,--force}'[force push]' \
+  '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]:revision:_hg_tags' \
+  ':destination:_hg_remote'
+}
+
+_hg_cmd_remove() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '(--after -A)'{-A,--after}'[record remove that has already occurred]' \
+  '(--force -f)'{-f,--force}'[remove file even if modified]' \
+  '*:file:_hg_files'
+}
+
+_hg_cmd_rename() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
+  '(--after -A)'{-A,--after}'[record a rename that has already occurred]' \
+  '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
+  '*:file:_hg_files'
+}
+
+_hg_cmd_resolve() {
+  local context state line
+  typeset -A opt_args
+
+  _arguments -s -w : $_hg_global_opts \
+  '(--list -l --mark -m --unmark -u)'{-l,--list}'[list state of files needing merge]:*:merged files:->resolve_files' \
+  '(--mark -m --list -l --unmark -u)'{-m,--mark}'[mark files as resolved]:*:unresolved files:_hg_unresolved' \
+  '(--unmark -u --list -l --mark -m)'{-u,--unmark}'[unmark files as resolved]:*:resolved files:_hg_resolved' \
+  '*:file:_hg_unresolved'
+
+  if [[ $state == 'resolve_files' ]]
+  then
+    _alternative 'files:resolved files:_hg_resolved' \
+      'files:unresolved files:_hg_unresolved'
+  fi
+}
+
+_hg_cmd_revert() {
+  local context state line
+  typeset -A opt_args
+
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
+  '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
+  '(--rev -r)'{-r+,--rev}'[revision to revert to]:revision:_hg_tags' \
+  '--no-backup[do not save backup copies of files]' \
+  '*:file:->diff_files'
+
+  if [[ $state == 'diff_files' ]]
+  then
+    if [[ -n $opt_args[-r] ]]
+    then
+      _hg_files
+    else
+      typeset -a status_files
+      _hg_status mard
+      _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files
+    fi
+  fi
+}
+
+_hg_cmd_serve() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--accesslog -A)'{-A+,--accesslog}'[name of access log file]:log file:_files' \
+  '(--errorlog -E)'{-E+,--errorlog}'[name of error log file]:log file:_files' \
+  '(--daemon -d)'{-d,--daemon}'[run server in background]' \
+  '(--port -p)'{-p+,--port}'[listen port]:listen port:' \
+  '(--address -a)'{-a+,--address}'[interface address]:interface address:' \
+  '(--name -n)'{-n+,--name}'[name to show in web pages]:repository name:' \
+  '(--templates -t)'{-t,--templates}'[web template directory]:template dir:_files -/' \
+  '--style[web template style]:style' \
+  '--stdio[for remote clients]' \
+  '(--ipv6 -6)'{-6,--ipv6}'[use IPv6 in addition to IPv4]'
+}
+
+_hg_cmd_showconfig() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--untrusted -u)'{-u+,--untrusted}'[show untrusted configuration options]' \
+  ':config item:_hg_config'
+}
+
+_hg_cmd_status() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '(--all -A)'{-A,--all}'[show status of all files]' \
+  '(--modified -m)'{-m,--modified}'[show only modified files]' \
+  '(--added -a)'{-a,--added}'[show only added files]' \
+  '(--removed -r)'{-r,--removed}'[show only removed files]' \
+  '(--deleted -d)'{-d,--deleted}'[show only deleted (but tracked) files]' \
+  '(--clean -c)'{-c,--clean}'[show only files without changes]' \
+  '(--unknown -u)'{-u,--unknown}'[show only unknown files]' \
+  '(--ignored -i)'{-i,--ignored}'[show ignored files]' \
+  '(--no-status -n)'{-n,--no-status}'[hide status prefix]' \
+  '(--copies -C)'{-C,--copies}'[show source of copied files]' \
+  '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
+  '--rev[show difference from revision]:revision:_hg_tags' \
+  '*:files:_files'
+}
+
+_hg_cmd_summary() {
+  _arguments -s -w : $_hg_global_opts \
+  '--remote[check for push and pull]'
+}
+
+_hg_cmd_tag() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--local -l)'{-l,--local}'[make the tag local]' \
+  '(--message -m)'{-m+,--message}'[message for tag commit log entry]:message:' \
+  '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
+  '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
+  '(--rev -r)'{-r+,--rev}'[revision to tag]:revision:_hg_tags' \
+  ':tag name:'
+}
+
+_hg_cmd_tip() {
+  _arguments -s -w : $_hg_global_opts $_hg_style_opts \
+  '(--patch -p)'{-p,--patch}'[show patch]'
+}
+
+_hg_cmd_unbundle() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--update -u)'{-u,--update}'[update to new tip if changesets were unbundled]' \
+  ':files:_files'
+}
+
+_hg_cmd_update() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--clean -C)'{-C,--clean}'[overwrite locally modified files]' \
+  '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
+  ':revision:_hg_tags'
+}
+
+# HGK
+_hg_cmd_view() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
+  ':revision range:_hg_tags'
+}
+
+# MQ
+_hg_qseries() {
+  typeset -a patches
+  patches=(${(f)"$(_hg_cmd qseries)"})
+  (( $#patches )) && _describe -t hg-patches 'patches' patches
+}
+
+_hg_qapplied() {
+  typeset -a patches
+  patches=(${(f)"$(_hg_cmd qapplied)"})
+  if (( $#patches ))
+  then
+    patches+=(qbase qtip)
+    _describe -t hg-applied-patches 'applied patches' patches
+  fi
+}
+
+_hg_qunapplied() {
+  typeset -a patches
+  patches=(${(f)"$(_hg_cmd qunapplied)"})
+  (( $#patches )) && _describe -t hg-unapplied-patches 'unapplied patches' patches
+}
+
+# unapplied, including guarded patches
+_hg_qdeletable() {
+  typeset -a unapplied
+  unapplied=(${(f)"$(_hg_cmd qseries)"})
+  for p in $(_hg_cmd qapplied)
+  do
+    unapplied=(${unapplied:#$p})
+  done
+
+  (( $#unapplied )) && _describe -t hg-allunapplied-patches 'all unapplied patches' unapplied
+}
+
+_hg_qguards() {
+  typeset -a guards
+  local guard
+  compset -P "+|-"
+  _hg_cmd qselect -s | while read guard
+  do
+    guards+=(${guard#(+|-)})
+  done
+  (( $#guards )) && _describe -t hg-guards 'guards' guards
+}
+
+_hg_qseries_opts=(
+  '(--summary -s)'{-s,--summary}'[print first line of patch header]')
+
+_hg_cmd_qapplied() {
+  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
+}
+
+_hg_cmd_qdelete() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--keep -k)'{-k,--keep}'[keep patch file]' \
+  '*'{-r+,--rev}'[stop managing a revision]:applied patch:_hg_revrange' \
+  '*:unapplied patch:_hg_qdeletable'
+}
+
+_hg_cmd_qdiff() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
+  '*:pattern:_hg_files'
+}
+
+_hg_cmd_qfold() {
+  _arguments -s -w : $_hg_global_opts $_h_commit_opts \
+  '(--keep,-k)'{-k,--keep}'[keep folded patch files]' \
+  '*:unapplied patch:_hg_qunapplied'
+}
+
+_hg_cmd_qgoto() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--force -f)'{-f,--force}'[overwrite any local changes]' \
+  ':patch:_hg_qseries'
+}
+
+_hg_cmd_qguard() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--list -l)'{-l,--list}'[list all patches and guards]' \
+  '(--none -n)'{-n,--none}'[drop all guards]' \
+  ':patch:_hg_qseries' \
+  '*:guards:_hg_qguards'
+}
+
+_hg_cmd_qheader() {
+  _arguments -s -w : $_hg_global_opts \
+  ':patch:_hg_qseries'
+}
+
+_hg_cmd_qimport() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--existing -e)'{-e,--existing}'[import file in patch dir]' \
+  '(--name -n 2)'{-n+,--name}'[patch file name]:name:' \
+  '(--force -f)'{-f,--force}'[overwrite existing files]' \
+  '*'{-r+,--rev}'[place existing revisions under mq control]:revision:_hg_revrange' \
+  '*:patch:_files'
+}
+
+_hg_cmd_qnew() {
+  _arguments -s -w : $_hg_global_opts $_hg_commit_opts \
+  '(--force -f)'{-f,--force}'[import uncommitted changes into patch]' \
+  ':patch:'
+}
+
+_hg_cmd_qnext() {
+  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
+}
+
+_hg_cmd_qpop() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--all -a :)'{-a,--all}'[pop all patches]' \
+  '(--name -n)'{-n+,--name}'[queue name to pop]:' \
+  '(--force -f)'{-f,--force}'[forget any local changes]' \
+  ':patch:_hg_qapplied'
+}
+
+_hg_cmd_qprev() {
+  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
+}
+
+_hg_cmd_qpush() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--all -a :)'{-a,--all}'[apply all patches]' \
+  '(--list -l)'{-l,--list}'[list patch name in commit text]' \
+  '(--merge -m)'{-m+,--merge}'[merge from another queue]:' \
+  '(--name -n)'{-n+,--name}'[merge queue name]:' \
+  '(--force -f)'{-f,--force}'[apply if the patch has rejects]' \
+  ':patch:_hg_qunapplied'
+}
+
+_hg_cmd_qrefresh() {
+  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_commit_opts \
+  '(--git -g)'{-g,--git}'[use git extended diff format]' \
+  '(--short -s)'{-s,--short}'[short refresh]' \
+  '*:files:_hg_files'
+}
+
+_hg_cmd_qrename() {
+  _arguments -s -w : $_hg_global_opts \
+  ':patch:_hg_qseries' \
+  ':destination:'
+}
+
+_hg_cmd_qselect() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--none -n :)'{-n,--none}'[disable all guards]' \
+  '(--series -s :)'{-s,--series}'[list all guards in series file]' \
+  '--pop[pop to before first guarded applied patch]' \
+  '--reapply[pop and reapply patches]' \
+  '*:guards:_hg_qguards'
+}
+
+_hg_cmd_qseries() {
+  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts \
+  '(--missing -m)'{-m,--missing}'[print patches not in series]'
+}
+
+_hg_cmd_qunapplied() {
+  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
+}
+
+_hg_cmd_qtop() {
+  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
+}
+
+_hg_cmd_strip() {
+  _arguments -s -w : $_hg_global_opts \
+  '(--force -f)'{-f,--force}'[force multi-head removal]' \
+  '(--backup -b)'{-b,--backup}'[bundle unrelated changesets]' \
+  '(--nobackup -n)'{-n,--nobackup}'[no backups]' \
+  ':revision:_hg_tags'
+}
+
+_hg "$@"
--- a/contrib/zsh_completion	Mon Nov 30 23:10:21 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,951 +0,0 @@
-#compdef hg
-
-# Zsh completion script for mercurial.  Rename this file to _hg and copy
-# it into your zsh function path (/usr/share/zsh/site-functions for
-# instance)
-#
-# If you do not want to install it globally, you can copy it somewhere
-# else and add that directory to $fpath. This must be done before
-# compinit is called. If the file is copied to ~/.zsh.d, your ~/.zshrc
-# file could look like this:
-#
-# fpath=("$HOME/.zsh.d" $fpath)
-# autoload -U compinit
-# compinit
-#
-# Copyright (C) 2005, 2006 Steve Borho <steve@borho.org>
-# Copyright (C) 2006-9 Brendan Cully <brendan@kublai.com>
-#
-# Permission is hereby granted, without written agreement and without
-# licence or royalty fees, to use, copy, modify, and distribute this
-# software and to distribute modified versions of this software for any
-# purpose, provided that the above copyright notice and the following
-# two paragraphs appear in all copies of this software.
-#
-# In no event shall the authors be liable to any party for direct,
-# indirect, special, incidental, or consequential damages arising out of
-# the use of this software and its documentation, even if the authors
-# have been advised of the possibility of such damage.
-#
-# The authors specifically disclaim any warranties, including, but not
-# limited to, the implied warranties of merchantability and fitness for
-# a particular purpose.  The software provided hereunder is on an "as
-# is" basis, and the authors have no obligation to provide maintenance,
-# support, updates, enhancements, or modifications.
-
-emulate -LR zsh
-setopt extendedglob
-
-local curcontext="$curcontext" state line
-typeset -A _hg_cmd_globals
-
-_hg() {
-  local cmd _hg_root
-  integer i=2
-  _hg_cmd_globals=()
-
-  while (( i < $#words ))
-  do
-    case "$words[$i]" in
-      -R|--repository)
-        eval _hg_root="$words[$i+1]"
-        _hg_cmd_globals+=("$words[$i]" "$_hg_root")
-        (( i += 2 ))
-        continue
-      ;;
-      -R*)
-        _hg_cmd_globals+="$words[$i]"
-        eval _hg_root="${words[$i]#-R}"
-       (( i++ ))
-       continue
-      ;;
-      --cwd|--config)
-        # pass along arguments to hg completer
-        _hg_cmd_globals+=("$words[$i]" "$words[$i+1]")
-        (( i += 2 ))
-        continue
-      ;;
-      -*)
-        # skip option
-        (( i++ ))
-        continue
-      ;;
-    esac
-    if [[ -z "$cmd" ]]
-    then
-      cmd="$words[$i]"
-      words[$i]=()
-      (( CURRENT-- ))
-    fi
-    (( i++ ))
-  done
-
-  if [[ -z "$cmd" ]]
-  then
-    _arguments -s -w : $_hg_global_opts \
-    ':mercurial command:_hg_commands'
-    return
-  fi
-
-  # resolve abbreviations and aliases
-  if ! (( $+functions[_hg_cmd_${cmd}] ))
-  then
-    local cmdexp
-    (( $#_hg_cmd_list )) || _hg_get_commands
-
-    cmdexp=$_hg_cmd_list[(r)${cmd}*]
-    if [[ $cmdexp == $_hg_cmd_list[(R)${cmd}*] ]]
-    then
-      # might be nice to rewrite the command line with the expansion
-      cmd="$cmdexp"
-    fi
-    if [[ -n $_hg_alias_list[$cmd] ]]
-    then
-      cmd=$_hg_alias_list[$cmd]
-    fi
-  fi
-
-  curcontext="${curcontext%:*:*}:hg-${cmd}:"
-
-  zstyle -s ":completion:$curcontext:" cache-policy update_policy
-
-  if [[ -z "$update_policy" ]]
-  then
-    zstyle ":completion:$curcontext:" cache-policy _hg_cache_policy
-  fi
-
-  if (( $+functions[_hg_cmd_${cmd}] ))
-  then
-    _hg_cmd_${cmd}
-  else
-    # complete unknown commands normally
-    _arguments -s -w : $_hg_global_opts \
-      '*:files:_hg_files'
-  fi
-}
-
-_hg_cache_policy() {
-  typeset -a old
-
-  # cache for a minute
-  old=( "$1"(mm+10) )
-  (( $#old )) && return 0
-
-  return 1
-}
-
-_hg_get_commands() {
-  typeset -ga _hg_cmd_list
-  typeset -gA _hg_alias_list
-  local hline cmd cmdalias
-
-  _call_program hg hg debugcomplete -v | while read -A hline
-  do
-    cmd=$hline[1]
-    _hg_cmd_list+=($cmd)
-
-    for cmdalias in $hline[2,-1]
-    do
-      _hg_cmd_list+=($cmdalias)
-      _hg_alias_list+=($cmdalias $cmd)
-    done
-  done
-}
-
-_hg_commands() {
-  (( $#_hg_cmd_list )) || _hg_get_commands
-  _describe -t commands 'mercurial command' _hg_cmd_list
-}
-
-_hg_revrange() {
-  compset -P 1 '*:'
-  _hg_tags "$@"
-}
-
-_hg_tags() {
-  typeset -a tags
-  local tag rev
-
-  _hg_cmd tags | while read tag
-  do
-    tags+=(${tag/ #    [0-9]#:*})
-  done
-  (( $#tags )) && _describe -t tags 'tags' tags
-}
-
-# likely merge candidates
-_hg_mergerevs() {
-  typeset -a heads
-  local myrev
-
-  heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"})
-  # exclude own revision
-  myrev=$(_hg_cmd log -r . --template '{rev}\\n')
-  heads=(${heads:#$myrev})
-
-  (( $#heads )) && _describe -t heads 'heads' heads
-}
-
-_hg_files() {
-  if [[ -n "$_hg_root" ]]
-  then
-    [[ -d "$_hg_root/.hg" ]] || return
-    case "$_hg_root" in
-      /*)
-        _files -W $_hg_root
-      ;;
-      *)
-        _files -W $PWD/$_hg_root
-      ;;
-    esac
-  else
-    _files
-  fi
-}
-
-_hg_status() {
-  [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
-  status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"})
-}
-
-_hg_unknown() {
-  typeset -a status_files
-  _hg_status u
-  _wanted files expl 'unknown files' _multi_parts / status_files
-}
-
-_hg_missing() {
-  typeset -a status_files
-  _hg_status d
-  _wanted files expl 'missing files' _multi_parts / status_files
-}
-
-_hg_modified() {
-  typeset -a status_files
-  _hg_status m
-  _wanted files expl 'modified files' _multi_parts / status_files
-}
-
-_hg_resolve() {
-  local rstate rpath
-
-  [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
-
-  _hg_cmd resolve -l ./$PREFIX | while read rstate rpath
-  do
-    [[ $rstate == 'R' ]] && resolved_files+=($rpath)
-    [[ $rstate == 'U' ]] && unresolved_files+=($rpath)
-  done
-}
-
-_hg_resolved() {
-  typeset -a resolved_files unresolved_files
-  _hg_resolve
-  _wanted files expl 'resolved files' _multi_parts / resolved_files
-}
-
-_hg_unresolved() {
-  typeset -a resolved_files unresolved_files
-  _hg_resolve
-  _wanted files expl 'unresolved files' _multi_parts / unresolved_files
-}
-
-_hg_config() {
-    typeset -a items
-    items=(${${(%f)"$(_call_program hg hg showconfig)"}%%\=*})
-    (( $#items )) && _describe -t config 'config item' items
-}
-
-_hg_addremove() {
-  _alternative 'files:unknown files:_hg_unknown' \
-    'files:missing files:_hg_missing'
-}
-
-_hg_ssh_urls() {
-  if [[ -prefix */ ]]
-  then
-    if zstyle -T ":completion:${curcontext}:files" remote-access
-    then
-      local host=${PREFIX%%/*}
-      typeset -a remdirs
-      compset -p $(( $#host + 1 ))
-      local rempath=${(M)PREFIX##*/}
-      local cacheid="hg:${host}-${rempath//\//_}"
-      cacheid=${cacheid%[-_]}
-      compset -P '*/'
-      if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
-      then
-        remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}")"}##*/}%/})
-        _store_cache "$cacheid" remdirs
-      fi
-      _describe -t directories 'remote directory' remdirs -S/
-    else
-      _message 'remote directory'
-    fi
-  else
-    if compset -P '*@'
-    then
-      _hosts -S/
-    else
-      _alternative 'hosts:remote host name:_hosts -S/' \
-        'users:user:_users -S@'
-    fi
-  fi
-}
-
-_hg_urls() {
-  if compset -P bundle://
-  then
-    _files
-  elif compset -P ssh://
-  then
-    _hg_ssh_urls
-  elif [[ -prefix *: ]]
-  then
-    _urls
-  else
-    local expl
-    compset -S '[^:]*'
-    _wanted url-schemas expl 'URL schema' compadd -S '' - \
-      http:// https:// ssh:// bundle://
-  fi
-}
-
-_hg_paths() {
-  typeset -a paths pnames
-  _hg_cmd paths | while read -A pnames
-  do
-    paths+=($pnames[1])
-  done
-  (( $#paths )) && _describe -t path-aliases 'repository alias' paths
-}
-
-_hg_remote() {
-  _alternative 'path-aliases:repository alias:_hg_paths' \
-    'directories:directory:_files -/' \
-    'urls:URL:_hg_urls'
-}
-
-_hg_clone_dest() {
-  _alternative 'directories:directory:_files -/' \
-    'urls:URL:_hg_urls'
-}
-
-# Common options
-_hg_global_opts=(
-    '(--repository -R)'{-R+,--repository}'[repository root directory]:repository:_files -/'
-    '--cwd[change working directory]:new working directory:_files -/'
-    '(--noninteractive -y)'{-y,--noninteractive}'[do not prompt, assume yes for any required answers]'
-    '(--verbose -v)'{-v,--verbose}'[enable additional output]'
-    '*--config[set/override config option]:defined config items:_hg_config'
-    '(--quiet -q)'{-q,--quiet}'[suppress output]'
-    '(--help -h)'{-h,--help}'[display help and exit]'
-    '--debug[debug mode]'
-    '--debugger[start debugger]'
-    '--encoding[set the charset encoding (default: UTF8)]'
-    '--encodingmode[set the charset encoding mode (default: strict)]'
-    '--lsprof[print improved command execution profile]'
-    '--traceback[print traceback on exception]'
-    '--time[time how long the command takes]'
-    '--profile[profile]'
-    '--version[output version information and exit]'
-)
-
-_hg_pat_opts=(
-  '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
-  '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
-
-_hg_diff_opts=(
-  '(--text -a)'{-a,--text}'[treat all files as text]'
-  '(--git -g)'{-g,--git}'[use git extended diff format]'
-  "--nodates[don't include dates in diff headers]")
-
-_hg_dryrun_opts=(
-  '(--dry-run -n)'{-n,--dry-run}'[do not perform actions, just print output]')
-
-_hg_style_opts=(
-  '--style[display using template map file]:'
-  '--template[display with template]:')
-
-_hg_commit_opts=(
-  '(-m --message -l --logfile --edit -e)'{-e,--edit}'[edit commit message]'
-  '(-e --edit -l --logfile --message -m)'{-m+,--message}'[use <text> as commit message]:message:'
-  '(-e --edit -m --message --logfile -l)'{-l+,--logfile}'[read the commit message from <file>]:log file:_files')
-
-_hg_remote_opts=(
-  '(--ssh -e)'{-e+,--ssh}'[specify ssh command to use]:'
-  '--remotecmd[specify hg command to run on the remote side]:')
-
-_hg_cmd() {
-  _call_program hg hg --config ui.verbose=0 --config defaults."$1"= \
-    "$_hg_cmd_globals[@]" "$@" 2> /dev/null
-}
-
-_hg_cmd_add() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
-  '*:unknown files:_hg_unknown'
-}
-
-_hg_cmd_addremove() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
-  '(--similarity -s)'{-s+,--similarity}'[guess renamed files by similarity (0<=s<=100)]:' \
-  '*:unknown or missing files:_hg_addremove'
-}
-
-_hg_cmd_annotate() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--rev -r)'{-r+,--rev}'[annotate the specified revision]:revision:_hg_tags' \
-  '(--follow -f)'{-f,--follow}'[follow file copies and renames]' \
-  '(--text -a)'{-a,--text}'[treat all files as text]' \
-  '(--user -u)'{-u,--user}'[list the author]' \
-  '(--date -d)'{-d,--date}'[list the date]' \
-  '(--number -n)'{-n,--number}'[list the revision number (default)]' \
-  '(--changeset -c)'{-c,--changeset}'[list the changeset]' \
-  '*:files:_hg_files'
-}
-
-_hg_cmd_archive() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '--no-decode[do not pass files through decoders]' \
-  '(--prefix -p)'{-p+,--prefix}'[directory prefix for files in archive]:' \
-  '(--rev -r)'{-r+,--rev}'[revision to distribute]:revision:_hg_tags' \
-  '(--type -t)'{-t+,--type}'[type of distribution to create]:archive type:(files tar tbz2 tgz uzip zip)' \
-  '*:destination:_files'
-}
-
-_hg_cmd_backout() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-    '--merge[merge with old dirstate parent after backout]' \
-    '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
-    '--parent[parent to choose when backing out merge]' \
-    '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
-    '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
-    '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
-    '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt'
-}
-
-_hg_cmd_bisect() {
-  _arguments -s -w : $_hg_global_opts \
-  '(-)'{-r,--reset}'[reset bisect state]' \
-  '(--good -g --bad -b --skip -s --reset -r)'{-g,--good}'[mark changeset good]'::revision:_hg_tags \
-  '(--good -g --bad -b --skip -s --reset -r)'{-b,--bad}'[mark changeset bad]'::revision:_hg_tags \
-  '(--good -g --bad -b --skip -s --reset -r)'{-s,--skip}'[skip testing changeset]' \
-  '(--command -c --noupdate -U)'{-c+,--command}'[use command to check changeset state]':commands:_command_names \
-  '(--command -c --noupdate -U)'{-U,--noupdate}'[do not update to target]'
-}
-
-_hg_cmd_branch() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--force -f)'{-f,--force}'[set branch name even if it shadows an existing branch]' \
-  '(--clean -C)'{-C,--clean}'[reset branch name to parent branch name]'
-}
-
-_hg_cmd_branches() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--active -a)'{-a,--active}'[show only branches that have unmerge heads]'
-}
-
-_hg_cmd_bundle() {
-  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
-  '(--force -f)'{-f,--force}'[run even when remote repository is unrelated]' \
-  '(2)*--base[a base changeset to specify instead of a destination]:revision:_hg_tags' \
-  ':output file:_files' \
-  ':destination repository:_files -/'
-}
-
-_hg_cmd_cat() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--output -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
-  '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
-  '*:file:_hg_files'
-}
-
-_hg_cmd_clone() {
-  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
-  '(--noupdate -U)'{-U,--noupdate}'[do not update the new working directory]' \
-  '(--rev -r)'{-r+,--rev}'[a changeset you would like to have after cloning]:' \
-  '--uncompressed[use uncompressed transfer (fast over LAN)]' \
-  ':source repository:_hg_remote' \
-  ':destination:_hg_clone_dest'
-}
-
-_hg_cmd_commit() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]' \
-  '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
-  '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt' \
-  '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
-  '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
-  '*:file:_hg_files'
-}
-
-_hg_cmd_copy() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
-  '(--after -A)'{-A,--after}'[record a copy that has already occurred]' \
-  '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
-  '*:file:_hg_files'
-}
-
-_hg_cmd_diff() {
-  typeset -A opt_args
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_diff_opts \
-  '*'{-r,--rev}'+[revision]:revision:_hg_revrange' \
-  '(--show-function -p)'{-p,--show-function}'[show which function each change is in]' \
-  '(--ignore-all-space -w)'{-w,--ignore-all-space}'[ignore white space when comparing lines]' \
-  '(--ignore-space-change -b)'{-b,--ignore-space-change}'[ignore changes in the amount of white space]' \
-  '(--ignore-blank-lines -B)'{-B,--ignore-blank-lines}'[ignore changes whose lines are all blank]' \
-  '*:file:->diff_files'
-
-  if [[ $state == 'diff_files' ]]
-  then
-    if [[ -n $opt_args[-r] ]]
-    then
-      _hg_files
-    else
-      _hg_modified
-    fi
-  fi
-}
-
-_hg_cmd_export() {
-  _arguments -s -w : $_hg_global_opts $_hg_diff_opts \
-  '(--outout -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
-  '--switch-parent[diff against the second parent]' \
-  '*:revision:_hg_tags'
-}
-
-_hg_cmd_grep() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--print0 -0)'{-0,--print0}'[end filenames with NUL]' \
-  '--all[print all revisions with matches]' \
-  '(--follow -f)'{-f,--follow}'[follow changeset or file history]' \
-  '(--ignore-case -i)'{-i,--ignore-case}'[ignore case when matching]' \
-  '(--files-with-matches -l)'{-l,--files-with-matches}'[print only filenames and revs that match]' \
-  '(--line-number -n)'{-n,--line-number}'[print matching line numbers]' \
-  '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \
-  '(--user -u)'{-u,--user}'[print user who committed change]' \
-  '1:search pattern:' \
-  '*:files:_hg_files'
-}
-
-_hg_cmd_heads() {
-  _arguments -s -w : $_hg_global_opts $_hg_style_opts \
-  '(--rev -r)'{-r+,--rev}'[show only heads which are descendants of rev]:revision:_hg_tags'
-}
-
-_hg_cmd_help() {
-  _arguments -s -w : $_hg_global_opts \
-  '*:mercurial command:_hg_commands'
-}
-
-_hg_cmd_identify() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--rev -r)'{-r+,--rev}'[identify the specified rev]:revision:_hg_tags' \
-  '(--num -n)'{-n+,--num}'[show local revision number]' \
-  '(--id -i)'{-i+,--id}'[show global revision id]' \
-  '(--branch -b)'{-b+,--branch}'[show branch]' \
-  '(--tags -t)'{-t+,--tags}'[show tags]'
-}
-
-_hg_cmd_import() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--strip -p)'{-p+,--strip}'[directory strip option for patch (default: 1)]:count:' \
-  '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
-  '(--force -f)'{-f,--force}'[skip check for outstanding uncommitted changes]' \
-  '*:patch:_files'
-}
-
-_hg_cmd_incoming() {
-  _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
-  '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
-  '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
-  '(--patch -p)'{-p,--patch}'[show patch]' \
-  '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:_hg_tags' \
-  '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
-  '--bundle[file to store the bundles into]:bundle file:_files' \
-  ':source:_hg_remote'
-}
-
-_hg_cmd_init() {
-  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
-  ':dir:_files -/'
-}
-
-_hg_cmd_locate() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--rev -r)'{-r+,--rev}'[search repository as it stood at revision]:revision:_hg_tags' \
-  '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
-  '(--fullpath -f)'{-f,--fullpath}'[print complete paths]' \
-  '*:search pattern:_hg_files'
-}
-
-_hg_cmd_log() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_style_opts \
-  '(--follow --follow-first -f)'{-f,--follow}'[follow changeset or history]' \
-  '(-f --follow)--follow-first[only follow the first parent of merge changesets]' \
-  '(--copies -C)'{-C,--copies}'[show copied files]' \
-  '(--keyword -k)'{-k+,--keyword}'[search for a keyword]:' \
-  '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
-  '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
-  '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
-  '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
-  '(--patch -p)'{-p,--patch}'[show patch]' \
-  '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_tags' \
-  '*:files:_hg_files'
-}
-
-_hg_cmd_manifest() {
-  _arguments -s -w : $_hg_global_opts \
-  ':revision:_hg_tags'
-}
-
-_hg_cmd_merge() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--force -f)'{-f,--force}'[force a merge with outstanding changes]' \
-  '(--rev -r 1)'{-r,--rev}'[revision to merge]:revision:_hg_mergerevs' \
-  '(--preview -P)'{-P,--preview}'[review revisions to merge (no merge is performed)]' \
-  ':revision:_hg_mergerevs'
-}
-
-_hg_cmd_outgoing() {
-  _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
-  '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
-  '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
-  '(--patch -p)'{-p,--patch}'[show patch]' \
-  '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]' \
-  '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
-  ':destination:_hg_remote'
-}
-
-_hg_cmd_parents() {
-  _arguments -s -w : $_hg_global_opts $_hg_style_opts \
-  '(--rev -r)'{-r+,--rev}'[show parents of the specified rev]:revision:_hg_tags' \
-  ':last modified file:_hg_files'
-}
-
-_hg_cmd_paths() {
-  _arguments -s -w : $_hg_global_opts \
-  ':path:_hg_paths'
-}
-
-_hg_cmd_pull() {
-  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
-  '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
-  '(--update -u)'{-u,--update}'[update to new tip if changesets were pulled]' \
-  '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:' \
-  ':source:_hg_remote'
-}
-
-_hg_cmd_push() {
-  _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
-  '(--force -f)'{-f,--force}'[force push]' \
-  '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]:revision:_hg_tags' \
-  ':destination:_hg_remote'
-}
-
-_hg_cmd_remove() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--after -A)'{-A,--after}'[record remove that has already occurred]' \
-  '(--force -f)'{-f,--force}'[remove file even if modified]' \
-  '*:file:_hg_files'
-}
-
-_hg_cmd_rename() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
-  '(--after -A)'{-A,--after}'[record a rename that has already occurred]' \
-  '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
-  '*:file:_hg_files'
-}
-
-_hg_cmd_resolve() {
-  local context state line
-  typeset -A opt_args
-
-  _arguments -s -w : $_hg_global_opts \
-  '(--list -l --mark -m --unmark -u)'{-l,--list}'[list state of files needing merge]:*:merged files:->resolve_files' \
-  '(--mark -m --list -l --unmark -u)'{-m,--mark}'[mark files as resolved]:*:unresolved files:_hg_unresolved' \
-  '(--unmark -u --list -l --mark -m)'{-u,--unmark}'[unmark files as resolved]:*:resolved files:_hg_resolved' \
-  '*:file:_hg_unresolved'
-
-  if [[ $state == 'resolve_files' ]]
-  then
-    _alternative 'files:resolved files:_hg_resolved' \
-      'files:unresolved files:_hg_unresolved'
-  fi
-}
-
-_hg_cmd_revert() {
-  local context state line
-  typeset -A opt_args
-
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
-  '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
-  '(--rev -r)'{-r+,--rev}'[revision to revert to]:revision:_hg_tags' \
-  '--no-backup[do not save backup copies of files]' \
-  '*:file:->diff_files'
-
-  if [[ $state == 'diff_files' ]]
-  then
-    if [[ -n $opt_args[-r] ]]
-    then
-      _hg_files
-    else
-      typeset -a status_files
-      _hg_status mard
-      _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files
-    fi
-  fi
-}
-
-_hg_cmd_serve() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--accesslog -A)'{-A+,--accesslog}'[name of access log file]:log file:_files' \
-  '(--errorlog -E)'{-E+,--errorlog}'[name of error log file]:log file:_files' \
-  '(--daemon -d)'{-d,--daemon}'[run server in background]' \
-  '(--port -p)'{-p+,--port}'[listen port]:listen port:' \
-  '(--address -a)'{-a+,--address}'[interface address]:interface address:' \
-  '(--name -n)'{-n+,--name}'[name to show in web pages]:repository name:' \
-  '(--templates -t)'{-t,--templates}'[web template directory]:template dir:_files -/' \
-  '--style[web template style]:style' \
-  '--stdio[for remote clients]' \
-  '(--ipv6 -6)'{-6,--ipv6}'[use IPv6 in addition to IPv4]'
-}
-
-_hg_cmd_showconfig() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--untrusted -u)'{-u+,--untrusted}'[show untrusted configuration options]' \
-  ':config item:_hg_config'
-}
-
-_hg_cmd_status() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '(--all -A)'{-A,--all}'[show status of all files]' \
-  '(--modified -m)'{-m,--modified}'[show only modified files]' \
-  '(--added -a)'{-a,--added}'[show only added files]' \
-  '(--removed -r)'{-r,--removed}'[show only removed files]' \
-  '(--deleted -d)'{-d,--deleted}'[show only deleted (but tracked) files]' \
-  '(--clean -c)'{-c,--clean}'[show only files without changes]' \
-  '(--unknown -u)'{-u,--unknown}'[show only unknown files]' \
-  '(--ignored -i)'{-i,--ignored}'[show ignored files]' \
-  '(--no-status -n)'{-n,--no-status}'[hide status prefix]' \
-  '(--copies -C)'{-C,--copies}'[show source of copied files]' \
-  '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
-  '--rev[show difference from revision]:revision:_hg_tags' \
-  '*:files:_files'
-}
-
-_hg_cmd_summary() {
-  _arguments -s -w : $_hg_global_opts \
-  '--remote[check for push and pull]'
-}
-
-_hg_cmd_tag() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--local -l)'{-l,--local}'[make the tag local]' \
-  '(--message -m)'{-m+,--message}'[message for tag commit log entry]:message:' \
-  '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
-  '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
-  '(--rev -r)'{-r+,--rev}'[revision to tag]:revision:_hg_tags' \
-  ':tag name:'
-}
-
-_hg_cmd_tip() {
-  _arguments -s -w : $_hg_global_opts $_hg_style_opts \
-  '(--patch -p)'{-p,--patch}'[show patch]'
-}
-
-_hg_cmd_unbundle() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--update -u)'{-u,--update}'[update to new tip if changesets were unbundled]' \
-  ':files:_files'
-}
-
-_hg_cmd_update() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--clean -C)'{-C,--clean}'[overwrite locally modified files]' \
-  '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
-  ':revision:_hg_tags'
-}
-
-# HGK
-_hg_cmd_view() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
-  ':revision range:_hg_tags'
-}
-
-# MQ
-_hg_qseries() {
-  typeset -a patches
-  patches=(${(f)"$(_hg_cmd qseries)"})
-  (( $#patches )) && _describe -t hg-patches 'patches' patches
-}
-
-_hg_qapplied() {
-  typeset -a patches
-  patches=(${(f)"$(_hg_cmd qapplied)"})
-  if (( $#patches ))
-  then
-    patches+=(qbase qtip)
-    _describe -t hg-applied-patches 'applied patches' patches
-  fi
-}
-
-_hg_qunapplied() {
-  typeset -a patches
-  patches=(${(f)"$(_hg_cmd qunapplied)"})
-  (( $#patches )) && _describe -t hg-unapplied-patches 'unapplied patches' patches
-}
-
-# unapplied, including guarded patches
-_hg_qdeletable() {
-  typeset -a unapplied
-  unapplied=(${(f)"$(_hg_cmd qseries)"})
-  for p in $(_hg_cmd qapplied)
-  do
-    unapplied=(${unapplied:#$p})
-  done
-
-  (( $#unapplied )) && _describe -t hg-allunapplied-patches 'all unapplied patches' unapplied
-}
-
-_hg_qguards() {
-  typeset -a guards
-  local guard
-  compset -P "+|-"
-  _hg_cmd qselect -s | while read guard
-  do
-    guards+=(${guard#(+|-)})
-  done
-  (( $#guards )) && _describe -t hg-guards 'guards' guards
-}
-
-_hg_qseries_opts=(
-  '(--summary -s)'{-s,--summary}'[print first line of patch header]')
-
-_hg_cmd_qapplied() {
-  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
-}
-
-_hg_cmd_qdelete() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--keep -k)'{-k,--keep}'[keep patch file]' \
-  '*'{-r+,--rev}'[stop managing a revision]:applied patch:_hg_revrange' \
-  '*:unapplied patch:_hg_qdeletable'
-}
-
-_hg_cmd_qdiff() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
-  '*:pattern:_hg_files'
-}
-
-_hg_cmd_qfold() {
-  _arguments -s -w : $_hg_global_opts $_h_commit_opts \
-  '(--keep,-k)'{-k,--keep}'[keep folded patch files]' \
-  '*:unapplied patch:_hg_qunapplied'
-}
-
-_hg_cmd_qgoto() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--force -f)'{-f,--force}'[overwrite any local changes]' \
-  ':patch:_hg_qseries'
-}
-
-_hg_cmd_qguard() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--list -l)'{-l,--list}'[list all patches and guards]' \
-  '(--none -n)'{-n,--none}'[drop all guards]' \
-  ':patch:_hg_qseries' \
-  '*:guards:_hg_qguards'
-}
-
-_hg_cmd_qheader() {
-  _arguments -s -w : $_hg_global_opts \
-  ':patch:_hg_qseries'
-}
-
-_hg_cmd_qimport() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--existing -e)'{-e,--existing}'[import file in patch dir]' \
-  '(--name -n 2)'{-n+,--name}'[patch file name]:name:' \
-  '(--force -f)'{-f,--force}'[overwrite existing files]' \
-  '*'{-r+,--rev}'[place existing revisions under mq control]:revision:_hg_revrange' \
-  '*:patch:_files'
-}
-
-_hg_cmd_qnew() {
-  _arguments -s -w : $_hg_global_opts $_hg_commit_opts \
-  '(--force -f)'{-f,--force}'[import uncommitted changes into patch]' \
-  ':patch:'
-}
-
-_hg_cmd_qnext() {
-  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
-}
-
-_hg_cmd_qpop() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--all -a :)'{-a,--all}'[pop all patches]' \
-  '(--name -n)'{-n+,--name}'[queue name to pop]:' \
-  '(--force -f)'{-f,--force}'[forget any local changes]' \
-  ':patch:_hg_qapplied'
-}
-
-_hg_cmd_qprev() {
-  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
-}
-
-_hg_cmd_qpush() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--all -a :)'{-a,--all}'[apply all patches]' \
-  '(--list -l)'{-l,--list}'[list patch name in commit text]' \
-  '(--merge -m)'{-m+,--merge}'[merge from another queue]:' \
-  '(--name -n)'{-n+,--name}'[merge queue name]:' \
-  '(--force -f)'{-f,--force}'[apply if the patch has rejects]' \
-  ':patch:_hg_qunapplied'
-}
-
-_hg_cmd_qrefresh() {
-  _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_commit_opts \
-  '(--git -g)'{-g,--git}'[use git extended diff format]' \
-  '(--short -s)'{-s,--short}'[short refresh]' \
-  '*:files:_hg_files'
-}
-
-_hg_cmd_qrename() {
-  _arguments -s -w : $_hg_global_opts \
-  ':patch:_hg_qseries' \
-  ':destination:'
-}
-
-_hg_cmd_qselect() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--none -n :)'{-n,--none}'[disable all guards]' \
-  '(--series -s :)'{-s,--series}'[list all guards in series file]' \
-  '--pop[pop to before first guarded applied patch]' \
-  '--reapply[pop and reapply patches]' \
-  '*:guards:_hg_qguards'
-}
-
-_hg_cmd_qseries() {
-  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts \
-  '(--missing -m)'{-m,--missing}'[print patches not in series]'
-}
-
-_hg_cmd_qunapplied() {
-  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
-}
-
-_hg_cmd_qtop() {
-  _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
-}
-
-_hg_cmd_strip() {
-  _arguments -s -w : $_hg_global_opts \
-  '(--force -f)'{-f,--force}'[force multi-head removal]' \
-  '(--backup -b)'{-b,--backup}'[bundle unrelated changesets]' \
-  '(--nobackup -n)'{-n,--nobackup}'[no backups]' \
-  ':revision:_hg_tags'
-}
-
-_hg "$@"
--- a/setup.py	Mon Nov 30 23:10:21 2009 +0200
+++ b/setup.py	Mon Nov 30 21:54:34 2009 +0100
@@ -263,7 +263,16 @@
             f = os.path.join(curdir, f)
             packagedata['mercurial'].append(f)
 
-datafiles = []
+datafiles = [
+    ('share/bash_completion.d', ['contrib/bash/hg']),
+    ('share/zsh/site-functions', ['contrib/zsh/_hg']),
+    ('share/mercurial/www', ['hgweb.cgi',
+                             'hgwebdir.cgi',
+                             'contrib/hgwebdir.fcgi',
+                             'contrib/hgwebdir.wsgi']),
+    ('share/mercurial/examples', ['contrib/sample.hgrc',
+                                  'contrib/mergetools.hgrc']),
+]
 
 setup(name='mercurial',
       version=version,