drawdag: inline transaction() function
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 30 Jun 2017 23:15:09 -0700
changeset 33172 0830c841fc7f
parent 33171 6d678ab1b10d
child 33173 4b0da963586d
drawdag: inline transaction() function I suspect Jun wrote the method before he learnt that Python 2.7 allows multiple context managers in a single with-clause.
tests/drawdag.py
--- a/tests/drawdag.py	Sun Jun 25 12:41:34 2017 -0700
+++ b/tests/drawdag.py	Fri Jun 30 23:15:09 2017 -0700
@@ -83,7 +83,6 @@
 from __future__ import absolute_import, print_function
 
 import collections
-import contextlib
 import itertools
 
 from mercurial.i18n import _
@@ -277,13 +276,6 @@
                 if leaf in v:
                     v.remove(leaf)
 
-@contextlib.contextmanager
-def transaction(repo):
-    with repo.wlock():
-        with repo.lock():
-            with repo.transaction('drawdag'):
-                yield
-
 @command('debugdrawdag', [])
 def debugdrawdag(ui, repo, **opts):
     """read an ASCII graph from stdin and create changesets
@@ -332,7 +324,7 @@
                     local=True)
 
     # handle special comments
-    with transaction(repo):
+    with repo.wlock(), repo.lock(), repo.transaction('drawdag'):
         getctx = lambda x: repo.unfiltered()[committed[x.strip()]]
         for line in text.splitlines():
             if ' # ' not in line: