[PATCH 1 of 2 V3] shelve: changes getting opts values by get method

liscju piotr.listkiewicz at gmail.com
Wed Mar 9 04:37:04 EST 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1457508117 -3600
#      Wed Mar 09 08:21:57 2016 +0100
# Node ID 99d42ff5175af8e03eedb8515395d89c0132319c
# Parent  c7f89ad87baef87f00c507545dfd4cc824bc3131
shelve: changes getting opts values by get method

When shelve is used by another extension that doesn't
provide all necessary values in opts shelve raises
KeyError exception. This patch fixes this by getting
values from opts dictionary with get method.

diff -r c7f89ad87bae -r 99d42ff5175a hgext/shelve.py
--- a/hgext/shelve.py	Mon Feb 29 17:52:17 2016 -0600
+++ b/hgext/shelve.py	Wed Mar 09 08:21:57 2016 +0100
@@ -269,10 +269,10 @@ def _docreatecmd(ui, repo, pats, opts):
     else:
         desc = '(changes in empty repository)'
 
-    if not opts['message']:
+    if not opts.get('message'):
         opts['message'] = desc
 
-    name = opts['name']
+    name = opts.get('name')
 
     lock = tr = None
     try:
@@ -519,7 +519,7 @@ def mergefiles(ui, repo, wctx, shelvectx
 
 def unshelvecleanup(ui, repo, name, opts):
     """remove related files after an unshelve"""
-    if not opts['keep']:
+    if not opts.get('keep'):
         for filetype in 'hg patch'.split():
             shelvedfile(repo, name, filetype).movetobackup()
         cleanupoldbackups(repo)
@@ -609,8 +609,8 @@ def unshelve(ui, repo, *shelved, **opts)
         return _dounshelve(ui, repo, *shelved, **opts)
 
 def _dounshelve(ui, repo, *shelved, **opts):
-    abortf = opts['abort']
-    continuef = opts['continue']
+    abortf = opts.get('abort')
+    continuef = opts.get('continue')
     if not abortf and not continuef:
         cmdutil.checkunfinished(repo)
 
@@ -829,7 +829,7 @@ def shelvecmd(ui, repo, *pats, **opts):
         ('stat', set(['stat', 'list'])),
     ]
     def checkopt(opt):
-        if opts[opt]:
+        if opts.get(opt):
             for i, allowable in allowables:
                 if opts[i] and opt not in allowable:
                     raise error.Abort(_("options '--%s' and '--%s' may not be "


More information about the Mercurial-devel mailing list