Patchwork D3741: update: use context manager for config override (API)

login
register
mail settings
Submitter phabricator
Date June 14, 2018, 11:34 p.m.
Message ID <differential-rev-PHID-DREV-ejp3ojw4wgiuzoe6m6zl-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/32151/
State Superseded
Headers show

Comments

phabricator - June 14, 2018, 11:34 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Note that update wasn't resetting the value before, so any extensions
  that called commands.update() and relied on ui.forcemerge being set
  after it returned would now have to set it themselves.
  
  (There technically a small API change in all of the patches in this
  series, I believe: If extensions relied on the methods to *clear*
  ui.forcemerge, then they would have to do that themselves now, because
  ui.configoverride() actually restores the previous config, it doesn't
  just clear it like these functions did before.)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3741

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5657,10 +5657,10 @@ 
         ctx = scmutil.revsingle(repo, rev, rev)
         rev = ctx.rev()
         hidden = ctx.hidden()
-        repo.ui.setconfig('ui', 'forcemerge', opts.get(r'tool'), 'update')
-
-        ret = hg.updatetotally(ui, repo, rev, brev, clean=clean,
-                               updatecheck=updatecheck)
+        overrides = {('ui', 'forcemerge'): opts.get('tool', '')}
+        with ui.configoverride(overrides, 'update'):
+            ret = hg.updatetotally(ui, repo, rev, brev, clean=clean,
+                                   updatecheck=updatecheck)
         if hidden:
             ctxstr = ctx.hex()[:12]
             ui.warn(_("updated to hidden changeset %s\n") % ctxstr)