Patchwork [8,of,8] shelve: get rid of ui.backupconfig

login
register
mail settings
Submitter Jun Wu
Date March 16, 2017, 9:57 p.m.
Message ID <4f98fa7baebed161fe94.1489701423@localhost.localdomain>
Download mbox | patch
Permalink /patch/19409/
State Accepted
Headers show

Comments

Jun Wu - March 16, 2017, 9:57 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1489699661 25200
#      Thu Mar 16 14:27:41 2017 -0700
# Node ID 4f98fa7baebed161fe94c98661a8c404dd82a87d
# Parent  8f87b407da24ee802e271f517dbc96ad32f21779
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 4f98fa7baebe
shelve: get rid of ui.backupconfig
Kostia Balytskyi - March 21, 2017, 12:01 p.m.
FYI, a very similar patch is a part of the latest shevle series I sent.

On 16/03/2017 21:57, Jun Wu wrote:
> # HG changeset patch

> # User Jun Wu <quark@fb.com>

> # Date 1489699661 25200

> #      Thu Mar 16 14:27:41 2017 -0700

> # Node ID 4f98fa7baebed161fe94c98661a8c404dd82a87d

> # Parent  8f87b407da24ee802e271f517dbc96ad32f21779

> # Available At https://bitbucket.org/quark-zju/hg-draft

> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 4f98fa7baebe

> shelve: get rid of ui.backupconfig

>

> diff --git a/hgext/shelve.py b/hgext/shelve.py

> --- a/hgext/shelve.py

> +++ b/hgext/shelve.py

> @@ -315,15 +315,14 @@ def getcommitfunc(extra, interactive, ed

>           if hasmq:

>               saved, repo.mq.checkapplied = repo.mq.checkapplied, False

> -        backup = repo.ui.backupconfig('phases', 'new-commit')

> +        override = {('phases', 'new-commit'): phases.secret}

>           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)

> +            with repo.ui.configoverride(override):

> +                return repo.commit(message, shelveuser, opts.get('date'),

> +                                   match, editor=editor_, extra=extra)

>           finally:

> -            repo.ui.restoreconfig(backup)

>               if hasmq:

>                   repo.mq.checkapplied = saved

> @@ -851,7 +850,5 @@ def _dounshelve(ui, repo, *shelved, **op

>       oldquiet = ui.quiet

>       lock = tr = None

> -    forcemerge = ui.backupconfig('ui', 'forcemerge')

>       try:

> -        ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'unshelve')

>           lock = repo.lock()

>   

> @@ -867,23 +864,26 @@ def _dounshelve(ui, repo, *shelved, **op

>           # to the original pctx.

>   

> -        tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,

> -                                                         tmpwctx)

> -

> -        repo, shelvectx = _unshelverestorecommit(ui, repo, basename, oldquiet)

> -        _checkunshelveuntrackedproblems(ui, repo, shelvectx)

> -        branchtorestore = ''

> -        if shelvectx.branch() != shelvectx.p1().branch():

> -            branchtorestore = shelvectx.branch()

> +        override = {('ui', 'forcemerge'): opts.get('tool', '')}

> +        with ui.configoverride(override, 'unshelve'):

> +            tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,

> +                                                             tmpwctx)

>   

> -        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)

> +            repo, shelvectx = _unshelverestorecommit(ui, repo, basename,

> +                                                     oldquiet)

> +            _checkunshelveuntrackedproblems(ui, repo, shelvectx)

> +            branchtorestore = ''

> +            if shelvectx.branch() != shelvectx.p1().branch():

> +                branchtorestore = shelvectx.branch()

>   

> -        shelvedstate.clear(repo)

> -        _finishunshelve(repo, oldtiprev, tr)

> -        unshelvecleanup(ui, repo, basename, opts)

> +            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)

> +

> +            shelvedstate.clear(repo)

> +            _finishunshelve(repo, oldtiprev, tr)

> +            unshelvecleanup(ui, repo, basename, opts)

>       finally:

>           ui.quiet = oldquiet

> @@ -891,5 +891,4 @@ def _dounshelve(ui, repo, *shelved, **op

>               tr.release()

>           lockmod.release(lock)

> -        ui.restoreconfig(forcemerge)

>   

>   @command('shelve',

> _______________________________________________

> Mercurial-devel mailing list

> Mercurial-devel@mercurial-scm.org

> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -315,15 +315,14 @@  def getcommitfunc(extra, interactive, ed
         if hasmq:
             saved, repo.mq.checkapplied = repo.mq.checkapplied, False
-        backup = repo.ui.backupconfig('phases', 'new-commit')
+        override = {('phases', 'new-commit'): phases.secret}
         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)
+            with repo.ui.configoverride(override):
+                return repo.commit(message, shelveuser, opts.get('date'),
+                                   match, editor=editor_, extra=extra)
         finally:
-            repo.ui.restoreconfig(backup)
             if hasmq:
                 repo.mq.checkapplied = saved
@@ -851,7 +850,5 @@  def _dounshelve(ui, repo, *shelved, **op
     oldquiet = ui.quiet
     lock = tr = None
-    forcemerge = ui.backupconfig('ui', 'forcemerge')
     try:
-        ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'unshelve')
         lock = repo.lock()
 
@@ -867,23 +864,26 @@  def _dounshelve(ui, repo, *shelved, **op
         # to the original pctx.
 
-        tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,
-                                                         tmpwctx)
-
-        repo, shelvectx = _unshelverestorecommit(ui, repo, basename, oldquiet)
-        _checkunshelveuntrackedproblems(ui, repo, shelvectx)
-        branchtorestore = ''
-        if shelvectx.branch() != shelvectx.p1().branch():
-            branchtorestore = shelvectx.branch()
+        override = {('ui', 'forcemerge'): opts.get('tool', '')}
+        with ui.configoverride(override, 'unshelve'):
+            tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,
+                                                             tmpwctx)
 
-        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)
+            repo, shelvectx = _unshelverestorecommit(ui, repo, basename,
+                                                     oldquiet)
+            _checkunshelveuntrackedproblems(ui, repo, shelvectx)
+            branchtorestore = ''
+            if shelvectx.branch() != shelvectx.p1().branch():
+                branchtorestore = shelvectx.branch()
 
-        shelvedstate.clear(repo)
-        _finishunshelve(repo, oldtiprev, tr)
-        unshelvecleanup(ui, repo, basename, opts)
+            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)
+
+            shelvedstate.clear(repo)
+            _finishunshelve(repo, oldtiprev, tr)
+            unshelvecleanup(ui, repo, basename, opts)
     finally:
         ui.quiet = oldquiet
@@ -891,5 +891,4 @@  def _dounshelve(ui, repo, *shelved, **op
             tr.release()
         lockmod.release(lock)
-        ui.restoreconfig(forcemerge)
 
 @command('shelve',