Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 33845:158dddc635ff
commit: use context manager with dirstateguard
When I wrote 5ac845ca059a (commit: don't let failed commit with
--addremove update dirstate (issue5645), 2017-07-31), Durham's
609606d21765 (rebase: use one dirstateguard for when using
rebase.singletransaction, 2017-07-20) had not yet landed, so I had to
write it in the old-fashioned way. Now that Durham's patch is in, we
can simplify by using a context manager.
Differential Revision: https://phab.mercurial-scm.org/D406
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 14 Aug 2017 23:26:54 -0700 |
parents | 5d286eb7009f |
children | eae63a9e59da |
comparison
equal
deleted
inserted
replaced
33844:5d286eb7009f | 33845:158dddc635ff |
---|---|
2998 dsguard = None | 2998 dsguard = None |
2999 # extract addremove carefully -- this function can be called from a command | 2999 # extract addremove carefully -- this function can be called from a command |
3000 # that doesn't support addremove | 3000 # that doesn't support addremove |
3001 if opts.get('addremove'): | 3001 if opts.get('addremove'): |
3002 dsguard = dirstateguard.dirstateguard(repo, 'commit') | 3002 dsguard = dirstateguard.dirstateguard(repo, 'commit') |
3003 try: | 3003 with dsguard or util.nullcontextmanager(): |
3004 if dsguard: | 3004 if dsguard: |
3005 if scmutil.addremove(repo, matcher, "", opts) != 0: | 3005 if scmutil.addremove(repo, matcher, "", opts) != 0: |
3006 raise error.Abort( | 3006 raise error.Abort( |
3007 _("failed to mark all new/missing files as added/removed")) | 3007 _("failed to mark all new/missing files as added/removed")) |
3008 | 3008 |
3009 r = commitfunc(ui, repo, message, matcher, opts) | 3009 return commitfunc(ui, repo, message, matcher, opts) |
3010 if dsguard: | |
3011 dsguard.close() | |
3012 return r | |
3013 finally: | |
3014 if dsguard: | |
3015 dsguard.release() | |
3016 | 3010 |
3017 def samefile(f, ctx1, ctx2): | 3011 def samefile(f, ctx1, ctx2): |
3018 if f in ctx1.manifest(): | 3012 if f in ctx1.manifest(): |
3019 a = ctx1.filectx(f) | 3013 a = ctx1.filectx(f) |
3020 if f in ctx2.manifest(): | 3014 if f in ctx2.manifest(): |