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

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

Comments

Jun Wu - March 16, 2017, 9:57 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1489700358 25200
#      Thu Mar 16 14:39:18 2017 -0700
# Node ID 8b086a28d1b605d6c0726d77c21f8d13188691fa
# Parent  93772a7ad2c443b7c92d0d23e85405f5b0d1a800
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 8b086a28d1b6
mq: get rid of ui.backupconfig
Yuya Nishihara - March 18, 2017, 2:34 a.m.
On Thu, 16 Mar 2017 14:57:01 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1489700358 25200
> #      Thu Mar 16 14:39:18 2017 -0700
> # Node ID 8b086a28d1b605d6c0726d77c21f8d13188691fa
> # Parent  93772a7ad2c443b7c92d0d23e85405f5b0d1a800
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 8b086a28d1b6
> mq: get rid of ui.backupconfig
> 
> diff --git a/hgext/mq.py b/hgext/mq.py
> --- a/hgext/mq.py
> +++ b/hgext/mq.py
> @@ -406,16 +406,10 @@ def newcommit(repo, phase, *args, **kwar
>          if repo.ui.configbool('mq', 'secret', False):
>              phase = phases.secret
> +    override = {('ui', 'allowemptycommit'): True}
>      if phase is not None:
> -        phasebackup = repo.ui.backupconfig('phases', 'new-commit')
> -    allowemptybackup = repo.ui.backupconfig('ui', 'allowemptycommit')
> -    try:
> -        if phase is not None:
> -            repo.ui.setconfig('phases', 'new-commit', phase, 'mq')
> +        override[('phases', 'new-commit')] = phase
> +    with repo.ui.configoverride(override, 'mq'):
>          repo.ui.setconfig('ui', 'allowemptycommit', True)

This setconfig() would be no longer needed.
Jun Wu - March 18, 2017, 2:53 a.m.
Excerpts from Yuya Nishihara's message of 2017-03-18 11:34:21 +0900:
> On Thu, 16 Mar 2017 14:57:01 -0700, Jun Wu wrote:
> > # HG changeset patch
> > # User Jun Wu <quark@fb.com>
> > # Date 1489700358 25200
> > #      Thu Mar 16 14:39:18 2017 -0700
> > # Node ID 8b086a28d1b605d6c0726d77c21f8d13188691fa
> > # Parent  93772a7ad2c443b7c92d0d23e85405f5b0d1a800
> > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r 8b086a28d1b6
> > mq: get rid of ui.backupconfig
> > 
> > diff --git a/hgext/mq.py b/hgext/mq.py
> > --- a/hgext/mq.py
> > +++ b/hgext/mq.py
> > @@ -406,16 +406,10 @@ def newcommit(repo, phase, *args, **kwar
> >          if repo.ui.configbool('mq', 'secret', False):
> >              phase = phases.secret
> > +    override = {('ui', 'allowemptycommit'): True}
> >      if phase is not None:
> > -        phasebackup = repo.ui.backupconfig('phases', 'new-commit')
> > -    allowemptybackup = repo.ui.backupconfig('ui', 'allowemptycommit')
> > -    try:
> > -        if phase is not None:
> > -            repo.ui.setconfig('phases', 'new-commit', phase, 'mq')
> > +        override[('phases', 'new-commit')] = phase
> > +    with repo.ui.configoverride(override, 'mq'):
> >          repo.ui.setconfig('ui', 'allowemptycommit', True)
> 
> This setconfig() would be no longer needed.

My fault. I'll scan all "setconfig" usage and do a clean-up. If we have
immutable configs, it's also better to avoid "setconfig"s.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -406,16 +406,10 @@  def newcommit(repo, phase, *args, **kwar
         if repo.ui.configbool('mq', 'secret', False):
             phase = phases.secret
+    override = {('ui', 'allowemptycommit'): True}
     if phase is not None:
-        phasebackup = repo.ui.backupconfig('phases', 'new-commit')
-    allowemptybackup = repo.ui.backupconfig('ui', 'allowemptycommit')
-    try:
-        if phase is not None:
-            repo.ui.setconfig('phases', 'new-commit', phase, 'mq')
+        override[('phases', 'new-commit')] = phase
+    with repo.ui.configoverride(override, 'mq'):
         repo.ui.setconfig('ui', 'allowemptycommit', True)
         return repo.commit(*args, **kwargs)
-    finally:
-        repo.ui.restoreconfig(allowemptybackup)
-        if phase is not None:
-            repo.ui.restoreconfig(phasebackup)
 
 class AbortNoCleanup(error.Abort):