Patchwork D406: commit: use context manager with dirstateguard

login
register
mail settings
Submitter phabricator
Date Aug. 15, 2017, 9:32 p.m.
Message ID <ea294a7e2f75fc887bb843fe6d15ae2d@localhost.localdomain>
Download mbox | patch
Permalink /patch/23053/
State Not Applicable
Headers show

Comments

phabricator - Aug. 15, 2017, 9:32 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG158dddc635ff: commit: use context manager with dirstateguard (authored by martinvonz).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D406?vs=922&id=952

REVISION DETAIL
  https://phab.mercurial-scm.org/D406

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3000,19 +3000,13 @@ 
     # that doesn't support addremove
     if opts.get('addremove'):
         dsguard = dirstateguard.dirstateguard(repo, 'commit')
-    try:
+    with dsguard or util.nullcontextmanager():
         if dsguard:
             if scmutil.addremove(repo, matcher, "", opts) != 0:
                 raise error.Abort(
                     _("failed to mark all new/missing files as added/removed"))
 
-        r = commitfunc(ui, repo, message, matcher, opts)
-        if dsguard:
-            dsguard.close()
-        return r
-    finally:
-        if dsguard:
-            dsguard.release()
+        return commitfunc(ui, repo, message, matcher, opts)
 
 def samefile(f, ctx1, ctx2):
     if f in ctx1.manifest():