# HG changeset patch # User Kostia Balytskyi <ikos...@fb.com> # Date 1489250294 28800 # Sat Mar 11 08:38:14 2017 -0800 # Node ID e06d7fd580a798de7818adae8b65eb166ea1defd # Parent 5179d6be9d6a33071c8a18cc48166a3f1d5ceec5 shelve: migrate config overrides to ui.configoverride
This patch also makes ui.quiet manipulations much more explicit and readable, addressing previous Yuya's concerns. diff --git a/hgext/shelve.py b/hgext/shelve.py --- a/hgext/shelve.py +++ b/hgext/shelve.py @@ -347,17 +347,16 @@ def getcommitfunc(extra, interactive, ed hasmq = util.safehasattr(repo, 'mq') if hasmq: saved, repo.mq.checkapplied = repo.mq.checkapplied, False - backup = repo.ui.backupconfig('phases', 'new-commit') try: - repo.ui.setconfig('phases', 'new-commit', phases.secret) - editor_ = False - if editor: - editor_ = cmdutil.getcommiteditor(editform='shelve.shelve', - **opts) - return repo.commit(message, shelveuser, opts.get('date'), match, - editor=editor_, extra=extra) + overrides = {('phases', 'new-commit'): phases.secret} + with repo.ui.configoverride(overrides): + editor_ = False + if editor: + editor_ = cmdutil.getcommiteditor(editform='shelve.shelve', + **opts) + return repo.commit(message, shelveuser, opts.get('date'), + match, editor=editor_, extra=extra) finally: - repo.ui.restoreconfig(backup) if hasmq: repo.mq.checkapplied = saved @@ -620,9 +619,7 @@ def unshelveabort(ui, repo, state, opts) def mergefiles(ui, repo, wctx, shelvectx): """updates to wctx and merges the changes from shelvectx into the dirstate.""" - oldquiet = ui.quiet - try: - ui.quiet = True + with ui.configoverride({('ui', 'quiet'): True}): hg.update(repo, wctx.node()) files = [] files.extend(shelvectx.files()) @@ -637,8 +634,6 @@ def mergefiles(ui, repo, wctx, shelvectx *pathtofiles(repo, files), **{'no_backup': True}) ui.popbuffer() - finally: - ui.quiet = oldquiet def restorebranch(ui, repo, branchtorestore): if branchtorestore and branchtorestore != repo.dirstate.branch(): @@ -709,17 +704,16 @@ def _commitworkingcopychanges(ui, repo, tempopts = {} tempopts['message'] = "pending changes temporary commit" tempopts['date'] = opts.get('date') - ui.quiet = True - node = cmdutil.commit(ui, repo, commitfunc, [], tempopts) + with ui.configoverride({('ui', 'quiet'): True}): + node = cmdutil.commit(ui, repo, commitfunc, [], tempopts) tmpwctx = repo[node] return tmpwctx, addedbefore -def _unshelverestorecommit(ui, repo, basename, oldquiet): +def _unshelverestorecommit(ui, repo, basename): """Recreate commit in the repository during the unshelve""" - ui.quiet = True - shelvedfile(repo, basename, 'hg').applybundle() - shelvectx = repo['tip'] - ui.quiet = oldquiet + with ui.configoverride({('ui', 'quiet'): True}): + shelvedfile(repo, basename, 'hg').applybundle() + shelvectx = repo['tip'] return repo, shelvectx def _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, basename, pctx, @@ -901,13 +895,9 @@ def _dounshelve(ui, repo, *shelved, **op if not shelvedfile(repo, basename, patchextension).exists(): raise error.Abort(_("shelved change '%s' not found") % basename) - oldquiet = ui.quiet lock = tr = None - forcemerge = ui.backupconfig('ui', 'forcemerge') try: - ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'unshelve') lock = repo.lock() - tr = repo.transaction('unshelve', report=lambda x: None) oldtiprev = len(repo) @@ -922,16 +912,18 @@ def _dounshelve(ui, repo, *shelved, **op tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts, tmpwctx) - repo, shelvectx = _unshelverestorecommit(ui, repo, basename, oldquiet) + repo, shelvectx = _unshelverestorecommit(ui, repo, basename) _checkunshelveuntrackedproblems(ui, repo, shelvectx) branchtorestore = '' if shelvectx.branch() != shelvectx.p1().branch(): branchtorestore = shelvectx.branch() - shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, - basename, pctx, tmpwctx, shelvectx, - branchtorestore) - mergefiles(ui, repo, pctx, shelvectx) + with ui.configoverride({('ui', 'forcemerge'): opts.get('tool', '')}, + 'unshelve'): + shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, + basename, pctx, tmpwctx, + shelvectx, branchtorestore) + mergefiles(ui, repo, pctx, shelvectx) restorebranch(ui, repo, branchtorestore) _forgetunknownfiles(repo, shelvectx, addedbefore) @@ -939,11 +931,9 @@ def _dounshelve(ui, repo, *shelved, **op _finishunshelve(repo, oldtiprev, tr) unshelvecleanup(ui, repo, basename, opts) finally: - ui.quiet = oldquiet if tr: tr.release() lockmod.release(lock) - ui.restoreconfig(forcemerge) @command('shelve', [('A', 'addremove', None, _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel