Mercurial > public > mercurial-scm > hg
comparison mercurial/debugcommands.py @ 38376:0d7ec620faef
debugbuilddag: use context manager for progress, locks, transaction
I minor side-effect is that .hg/localtags is now written before the
transaction commits.
Differential Revision: https://phab.mercurial-scm.org/D3777
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 17 Jun 2018 21:47:34 -0700 |
parents | fce1c17493db |
children | a0c3d83d5f04 |
comparison
equal
deleted
inserted
replaced
38375:fce1c17493db | 38376:0d7ec620faef |
---|---|
179 # make a file with k lines per rev | 179 # make a file with k lines per rev |
180 initialmergedlines = ['%d' % i for i in xrange(0, total * linesperrev)] | 180 initialmergedlines = ['%d' % i for i in xrange(0, total * linesperrev)] |
181 initialmergedlines.append("") | 181 initialmergedlines.append("") |
182 | 182 |
183 tags = [] | 183 tags = [] |
184 | |
185 wlock = lock = tr = None | |
186 progress = ui.makeprogress(_('building'), unit=_('revisions'), | 184 progress = ui.makeprogress(_('building'), unit=_('revisions'), |
187 total=total) | 185 total=total) |
188 try: | 186 with progress, repo.wlock(), repo.lock(), repo.transaction("builddag"): |
189 wlock = repo.wlock() | |
190 lock = repo.lock() | |
191 tr = repo.transaction("builddag") | |
192 | |
193 at = -1 | 187 at = -1 |
194 atbranch = 'default' | 188 atbranch = 'default' |
195 nodeids = [] | 189 nodeids = [] |
196 id = 0 | 190 id = 0 |
197 progress.update(id) | 191 progress.update(id) |
266 tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) | 260 tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) |
267 elif type == 'a': | 261 elif type == 'a': |
268 ui.note(('branch %s\n' % data)) | 262 ui.note(('branch %s\n' % data)) |
269 atbranch = data | 263 atbranch = data |
270 progress.update(id) | 264 progress.update(id) |
271 tr.close() | |
272 | 265 |
273 if tags: | 266 if tags: |
274 repo.vfs.write("localtags", "".join(tags)) | 267 repo.vfs.write("localtags", "".join(tags)) |
275 finally: | |
276 progress.complete() | |
277 release(tr, lock, wlock) | |
278 | 268 |
279 def _debugchangegroup(ui, gen, all=None, indent=0, **opts): | 269 def _debugchangegroup(ui, gen, all=None, indent=0, **opts): |
280 indent_string = ' ' * indent | 270 indent_string = ' ' * indent |
281 if all: | 271 if all: |
282 ui.write(("%sformat: id, p1, p2, cset, delta base, len(delta)\n") | 272 ui.write(("%sformat: id, p1, p2, cset, delta base, len(delta)\n") |