From patchwork Thu Jun 5 14:12:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 3, V2] shelve: refactor option combination check to add new one easily From: Katsunori FUJIWARA X-Patchwork-Id: 4938 Message-Id: To: mercurial-devel@selenic.com Date: Thu, 05 Jun 2014 23:12:04 +0900 # HG changeset patch # User FUJIWARA Katsunori # Date 1401977395 -32400 # Thu Jun 05 23:09:55 2014 +0900 # Node ID c90c042600bcb28108366b8c08a06d9ac3259ab7 # Parent 804a341610d154c8a2a4d3d63e36ff2cf08acc4f shelve: refactor option combination check to add new one easily Before this patch, the name of the newly added option should be added into each strings to be passed to 'checkopt()' internal function: these are white-space-separated list of un-acceptable option names. The name of new option should be added into multiple strings, because every options can belong to only one category of 'create', 'cleanup', 'delete' or 'list'. In addition of this redundancy, each strings passed to 'checkopt()' are already too long to include new one. This patch refactors option combination check to add new one easily in succeeding patch. New 'checkopt()' takes only one of categories ('cleanup', 'delete' or 'list'), and checks whether option allowed only for other categories is specified or not, if specified category is activated in 'opts'. 'date' entry is listed in 'allowableopts', 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. - but explicit listing it up can advertise that this ignoring is intentional diff --git a/hgext/shelve.py b/hgext/shelve.py --- a/hgext/shelve.py +++ b/hgext/shelve.py @@ -675,20 +675,31 @@ ''' cmdutil.checkunfinished(repo) - def checkopt(opt, incompatible): + allowableopts = { # 'create' is pseudo option + 'addremove': 'create', + 'cleanup': 'cleanup', +# 'date': 'create', # ignored for passing '--date "0 0"' always in tests + 'delete': 'delete', + 'list': 'list', + 'message': 'create', + 'name': 'create', + 'patch': 'list', + 'stat': 'list', + } + def checkopt(opt): if opts[opt]: - for i in incompatible.split(): - if opts[i]: + for i, a in allowableopts.iteritems(): + if opts[i] and a != opt: raise util.Abort(_("options '--%s' and '--%s' may not be " "used together") % (opt, i)) return True - if checkopt('cleanup', 'addremove delete list message name patch stat'): + if checkopt('cleanup'): if pats: raise util.Abort(_("cannot specify names when using '--cleanup'")) return cleanupcmd(ui, repo) - elif checkopt('delete', 'addremove cleanup list message name patch stat'): + elif checkopt('delete'): return deletecmd(ui, repo, pats) - elif checkopt('list', 'addremove cleanup delete message name'): + elif checkopt('list'): return listcmd(ui, repo, pats, opts) else: for i in ('patch', 'stat'):