Mercurial > hg
comparison tests/drawdag.py @ 33172:0830c841fc7f
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.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 30 Jun 2017 23:15:09 -0700 |
parents | 4d780d510b44 |
children | 0103e7187237 |
comparison
equal
deleted
inserted
replaced
33171:6d678ab1b10d | 33172:0830c841fc7f |
---|---|
81 # prune: A, B, C # many to nothing | 81 # prune: A, B, C # many to nothing |
82 """ | 82 """ |
83 from __future__ import absolute_import, print_function | 83 from __future__ import absolute_import, print_function |
84 | 84 |
85 import collections | 85 import collections |
86 import contextlib | |
87 import itertools | 86 import itertools |
88 | 87 |
89 from mercurial.i18n import _ | 88 from mercurial.i18n import _ |
90 from mercurial import ( | 89 from mercurial import ( |
91 context, | 90 context, |
275 del remaining[leaf] | 274 del remaining[leaf] |
276 for k, v in remaining.iteritems(): | 275 for k, v in remaining.iteritems(): |
277 if leaf in v: | 276 if leaf in v: |
278 v.remove(leaf) | 277 v.remove(leaf) |
279 | 278 |
280 @contextlib.contextmanager | |
281 def transaction(repo): | |
282 with repo.wlock(): | |
283 with repo.lock(): | |
284 with repo.transaction('drawdag'): | |
285 yield | |
286 | |
287 @command('debugdrawdag', []) | 279 @command('debugdrawdag', []) |
288 def debugdrawdag(ui, repo, **opts): | 280 def debugdrawdag(ui, repo, **opts): |
289 """read an ASCII graph from stdin and create changesets | 281 """read an ASCII graph from stdin and create changesets |
290 | 282 |
291 The ASCII graph is like what :hg:`log -G` outputs, with each `o` replaced | 283 The ASCII graph is like what :hg:`log -G` outputs, with each `o` replaced |
330 committed[name] = n | 322 committed[name] = n |
331 tagsmod.tag(repo, name, n, message=None, user=None, date=None, | 323 tagsmod.tag(repo, name, n, message=None, user=None, date=None, |
332 local=True) | 324 local=True) |
333 | 325 |
334 # handle special comments | 326 # handle special comments |
335 with transaction(repo): | 327 with repo.wlock(), repo.lock(), repo.transaction('drawdag'): |
336 getctx = lambda x: repo.unfiltered()[committed[x.strip()]] | 328 getctx = lambda x: repo.unfiltered()[committed[x.strip()]] |
337 for line in text.splitlines(): | 329 for line in text.splitlines(): |
338 if ' # ' not in line: | 330 if ' # ' not in line: |
339 continue | 331 continue |
340 | 332 |