##// END OF EJS Templates
import: use context manager for lock, dirstateguard, transaction...
Martin von Zweigbergk -
r38380:2ceea155 default
parent child Browse files
Show More
@@ -40,7 +40,6 b' from . import ('
40 hbisect,
40 hbisect,
41 help,
41 help,
42 hg,
42 hg,
43 lock as lockmod,
44 logcmdutil,
43 logcmdutil,
45 merge as mergemod,
44 merge as mergemod,
46 obsolete,
45 obsolete,
@@ -67,8 +66,6 b' from .utils import ('
67 stringutil,
66 stringutil,
68 )
67 )
69
68
70 release = lockmod.release
71
72 table = {}
69 table = {}
73 table.update(debugcommandsmod.command._table)
70 table.update(debugcommandsmod.command._table)
74
71
@@ -3111,22 +3108,24 b' def import_(ui, repo, patch1=None, *patc'
3111 raise error.Abort(_('cannot use --exact with --prefix'))
3108 raise error.Abort(_('cannot use --exact with --prefix'))
3112
3109
3113 base = opts["base"]
3110 base = opts["base"]
3114 dsguard = lock = tr = None
3115 msgs = []
3111 msgs = []
3116 ret = 0
3112 ret = 0
3117
3113
3118 with repo.wlock():
3114 with repo.wlock():
3119 try:
3115 if update:
3120 if update:
3116 cmdutil.checkunfinished(repo)
3121 cmdutil.checkunfinished(repo)
3117 if (exact or not opts.get('force')):
3122 if (exact or not opts.get('force')):
3118 cmdutil.bailifchanged(repo)
3123 cmdutil.bailifchanged(repo)
3119
3124
3120 if not opts.get('no_commit'):
3125 if not opts.get('no_commit'):
3121 lock = repo.lock
3126 lock = repo.lock()
3122 tr = lambda: repo.transaction('import')
3127 tr = repo.transaction('import')
3123 dsguard = util.nullcontextmanager
3128 else:
3124 else:
3129 dsguard = dirstateguard.dirstateguard(repo, 'import')
3125 lock = util.nullcontextmanager
3126 tr = util.nullcontextmanager
3127 dsguard = lambda: dirstateguard.dirstateguard(repo, 'import')
3128 with lock(), tr(), dsguard():
3130 parents = repo[None].parents()
3129 parents = repo[None].parents()
3131 for patchurl in patches:
3130 for patchurl in patches:
3132 if patchurl == '-':
3131 if patchurl == '-':
@@ -3162,17 +3161,9 b' def import_(ui, repo, patch1=None, *patc'
3162 if not haspatch:
3161 if not haspatch:
3163 raise error.Abort(_('%s: no diffs found') % patchurl)
3162 raise error.Abort(_('%s: no diffs found') % patchurl)
3164
3163
3165 if tr:
3166 tr.close()
3167 if msgs:
3164 if msgs:
3168 repo.savecommitmessage('\n* * *\n'.join(msgs))
3165 repo.savecommitmessage('\n* * *\n'.join(msgs))
3169 if dsguard:
3166 return ret
3170 dsguard.close()
3171 return ret
3172 finally:
3173 if tr:
3174 tr.release()
3175 release(lock, dsguard)
3176
3167
3177 @command('incoming|in',
3168 @command('incoming|in',
3178 [('f', 'force', None,
3169 [('f', 'force', None,
General Comments 0
You need to be logged in to leave comments. Login now