3 # Zsh completion script for mercurial. Rename this file to _hg and copy
4 # it into your zsh function path (/usr/share/zsh/site-functions for
7 # If you do not want to install it globally, you can copy it somewhere
8 # else and add that directory to $fpath. This must be done before
9 # compinit is called. If the file is copied to ~/.zsh.d, your ~/.zshrc
10 # file could look like this:
12 # fpath=("$HOME/.zsh.d" $fpath)
13 # autoload -U compinit
16 # Copyright (C) 2005, 2006 Steve Borho <steve@borho.org>
17 # Copyright (C) 2006-9 Brendan Cully <brendan@kublai.com>
19 # Permission is hereby granted, without written agreement and without
20 # licence or royalty fees, to use, copy, modify, and distribute this
21 # software and to distribute modified versions of this software for any
22 # purpose, provided that the above copyright notice and the following
23 # two paragraphs appear in all copies of this software.
25 # In no event shall the authors be liable to any party for direct,
26 # indirect, special, incidental, or consequential damages arising out of
27 # the use of this software and its documentation, even if the authors
28 # have been advised of the possibility of such damage.
30 # The authors specifically disclaim any warranties, including, but not
31 # limited to, the implied warranties of merchantability and fitness for
32 # a particular purpose. The software provided hereunder is on an "as
33 # is" basis, and the authors have no obligation to provide maintenance,
34 # support, updates, enhancements, or modifications.
39 local curcontext="$curcontext" state line
40 typeset -A _hg_cmd_globals
47 while (( i < $#words ))
51 eval _hg_root="$words[$i+1]"
52 _hg_cmd_globals+=("$words[$i]" "$_hg_root")
57 _hg_cmd_globals+="$words[$i]"
58 eval _hg_root="${words[$i]#-R}"
63 # pass along arguments to hg completer
64 _hg_cmd_globals+=("$words[$i]" "$words[$i+1]")
85 _arguments -s -w : $_hg_global_opts \
86 ':mercurial command:_hg_commands'
90 # resolve abbreviations and aliases
91 if ! (( $+functions[_hg_cmd_${cmd}] ))
94 (( $#_hg_cmd_list )) || _hg_get_commands
96 cmdexp=$_hg_cmd_list[(r)${cmd}*]
97 if [[ $cmdexp == $_hg_cmd_list[(R)${cmd}*] ]]
99 # might be nice to rewrite the command line with the expansion
102 if [[ -n $_hg_alias_list[$cmd] ]]
104 cmd=$_hg_alias_list[$cmd]
108 curcontext="${curcontext%:*:*}:hg-${cmd}:"
110 zstyle -s ":completion:$curcontext:" cache-policy update_policy
112 if [[ -z "$update_policy" ]]
114 zstyle ":completion:$curcontext:" cache-policy _hg_cache_policy
117 if (( $+functions[_hg_cmd_${cmd}] ))
121 # complete unknown commands normally
122 _arguments -s -w : $_hg_global_opts \
132 (( $#old )) && return 0
138 typeset -ga _hg_cmd_list
139 typeset -gA _hg_alias_list
140 local hline cmd cmdalias
142 _call_program hg hg debugcomplete -v | while read -A hline
147 for cmdalias in $hline[2,-1]
149 _hg_cmd_list+=($cmdalias)
150 _hg_alias_list+=($cmdalias $cmd)
156 (( $#_hg_cmd_list )) || _hg_get_commands
157 _describe -t commands 'mercurial command' _hg_cmd_list
169 _hg_cmd tags | while read tag
171 tags+=(${tag/ # [0-9]#:*})
173 (( $#tags )) && _describe -t tags 'tags' tags
176 # likely merge candidates
181 heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"})
182 # exclude own revision
183 myrev=$(_hg_cmd log -r . --template '{rev}\\n')
184 heads=(${heads:#$myrev})
186 (( $#heads )) && _describe -t heads 'heads' heads
190 if [[ -n "$_hg_root" ]]
192 [[ -d "$_hg_root/.hg" ]] || return
198 _files -W $PWD/$_hg_root
207 [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
208 status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"})
212 typeset -a status_files
214 _wanted files expl 'unknown files' _multi_parts / status_files
218 typeset -a status_files
220 _wanted files expl 'missing files' _multi_parts / status_files
224 typeset -a status_files
226 _wanted files expl 'modified files' _multi_parts / status_files
232 [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
234 _hg_cmd resolve -l ./$PREFIX | while read rstate rpath
236 [[ $rstate == 'R' ]] && resolved_files+=($rpath)
237 [[ $rstate == 'U' ]] && unresolved_files+=($rpath)
242 typeset -a resolved_files unresolved_files
244 _wanted files expl 'resolved files' _multi_parts / resolved_files
248 typeset -a resolved_files unresolved_files
250 _wanted files expl 'unresolved files' _multi_parts / unresolved_files
255 items=(${${(%f)"$(_call_program hg hg showconfig)"}%%\=*})
256 (( $#items )) && _describe -t config 'config item' items
260 _alternative 'files:unknown files:_hg_unknown' \
261 'files:missing files:_hg_missing'
267 if zstyle -T ":completion:${curcontext}:files" remote-access
269 local host=${PREFIX%%/*}
271 compset -p $(( $#host + 1 ))
272 local rempath=${(M)PREFIX##*/}
273 local cacheid="hg:${host}-${rempath//\//_}"
274 cacheid=${cacheid%[-_]}
276 if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
278 remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}")"}##*/}%/})
279 _store_cache "$cacheid" remdirs
281 _describe -t directories 'remote directory' remdirs -S/
283 _message 'remote directory'
290 _alternative 'hosts:remote host name:_hosts -S/' \
291 'users:user:_users -S@'
297 if compset -P bundle://
300 elif compset -P ssh://
303 elif [[ -prefix *: ]]
309 _wanted url-schemas expl 'URL schema' compadd -S '' - \
310 http:// https:// ssh:// bundle://
315 typeset -a paths pnames
316 _hg_cmd paths | while read -A pnames
320 (( $#paths )) && _describe -t path-aliases 'repository alias' paths
324 _alternative 'path-aliases:repository alias:_hg_paths' \
325 'directories:directory:_files -/' \
330 _alternative 'directories:directory:_files -/' \
336 '(--repository -R)'{-R+,--repository}'[repository root directory]:repository:_files -/'
337 '--cwd[change working directory]:new working directory:_files -/'
338 '(--noninteractive -y)'{-y,--noninteractive}'[do not prompt, assume yes for any required answers]'
339 '(--verbose -v)'{-v,--verbose}'[enable additional output]'
340 '*--config[set/override config option]:defined config items:_hg_config'
341 '(--quiet -q)'{-q,--quiet}'[suppress output]'
342 '(--help -h)'{-h,--help}'[display help and exit]'
343 '--debug[debug mode]'
344 '--debugger[start debugger]'
345 '--encoding[set the charset encoding (default: UTF8)]'
346 '--encodingmode[set the charset encoding mode (default: strict)]'
347 '--lsprof[print improved command execution profile]'
348 '--traceback[print traceback on exception]'
349 '--time[time how long the command takes]'
351 '--version[output version information and exit]'
355 '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
356 '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
359 '(--text -a)'{-a,--text}'[treat all files as text]'
360 '(--git -g)'{-g,--git}'[use git extended diff format]'
361 "--nodates[don't include dates in diff headers]")
364 '(--dry-run -n)'{-n,--dry-run}'[do not perform actions, just print output]')
367 '--style[display using template map file]:'
368 '--template[display with template]:')
371 '(-m --message -l --logfile --edit -e)'{-e,--edit}'[edit commit message]'
372 '(-e --edit -l --logfile --message -m)'{-m+,--message}'[use <text> as commit message]:message:'
373 '(-e --edit -m --message --logfile -l)'{-l+,--logfile}'[read the commit message from <file>]:log file:_files')
376 '(--ssh -e)'{-e+,--ssh}'[specify ssh command to use]:'
377 '--remotecmd[specify hg command to run on the remote side]:')
380 _call_program hg hg --config ui.verbose=0 --config defaults."$1"= \
381 "$_hg_cmd_globals[@]" "$@" 2> /dev/null
385 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
386 '*:unknown files:_hg_unknown'
389 _hg_cmd_addremove() {
390 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
391 '(--similarity -s)'{-s+,--similarity}'[guess renamed files by similarity (0<=s<=100)]:' \
392 '*:unknown or missing files:_hg_addremove'
396 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
397 '(--rev -r)'{-r+,--rev}'[annotate the specified revision]:revision:_hg_tags' \
398 '(--follow -f)'{-f,--follow}'[follow file copies and renames]' \
399 '(--text -a)'{-a,--text}'[treat all files as text]' \
400 '(--user -u)'{-u,--user}'[list the author]' \
401 '(--date -d)'{-d,--date}'[list the date]' \
402 '(--number -n)'{-n,--number}'[list the revision number (default)]' \
403 '(--changeset -c)'{-c,--changeset}'[list the changeset]' \
408 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
409 '--no-decode[do not pass files through decoders]' \
410 '(--prefix -p)'{-p+,--prefix}'[directory prefix for files in archive]:' \
411 '(--rev -r)'{-r+,--rev}'[revision to distribute]:revision:_hg_tags' \
412 '(--type -t)'{-t+,--type}'[type of distribution to create]:archive type:(files tar tbz2 tgz uzip zip)' \
413 '*:destination:_files'
417 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
418 '--merge[merge with old dirstate parent after backout]' \
419 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
420 '--parent[parent to choose when backing out merge]' \
421 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
422 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
423 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
424 '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt'
428 _arguments -s -w : $_hg_global_opts \
429 '(-)'{-r,--reset}'[reset bisect state]' \
430 '(--good -g --bad -b --skip -s --reset -r)'{-g,--good}'[mark changeset good]'::revision:_hg_tags \
431 '(--good -g --bad -b --skip -s --reset -r)'{-b,--bad}'[mark changeset bad]'::revision:_hg_tags \
432 '(--good -g --bad -b --skip -s --reset -r)'{-s,--skip}'[skip testing changeset]' \
433 '(--command -c --noupdate -U)'{-c+,--command}'[use command to check changeset state]':commands:_command_names \
434 '(--command -c --noupdate -U)'{-U,--noupdate}'[do not update to target]'
438 _arguments -s -w : $_hg_global_opts \
439 '(--force -f)'{-f,--force}'[set branch name even if it shadows an existing branch]' \
440 '(--clean -C)'{-C,--clean}'[reset branch name to parent branch name]'
444 _arguments -s -w : $_hg_global_opts \
445 '(--active -a)'{-a,--active}'[show only branches that have unmerge heads]'
449 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
450 '(--force -f)'{-f,--force}'[run even when remote repository is unrelated]' \
451 '(2)*--base[a base changeset to specify instead of a destination]:revision:_hg_tags' \
452 ':output file:_files' \
453 ':destination repository:_files -/'
457 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
458 '(--output -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
459 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
464 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
465 '(--noupdate -U)'{-U,--noupdate}'[do not update the new working directory]' \
466 '(--rev -r)'{-r+,--rev}'[a changeset you would like to have after cloning]:' \
467 '--uncompressed[use uncompressed transfer (fast over LAN)]' \
468 ':source repository:_hg_remote' \
469 ':destination:_hg_clone_dest'
473 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
474 '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]' \
475 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
476 '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt' \
477 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
478 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
483 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
484 '(--after -A)'{-A,--after}'[record a copy that has already occurred]' \
485 '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
491 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_diff_opts \
492 '*'{-r,--rev}'+[revision]:revision:_hg_revrange' \
493 '(--show-function -p)'{-p,--show-function}'[show which function each change is in]' \
494 '(--ignore-all-space -w)'{-w,--ignore-all-space}'[ignore white space when comparing lines]' \
495 '(--ignore-space-change -b)'{-b,--ignore-space-change}'[ignore changes in the amount of white space]' \
496 '(--ignore-blank-lines -B)'{-B,--ignore-blank-lines}'[ignore changes whose lines are all blank]' \
497 '*:file:->diff_files'
499 if [[ $state == 'diff_files' ]]
501 if [[ -n $opt_args[-r] ]]
511 _arguments -s -w : $_hg_global_opts $_hg_diff_opts \
512 '(--outout -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
513 '--switch-parent[diff against the second parent]' \
514 '*:revision:_hg_tags'
518 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
519 '(--print0 -0)'{-0,--print0}'[end filenames with NUL]' \
520 '--all[print all revisions with matches]' \
521 '(--follow -f)'{-f,--follow}'[follow changeset or file history]' \
522 '(--ignore-case -i)'{-i,--ignore-case}'[ignore case when matching]' \
523 '(--files-with-matches -l)'{-l,--files-with-matches}'[print only filenames and revs that match]' \
524 '(--line-number -n)'{-n,--line-number}'[print matching line numbers]' \
525 '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \
526 '(--user -u)'{-u,--user}'[print user who committed change]' \
527 '1:search pattern:' \
532 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
533 '(--rev -r)'{-r+,--rev}'[show only heads which are descendants of rev]:revision:_hg_tags'
537 _arguments -s -w : $_hg_global_opts \
538 '*:mercurial command:_hg_commands'
542 _arguments -s -w : $_hg_global_opts \
543 '(--rev -r)'{-r+,--rev}'[identify the specified rev]:revision:_hg_tags' \
544 '(--num -n)'{-n+,--num}'[show local revision number]' \
545 '(--id -i)'{-i+,--id}'[show global revision id]' \
546 '(--branch -b)'{-b+,--branch}'[show branch]' \
547 '(--tags -t)'{-t+,--tags}'[show tags]'
551 _arguments -s -w : $_hg_global_opts \
552 '(--strip -p)'{-p+,--strip}'[directory strip option for patch (default: 1)]:count:' \
553 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
554 '(--force -f)'{-f,--force}'[skip check for outstanding uncommitted changes]' \
559 _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
560 '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
561 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
562 '(--patch -p)'{-p,--patch}'[show patch]' \
563 '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:_hg_tags' \
564 '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
565 '--bundle[file to store the bundles into]:bundle file:_files' \
570 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
575 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
576 '(--rev -r)'{-r+,--rev}'[search repository as it stood at revision]:revision:_hg_tags' \
577 '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
578 '(--fullpath -f)'{-f,--fullpath}'[print complete paths]' \
579 '*:search pattern:_hg_files'
583 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_style_opts \
584 '(--follow --follow-first -f)'{-f,--follow}'[follow changeset or history]' \
585 '(-f --follow)--follow-first[only follow the first parent of merge changesets]' \
586 '(--copies -C)'{-C,--copies}'[show copied files]' \
587 '(--keyword -k)'{-k+,--keyword}'[search for a keyword]:' \
588 '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
589 '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
590 '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
591 '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
592 '(--patch -p)'{-p,--patch}'[show patch]' \
593 '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_tags' \
598 _arguments -s -w : $_hg_global_opts \
603 _arguments -s -w : $_hg_global_opts \
604 '(--force -f)'{-f,--force}'[force a merge with outstanding changes]' \
605 '(--rev -r 1)'{-r,--rev}'[revision to merge]:revision:_hg_mergerevs' \
606 '(--preview -P)'{-P,--preview}'[review revisions to merge (no merge is performed)]' \
607 ':revision:_hg_mergerevs'
611 _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
612 '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
613 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
614 '(--patch -p)'{-p,--patch}'[show patch]' \
615 '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]' \
616 '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
617 ':destination:_hg_remote'
621 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
622 '(--rev -r)'{-r+,--rev}'[show parents of the specified rev]:revision:_hg_tags' \
623 ':last modified file:_hg_files'
627 _arguments -s -w : $_hg_global_opts \
632 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
633 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
634 '(--update -u)'{-u,--update}'[update to new tip if changesets were pulled]' \
635 '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:' \
640 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
641 '(--force -f)'{-f,--force}'[force push]' \
642 '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]:revision:_hg_tags' \
643 ':destination:_hg_remote'
647 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
648 '(--after -A)'{-A,--after}'[record remove that has already occurred]' \
649 '(--force -f)'{-f,--force}'[remove file even if modified]' \
654 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
655 '(--after -A)'{-A,--after}'[record a rename that has already occurred]' \
656 '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
661 local context state line
664 _arguments -s -w : $_hg_global_opts \
665 '(--list -l --mark -m --unmark -u)'{-l,--list}'[list state of files needing merge]:*:merged files:->resolve_files' \
666 '(--mark -m --list -l --unmark -u)'{-m,--mark}'[mark files as resolved]:*:unresolved files:_hg_unresolved' \
667 '(--unmark -u --list -l --mark -m)'{-u,--unmark}'[unmark files as resolved]:*:resolved files:_hg_resolved' \
668 '*:file:_hg_unresolved'
670 if [[ $state == 'resolve_files' ]]
672 _alternative 'files:resolved files:_hg_resolved' \
673 'files:unresolved files:_hg_unresolved'
678 local context state line
681 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
682 '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
683 '(--rev -r)'{-r+,--rev}'[revision to revert to]:revision:_hg_tags' \
684 '--no-backup[do not save backup copies of files]' \
685 '*:file:->diff_files'
687 if [[ $state == 'diff_files' ]]
689 if [[ -n $opt_args[-r] ]]
693 typeset -a status_files
695 _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files
701 _arguments -s -w : $_hg_global_opts \
702 '(--accesslog -A)'{-A+,--accesslog}'[name of access log file]:log file:_files' \
703 '(--errorlog -E)'{-E+,--errorlog}'[name of error log file]:log file:_files' \
704 '(--daemon -d)'{-d,--daemon}'[run server in background]' \
705 '(--port -p)'{-p+,--port}'[listen port]:listen port:' \
706 '(--address -a)'{-a+,--address}'[interface address]:interface address:' \
707 '(--name -n)'{-n+,--name}'[name to show in web pages]:repository name:' \
708 '(--templates -t)'{-t,--templates}'[web template directory]:template dir:_files -/' \
709 '--style[web template style]:style' \
710 '--stdio[for remote clients]' \
711 '(--ipv6 -6)'{-6,--ipv6}'[use IPv6 in addition to IPv4]'
714 _hg_cmd_showconfig() {
715 _arguments -s -w : $_hg_global_opts \
716 '(--untrusted -u)'{-u+,--untrusted}'[show untrusted configuration options]' \
717 ':config item:_hg_config'
721 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
722 '(--all -A)'{-A,--all}'[show status of all files]' \
723 '(--modified -m)'{-m,--modified}'[show only modified files]' \
724 '(--added -a)'{-a,--added}'[show only added files]' \
725 '(--removed -r)'{-r,--removed}'[show only removed files]' \
726 '(--deleted -d)'{-d,--deleted}'[show only deleted (but tracked) files]' \
727 '(--clean -c)'{-c,--clean}'[show only files without changes]' \
728 '(--unknown -u)'{-u,--unknown}'[show only unknown files]' \
729 '(--ignored -i)'{-i,--ignored}'[show ignored files]' \
730 '(--no-status -n)'{-n,--no-status}'[hide status prefix]' \
731 '(--copies -C)'{-C,--copies}'[show source of copied files]' \
732 '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
733 '--rev[show difference from revision]:revision:_hg_tags' \
738 _arguments -s -w : $_hg_global_opts \
739 '(--local -l)'{-l,--local}'[make the tag local]' \
740 '(--message -m)'{-m+,--message}'[message for tag commit log entry]:message:' \
741 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
742 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
743 '(--rev -r)'{-r+,--rev}'[revision to tag]:revision:_hg_tags' \
748 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
749 '(--patch -p)'{-p,--patch}'[show patch]'
753 _arguments -s -w : $_hg_global_opts \
754 '(--update -u)'{-u,--update}'[update to new tip if changesets were unbundled]' \
759 _arguments -s -w : $_hg_global_opts \
760 '(--clean -C)'{-C,--clean}'[overwrite locally modified files]' \
761 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
767 _arguments -s -w : $_hg_global_opts \
768 '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
769 ':revision range:_hg_tags'
775 patches=(${(f)"$(_hg_cmd qseries)"})
776 (( $#patches )) && _describe -t hg-patches 'patches' patches
781 patches=(${(f)"$(_hg_cmd qapplied)"})
784 patches+=(qbase qtip)
785 _describe -t hg-applied-patches 'applied patches' patches
791 patches=(${(f)"$(_hg_cmd qunapplied)"})
792 (( $#patches )) && _describe -t hg-unapplied-patches 'unapplied patches' patches
795 # unapplied, including guarded patches
798 unapplied=(${(f)"$(_hg_cmd qseries)"})
799 for p in $(_hg_cmd qapplied)
801 unapplied=(${unapplied:#$p})
804 (( $#unapplied )) && _describe -t hg-allunapplied-patches 'all unapplied patches' unapplied
811 _hg_cmd qselect -s | while read guard
813 guards+=(${guard#(+|-)})
815 (( $#guards )) && _describe -t hg-guards 'guards' guards
819 '(--summary -s)'{-s,--summary}'[print first line of patch header]')
822 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
826 _arguments -s -w : $_hg_global_opts \
827 '(--keep -k)'{-k,--keep}'[keep patch file]' \
828 '*'{-r+,--rev}'[stop managing a revision]:applied patch:_hg_revrange' \
829 '*:unapplied patch:_hg_qdeletable'
833 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
834 '*:pattern:_hg_files'
838 _arguments -s -w : $_hg_global_opts $_h_commit_opts \
839 '(--keep,-k)'{-k,--keep}'[keep folded patch files]' \
840 '*:unapplied patch:_hg_qunapplied'
844 _arguments -s -w : $_hg_global_opts \
845 '(--force -f)'{-f,--force}'[overwrite any local changes]' \
850 _arguments -s -w : $_hg_global_opts \
851 '(--list -l)'{-l,--list}'[list all patches and guards]' \
852 '(--none -n)'{-n,--none}'[drop all guards]' \
853 ':patch:_hg_qseries' \
854 '*:guards:_hg_qguards'
858 _arguments -s -w : $_hg_global_opts \
863 _arguments -s -w : $_hg_global_opts \
864 '(--existing -e)'{-e,--existing}'[import file in patch dir]' \
865 '(--name -n 2)'{-n+,--name}'[patch file name]:name:' \
866 '(--force -f)'{-f,--force}'[overwrite existing files]' \
867 '*'{-r+,--rev}'[place existing revisions under mq control]:revision:_hg_revrange' \
872 _arguments -s -w : $_hg_global_opts $_hg_commit_opts \
873 '(--force -f)'{-f,--force}'[import uncommitted changes into patch]' \
878 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
882 _arguments -s -w : $_hg_global_opts \
883 '(--all -a :)'{-a,--all}'[pop all patches]' \
884 '(--name -n)'{-n+,--name}'[queue name to pop]:' \
885 '(--force -f)'{-f,--force}'[forget any local changes]' \
886 ':patch:_hg_qapplied'
890 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
894 _arguments -s -w : $_hg_global_opts \
895 '(--all -a :)'{-a,--all}'[apply all patches]' \
896 '(--list -l)'{-l,--list}'[list patch name in commit text]' \
897 '(--merge -m)'{-m+,--merge}'[merge from another queue]:' \
898 '(--name -n)'{-n+,--name}'[merge queue name]:' \
899 '(--force -f)'{-f,--force}'[apply if the patch has rejects]' \
900 ':patch:_hg_qunapplied'
904 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_commit_opts \
905 '(--git -g)'{-g,--git}'[use git extended diff format]' \
906 '(--short -s)'{-s,--short}'[short refresh]' \
911 _arguments -s -w : $_hg_global_opts \
912 ':patch:_hg_qseries' \
917 _arguments -s -w : $_hg_global_opts \
918 '(--none -n :)'{-n,--none}'[disable all guards]' \
919 '(--series -s :)'{-s,--series}'[list all guards in series file]' \
920 '--pop[pop to before first guarded applied patch]' \
921 '--reapply[pop and reapply patches]' \
922 '*:guards:_hg_qguards'
926 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts \
927 '(--missing -m)'{-m,--missing}'[print patches not in series]'
930 _hg_cmd_qunapplied() {
931 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
935 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
939 _arguments -s -w : $_hg_global_opts \
940 '(--force -f)'{-f,--force}'[force multi-head removal]' \
941 '(--backup -b)'{-b,--backup}'[bundle unrelated changesets]' \
942 '(--nobackup -n)'{-n,--nobackup}'[no backups]' \