D406: commit: use context manager with dirstateguard

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Aug 15 17:32:55 EDT 2017


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

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():



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


More information about the Mercurial-devel mailing list