Mercurial > hg
comparison hgext/shelve.py @ 21851:aad28ff87788
shelve: refactor option combination check to easily add new ones
Before this patch, the name of a newly added option had to be added
into each string that was passed to the "checkopt()" internal
function: these are white-space-separated list of un-acceptable option
names (= "black list" for the specified "opt").
This new option had to be added into multiple strings because each
option could belong to only one action of "create", "cleanup",
"delete" or "list".
In addition to this redundancy, each string passed to "checkopt()" was
already too long to include a new one.
This patch refactors option combination check to make it easier to add
a new option in a subsequent patch.
New "checkopt()" only takes one action ("cleanup", "delete" or
"list"), and checks whether all explicitly activated options are
allowed for it or not (if specified action is activated in "opts").
The "date" entry is listed in "allowables", but commented out,
because:
- "date" shouldn't be checked for test
checking "date" causes unexpected failure of "test-shelve.t",
because "run-test.py" puts "[default] shelve = --date '0 0'" into
hgrc.
- explicitly listing it can advertise that ignoring it is intentional
This patch doesn't choose "white list" for the specified "opt", to
avoid treating global options.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 20 Jun 2014 16:15:38 +0900 |
parents | 4d9d490d7bbe |
children | 37a5decc6924 |
comparison
equal
deleted
inserted
replaced
21850:3b97a93dc137 | 21851:aad28ff87788 |
---|---|
673 To delete specific shelved changes, use ``--delete``. To delete | 673 To delete specific shelved changes, use ``--delete``. To delete |
674 all shelved changes, use ``--cleanup``. | 674 all shelved changes, use ``--cleanup``. |
675 ''' | 675 ''' |
676 cmdutil.checkunfinished(repo) | 676 cmdutil.checkunfinished(repo) |
677 | 677 |
678 def checkopt(opt, incompatible): | 678 allowables = [ |
679 ('addremove', 'create'), # 'create' is pseudo action | |
680 ('cleanup', 'cleanup'), | |
681 # ('date', 'create'), # ignored for passing '--date "0 0"' in tests | |
682 ('delete', 'delete'), | |
683 ('list', 'list'), | |
684 ('message', 'create'), | |
685 ('name', 'create'), | |
686 ('patch', 'list'), | |
687 ('stat', 'list'), | |
688 ] | |
689 def checkopt(opt): | |
679 if opts[opt]: | 690 if opts[opt]: |
680 for i in incompatible.split(): | 691 for i, allowable in allowables: |
681 if opts[i]: | 692 if opts[i] and opt != allowable: |
682 raise util.Abort(_("options '--%s' and '--%s' may not be " | 693 raise util.Abort(_("options '--%s' and '--%s' may not be " |
683 "used together") % (opt, i)) | 694 "used together") % (opt, i)) |
684 return True | 695 return True |
685 if checkopt('cleanup', 'addremove delete list message name patch stat'): | 696 if checkopt('cleanup'): |
686 if pats: | 697 if pats: |
687 raise util.Abort(_("cannot specify names when using '--cleanup'")) | 698 raise util.Abort(_("cannot specify names when using '--cleanup'")) |
688 return cleanupcmd(ui, repo) | 699 return cleanupcmd(ui, repo) |
689 elif checkopt('delete', 'addremove cleanup list message name patch stat'): | 700 elif checkopt('delete'): |
690 return deletecmd(ui, repo, pats) | 701 return deletecmd(ui, repo, pats) |
691 elif checkopt('list', 'addremove cleanup delete message name'): | 702 elif checkopt('list'): |
692 return listcmd(ui, repo, pats, opts) | 703 return listcmd(ui, repo, pats, opts) |
693 else: | 704 else: |
694 for i in ('patch', 'stat'): | 705 for i in ('patch', 'stat'): |
695 if opts[i]: | 706 if opts[i]: |
696 raise util.Abort(_("option '--%s' may not be " | 707 raise util.Abort(_("option '--%s' may not be " |