diff --git a/hgext3rd/absorb/__init__.py b/hgext3rd/absorb/__init__.py --- a/hgext3rd/absorb/__init__.py +++ b/hgext3rd/absorb/__init__.py @@ -642,17 +642,16 @@ def commit(self): """commit changes. update self.finalnode, self.replacemap""" - with self.repo.wlock(): # update bookmarks - with self.repo.lock(): # commit - with self.repo.transaction('absorb') as tr: - self._commitstack() - self._movebookmarks(tr) - if self.repo['.'].node() in self.replacemap: - self._moveworkingdirectoryparent() - if self._useobsolete: - self._obsoleteoldcommits() - if not self._useobsolete: # strip must be outside transactions - self._stripoldcommits() + with self.repo.wlock(), self.repo.lock(): + with self.repo.transaction('absorb') as tr: + self._commitstack() + self._movebookmarks(tr) + if self.repo['.'].node() in self.replacemap: + self._moveworkingdirectoryparent() + if self._useobsolete: + self._obsoleteoldcommits() + if not self._useobsolete: # strip must be outside transactions + self._stripoldcommits() return self.finalnode def printchunkstats(self): diff --git a/hgext3rd/fbamend/__init__.py b/hgext3rd/fbamend/__init__.py --- a/hgext3rd/fbamend/__init__.py +++ b/hgext3rd/fbamend/__init__.py @@ -420,14 +420,12 @@ """ repo = repo.unfiltered() cl = repo.changelog - with repo.wlock(): - with repo.lock(): - with repo.transaction('movebookmarks') as tr: - for rev in revs: - latest = cl.node(common.latest(repo, rev)) - for bm in repo.nodebookmarks(cl.node(rev)): - repo._bookmarks[bm] = latest - repo._bookmarks.recordchange(tr) + with repo.wlock(), repo.lock(), repo.transaction('movebookmarks') as tr: + for rev in revs: + latest = cl.node(common.latest(repo, rev)) + for bm in repo.nodebookmarks(cl.node(rev)): + repo._bookmarks[bm] = latest + repo._bookmarks.recordchange(tr) ### bookmarks api compatibility layer ### def bmactivate(repo, mark): diff --git a/hgext3rd/fbamend/movement.py b/hgext3rd/fbamend/movement.py --- a/hgext3rd/fbamend/movement.py +++ b/hgext3rd/fbamend/movement.py @@ -111,37 +111,36 @@ elif opts.get('rebase', False): raise error.Abort(_("cannot use both --merge and --rebase")) - with repo.wlock(): - with repo.lock(): - # Record the active bookmark, if any. - bookmark = repo._activebookmark - noactivate = opts.get('no_activate_bookmark', False) - movebookmark = opts.get('move_bookmark', False) + with repo.wlock(), repo.lock(): + # Record the active bookmark, if any. + bookmark = repo._activebookmark + noactivate = opts.get('no_activate_bookmark', False) + movebookmark = opts.get('move_bookmark', False) - with repo.transaction('moverelative') as tr: - # Find the desired changeset. May potentially perform rebase. - try: - target = _findtarget(ui, repo, n, opts, reverse) - except error.InterventionRequired: - # Rebase failed. Need to manually close transaction to allow - # `hg rebase --continue` to work correctly. - tr.close() - raise + with repo.transaction('moverelative') as tr: + # Find the desired changeset. May potentially perform rebase. + try: + target = _findtarget(ui, repo, n, opts, reverse) + except error.InterventionRequired: + # Rebase failed. Need to manually close transaction to allow + # `hg rebase --continue` to work correctly. + tr.close() + raise - # Move the active bookmark if neccesary. Needs to happen before - # we update to avoid getting a 'leaving bookmark X' message. - if movebookmark and bookmark is not None: - _setbookmark(repo, tr, bookmark, target) + # Move the active bookmark if neccesary. Needs to happen before + # we update to avoid getting a 'leaving bookmark X' message. + if movebookmark and bookmark is not None: + _setbookmark(repo, tr, bookmark, target) - # Update to the target changeset. - commands.update(ui, repo, rev=target) + # Update to the target changeset. + commands.update(ui, repo, rev=target) - # Print out the changeset we landed on. - _showchangesets(ui, repo, revs=[target]) + # Print out the changeset we landed on. + _showchangesets(ui, repo, revs=[target]) - # Activate the bookmark on the new changeset. - if not noactivate and not movebookmark: - _activate(ui, repo, target) + # Activate the bookmark on the new changeset. + if not noactivate and not movebookmark: + _activate(ui, repo, target) def _findtarget(ui, repo, n, opts, reverse): """Find the appropriate target changeset for `hg previous` and diff --git a/hgext3rd/fbamend/restack.py b/hgext3rd/fbamend/restack.py --- a/hgext3rd/fbamend/restack.py +++ b/hgext3rd/fbamend/restack.py @@ -26,39 +26,38 @@ if rebaseopts is None: rebaseopts = {} - with repo.wlock(): - with repo.lock(): - cmdutil.checkunfinished(repo) - cmdutil.bailifchanged(repo) + with repo.wlock(), repo.lock(): + cmdutil.checkunfinished(repo) + cmdutil.bailifchanged(repo) - # Find the latest version of the changeset at the botom of the - # current stack. If the current changeset is public, simply start - # restacking from the current changeset with the assumption - # that there are non-public changesets higher up. - base = repo.revs('::. & draft()').first() - latest = (common.latest(repo, base) if base is not None - else repo['.'].rev()) - targets = _findrestacktargets(repo, latest) + # Find the latest version of the changeset at the botom of the + # current stack. If the current changeset is public, simply start + # restacking from the current changeset with the assumption + # that there are non-public changesets higher up. + base = repo.revs('::. & draft()').first() + latest = (common.latest(repo, base) if base is not None + else repo['.'].rev()) + targets = _findrestacktargets(repo, latest) - with repo.transaction('restack') as tr: - # Attempt to stabilize all changesets that are or will be (after - # rebasing) descendants of base. - for rev in targets: - try: - common.restackonce(ui, repo, rev, rebaseopts) - except error.InterventionRequired: - tr.close() - raise + with repo.transaction('restack') as tr: + # Attempt to stabilize all changesets that are or will be (after + # rebasing) descendants of base. + for rev in targets: + try: + common.restackonce(ui, repo, rev, rebaseopts) + except error.InterventionRequired: + tr.close() + raise - # Ensure that we always end up on the latest version of the - # current changeset. Usually, this will be taken care of - # by the rebase operation. However, in some cases (such as - # if we are on the precursor of the base changeset) the - # rebase will not update to the latest version, so we need - # to do this manually. - successor = repo.revs('allsuccessors(.)').last() - if successor is not None: - commands.update(ui, repo, rev=successor) + # Ensure that we always end up on the latest version of the + # current changeset. Usually, this will be taken care of + # by the rebase operation. However, in some cases (such as + # if we are on the precursor of the base changeset) the + # rebase will not update to the latest version, so we need + # to do this manually. + successor = repo.revs('allsuccessors(.)').last() + if successor is not None: + commands.update(ui, repo, rev=successor) def _findrestacktargets(repo, base): """Starting from the given base revision, do a BFS forwards through diff --git a/hgext3rd/fbamend/unamend.py b/hgext3rd/fbamend/unamend.py --- a/hgext3rd/fbamend/unamend.py +++ b/hgext3rd/fbamend/unamend.py @@ -56,30 +56,29 @@ if curctx.children(): raise error.Abort(_("cannot unamend in the middle of a stack")) - with repo.wlock(): - with repo.lock(): - repobookmarks = repo._bookmarks - ctxbookmarks = curctx.bookmarks() - changedfiles = [] - wctx = repo[None] - wm = wctx.manifest() - cm = precctx.manifest() - dirstate = repo.dirstate - diff = cm.diff(wm) - changedfiles.extend(diff.iterkeys()) + with repo.wlock(), repo.lock(): + repobookmarks = repo._bookmarks + ctxbookmarks = curctx.bookmarks() + changedfiles = [] + wctx = repo[None] + wm = wctx.manifest() + cm = precctx.manifest() + dirstate = repo.dirstate + diff = cm.diff(wm) + changedfiles.extend(diff.iterkeys()) - tr = repo.transaction('unamend') - with dirstate.parentchange(): - dirstate.rebuild(precnode, cm, changedfiles) - # we want added and removed files to be shown - # properly, not with ? and ! prefixes - for filename, data in diff.iteritems(): - if data[0][0] is None: - dirstate.add(filename) - if data[1][0] is None: - dirstate.remove(filename) - for book in ctxbookmarks: - repobookmarks[book] = precnode - repobookmarks.recordchange(tr) - obsolete.createmarkers(repo, [(curctx, (precctx,))]) - tr.close() + tr = repo.transaction('unamend') + with dirstate.parentchange(): + dirstate.rebuild(precnode, cm, changedfiles) + # we want added and removed files to be shown + # properly, not with ? and ! prefixes + for filename, data in diff.iteritems(): + if data[0][0] is None: + dirstate.add(filename) + if data[1][0] is None: + dirstate.remove(filename) + for book in ctxbookmarks: + repobookmarks[book] = precnode + repobookmarks.recordchange(tr) + obsolete.createmarkers(repo, [(curctx, (precctx,))]) + tr.close() diff --git a/hgext3rd/fixcorrupt.py b/hgext3rd/fixcorrupt.py --- a/hgext3rd/fixcorrupt.py +++ b/hgext3rd/fixcorrupt.py @@ -146,19 +146,18 @@ # truncate revlogs backupprefix = '%s-' % int(time.time()) - with repo.wlock(): - with repo.lock(): - repo.destroying() - for name, log in logs: - rev, linkrev = badrevs[name] - ui.write(_('%s: will lose %d revisions\n') - % (name, len(log) - 1 - rev)) - truncate(ui, repo, log.datafile, log.start(rev), dryrun, - backupprefix) - truncate(ui, repo, log.indexfile, rev * 64, dryrun, - backupprefix) - if dryrun: - ui.write(_('re-run with --no-dryrun to fix.\n')) - else: - ui.write(_('fix completed. re-run to check more revisions.\n')) - repo.destroyed() + with repo.wlock(), repo.lock(): + repo.destroying() + for name, log in logs: + rev, linkrev = badrevs[name] + ui.write(_('%s: will lose %d revisions\n') + % (name, len(log) - 1 - rev)) + truncate(ui, repo, log.datafile, log.start(rev), dryrun, + backupprefix) + truncate(ui, repo, log.indexfile, rev * 64, dryrun, + backupprefix) + if dryrun: + ui.write(_('re-run with --no-dryrun to fix.\n')) + else: + ui.write(_('fix completed. re-run to check more revisions.\n')) + repo.destroyed() diff --git a/hgext3rd/pullcreatemarkers.py b/hgext3rd/pullcreatemarkers.py --- a/hgext3rd/pullcreatemarkers.py +++ b/hgext3rd/pullcreatemarkers.py @@ -56,8 +56,7 @@ if not tocreate: return r - with unfiltered.lock(): - with unfiltered.transaction('pullcreatemarkers'): - obsolete.createmarkers(unfiltered, tocreate) + with unfiltered.lock(), unfiltered.transaction('pullcreatemarkers'): + obsolete.createmarkers(unfiltered, tocreate) return r diff --git a/hgext3rd/uncommit.py b/hgext3rd/uncommit.py --- a/hgext3rd/uncommit.py +++ b/hgext3rd/uncommit.py @@ -140,33 +140,32 @@ modified in the working directory. """ - with repo.wlock(): - with repo.lock(): - wctx = repo[None] + with repo.wlock(), repo.lock(): + wctx = repo[None] - if len(wctx.parents()) <= 0 or not wctx.parents()[0]: - raise error.Abort(_("cannot uncommit null changeset")) - if len(wctx.parents()) > 1: - raise error.Abort(_("cannot uncommit while merging")) - old = repo['.'] - oldphase = old.phase() - if oldphase == phases.public: - raise error.Abort(_("cannot rewrite immutable changeset")) - if len(old.parents()) > 1: - raise error.Abort(_("cannot uncommit merge changeset")) + if len(wctx.parents()) <= 0 or not wctx.parents()[0]: + raise error.Abort(_("cannot uncommit null changeset")) + if len(wctx.parents()) > 1: + raise error.Abort(_("cannot uncommit while merging")) + old = repo['.'] + oldphase = old.phase() + if oldphase == phases.public: + raise error.Abort(_("cannot rewrite immutable changeset")) + if len(old.parents()) > 1: + raise error.Abort(_("cannot uncommit merge changeset")) - with repo.transaction('uncommit') as tr: - match = scmutil.match(old, pats, opts) - newid = _commitfiltered(repo, old, match) - if newid is None: - raise error.Abort(_('nothing to uncommit')) + with repo.transaction('uncommit') as tr: + match = scmutil.match(old, pats, opts) + newid = _commitfiltered(repo, old, match) + if newid is None: + raise error.Abort(_('nothing to uncommit')) - # Move local changes on filtered changeset - obsolete.createmarkers(repo, [(old, (repo[newid],))]) - phases.retractboundary(repo, tr, oldphase, [newid]) + # Move local changes on filtered changeset + obsolete.createmarkers(repo, [(old, (repo[newid],))]) + phases.retractboundary(repo, tr, oldphase, [newid]) - with repo.dirstate.parentchange(): - repo.dirstate.setparents(newid, node.nullid) - _uncommitdirstate(repo, old, match) + with repo.dirstate.parentchange(): + repo.dirstate.setparents(newid, node.nullid) + _uncommitdirstate(repo, old, match) - _updatebookmarks(repo, old.node(), newid, tr) + _updatebookmarks(repo, old.node(), newid, tr) diff --git a/hgext3rd/undo.py b/hgext3rd/undo.py --- a/hgext3rd/undo.py +++ b/hgext3rd/undo.py @@ -54,9 +54,8 @@ def safelog(repo, command): if repo is not None:# some hg commands don't require repo - with repo.lock(): - with repo.transaction("undolog"): - log(repo.filtered('visible'), command) + with repo.lock(), repo.transaction("undolog"): + log(repo.filtered('visible'), command) def log(repo, command): newnodes = { diff --git a/infinitepush/__init__.py b/infinitepush/__init__.py --- a/infinitepush/__init__.py +++ b/infinitepush/__init__.py @@ -733,13 +733,11 @@ def _savelocalbookmarks(repo, bookmarks): if not bookmarks: return - with repo.wlock(): - with repo.lock(): - with repo.transaction('bookmark') as tr: - for scratchbook, node in bookmarks.iteritems(): - changectx = repo[node] - repo._bookmarks[scratchbook] = changectx.node() - repo._bookmarks.recordchange(tr) + with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: + for scratchbook, node in bookmarks.iteritems(): + changectx = repo[node] + repo._bookmarks[scratchbook] = changectx.node() + repo._bookmarks.recordchange(tr) def _findcommonincoming(orig, *args, **kwargs): common, inc, remoteheads = orig(*args, **kwargs) @@ -1007,14 +1005,13 @@ bundlesize=len(bundledata)): key = store.write(bundledata) - with logservicecall(log, 'index', newheadscount=newheadscount): - with index: - if key: - index.addbundle(key, nodesctx) - if bookmark: - index.addbookmark(bookmark, bookmarknode) - _maybeaddpushbackpart(op, bookmark, bookmarknode, - bookprevnode, params) + with logservicecall(log, 'index', newheadscount=newheadscount), index: + if key: + index.addbundle(key, nodesctx) + if bookmark: + index.addbookmark(bookmark, bookmarknode) + _maybeaddpushbackpart(op, bookmark, bookmarknode, + bookprevnode, params) log(scratchbranchparttype, eventtype='success', elapsedms=(time.time() - parthandlerstart) * 1000) @@ -1056,12 +1053,11 @@ else: todelete.append(bookmark) log = _getorcreateinfinitepushlogger(op) - with logservicecall(log, scratchbookmarksparttype): - with index: - if todelete: - index.deletebookmarks(todelete) - if toinsert: - index.addmanybookmarks(toinsert) + with logservicecall(log, scratchbookmarksparttype), index: + if todelete: + index.deletebookmarks(todelete) + if toinsert: + index.addmanybookmarks(toinsert) def _maybeaddpushbackpart(op, bookmark, newnode, oldnode, params): if params.get('pushbackbookmarks'): diff --git a/infinitepush/backupcommands.py b/infinitepush/backupcommands.py --- a/infinitepush/backupcommands.py +++ b/infinitepush/backupcommands.py @@ -223,16 +223,14 @@ pullopts['source'] = dest result = pullcmd(ui, repo, **pullopts) - with repo.wlock(): - with repo.lock(): - with repo.transaction('bookmark') as tr: - for book, hexnode in backupstate.localbookmarks.iteritems(): - if hexnode in repo: - repo._bookmarks[book] = bin(hexnode) - else: - ui.warn(_('%s not found, not creating %s bookmark') % - (hexnode, book)) - repo._bookmarks.recordchange(tr) + with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: + for book, hexnode in backupstate.localbookmarks.iteritems(): + if hexnode in repo: + repo._bookmarks[book] = bin(hexnode) + else: + ui.warn(_('%s not found, not creating %s bookmark') % + (hexnode, book)) + repo._bookmarks.recordchange(tr) return result diff --git a/treemanifest/__init__.py b/treemanifest/__init__.py --- a/treemanifest/__init__.py +++ b/treemanifest/__init__.py @@ -332,10 +332,8 @@ ('l', 'limit', '10000000', _('')) ], _('hg backfilltree [OPTIONS]')) def backfilltree(ui, repo, *args, **opts): - with repo.wlock(): - with repo.lock(): - with repo.transaction('backfilltree') as tr: - _backfill(tr, repo, int(opts.get('limit'))) + with repo.wlock(), repo.lock(), repo.transaction('backfilltree') as tr: + _backfill(tr, repo, int(opts.get('limit'))) def _backfill(tr, repo, limit): ui = repo.ui