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

login
register
mail settings
Submitter Jun Wu
Date March 16, 2017, 9:56 p.m.
Message ID <def9b72933ce717a48e3.1489701416@localhost.localdomain>
Download mbox | patch
Permalink /patch/19404/
State Accepted
Headers show

Comments

Jun Wu - March 16, 2017, 9:56 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1489698920 25200
#      Thu Mar 16 14:15:20 2017 -0700
# Node ID def9b72933ce717a48e3cc8fa4934bd3459b9479
# Parent  5c9cda37d7f6b181ab604c8d5a7592b5553f886b
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r def9b72933ce
commit: get rid of ui.backupconfig
via Mercurial-devel - March 17, 2017, 12:19 a.m.
On Thu, Mar 16, 2017 at 2:56 PM, Jun Wu <quark@fb.com> wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1489698920 25200
> #      Thu Mar 16 14:15:20 2017 -0700
> # Node ID def9b72933ce717a48e3cc8fa4934bd3459b9479
> # Parent  5c9cda37d7f6b181ab604c8d5a7592b5553f886b
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r def9b72933ce
> commit: get rid of ui.backupconfig

Queuing this series with some small changes mentioned below. Thanks. I
will not have time to run tests on all commits before I leave for
home, but I'll push anyway, and will update later tonight if tests
fail.

>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1703,23 +1703,19 @@ def _docommit(ui, repo, *pats, **opts):
>      else:
>          def commitfunc(ui, repo, message, match, opts):
> -            backup = ui.backupconfig('phases', 'new-commit')
> +            configoverride = {}

The name confused me for a while because it's the same as the method
on ui, but it's not even a function here. I renamed them throughout
the series to "overrides" (plural and no "config" prefix), which seems
more consistent with the rest of the series and with how we usually
pluralize dict-type variables.

> +            if opts.get('secret'):
> +                configoverride[('phases', 'new-commit')] = 'secret'
> +
>              baseui = repo.baseui
> -            basebackup = baseui.backupconfig('phases', 'new-commit')
> -            try:
> -                if opts.get('secret'):
> -                    ui.setconfig('phases', 'new-commit', 'secret', 'commit')
> -                    # Propagate to subrepos
> -                    baseui.setconfig('phases', 'new-commit', 'secret', 'commit')
> -
> -                editform = cmdutil.mergeeditform(repo[None], 'commit.normal')
> -                editor = cmdutil.getcommiteditor(editform=editform, **opts)
> -                return repo.commit(message, opts.get('user'), opts.get('date'),
> -                                   match,
> -                                   editor=editor,
> -                                   extra=extra)
> -            finally:
> -                ui.restoreconfig(backup)
> -                repo.baseui.restoreconfig(basebackup)
> -
> +            with baseui.configoverride(configoverride, 'commit'):
> +                with ui.configoverride(configoverride, 'commit'):
> +                    editform = cmdutil.mergeeditform(repo[None],
> +                                                     'commit.normal')
> +                    editor = cmdutil.getcommiteditor(editform=editform, **opts)
> +                    return repo.commit(message, opts.get('user'),

I wrapped after the first argument too (yes, I know it was
inconsistent before too).

> +                                       opts.get('date'),
> +                                       match,
> +                                       editor=editor,
> +                                       extra=extra)
>
>          node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Jun Wu - March 17, 2017, 12:22 a.m.
Thanks!

Excerpts from Martin von Zweigbergk's message of 2017-03-16 17:19:15 -0700:
> On Thu, Mar 16, 2017 at 2:56 PM, Jun Wu <quark@fb.com> wrote:
> > # HG changeset patch
> > # User Jun Wu <quark@fb.com>
> > # Date 1489698920 25200
> > #      Thu Mar 16 14:15:20 2017 -0700
> > # Node ID def9b72933ce717a48e3cc8fa4934bd3459b9479
> > # Parent  5c9cda37d7f6b181ab604c8d5a7592b5553f886b
> > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r def9b72933ce
> > commit: get rid of ui.backupconfig
> 
> Queuing this series with some small changes mentioned below. Thanks. I
> will not have time to run tests on all commits before I leave for
> home, but I'll push anyway, and will update later tonight if tests
> fail.
> 
> >
> > diff --git a/mercurial/commands.py b/mercurial/commands.py
> > --- a/mercurial/commands.py
> > +++ b/mercurial/commands.py
> > @@ -1703,23 +1703,19 @@ def _docommit(ui, repo, *pats, **opts):
> >      else:
> >          def commitfunc(ui, repo, message, match, opts):
> > -            backup = ui.backupconfig('phases', 'new-commit')
> > +            configoverride = {}
> 
> The name confused me for a while because it's the same as the method
> on ui, but it's not even a function here. I renamed them throughout
> the series to "overrides" (plural and no "config" prefix), which seems
> more consistent with the rest of the series and with how we usually
> pluralize dict-type variables.
> 
> > +            if opts.get('secret'):
> > +                configoverride[('phases', 'new-commit')] = 'secret'
> > +
> >              baseui = repo.baseui
> > -            basebackup = baseui.backupconfig('phases', 'new-commit')
> > -            try:
> > -                if opts.get('secret'):
> > -                    ui.setconfig('phases', 'new-commit', 'secret', 'commit')
> > -                    # Propagate to subrepos
> > -                    baseui.setconfig('phases', 'new-commit', 'secret', 'commit')
> > -
> > -                editform = cmdutil.mergeeditform(repo[None], 'commit.normal')
> > -                editor = cmdutil.getcommiteditor(editform=editform, **opts)
> > -                return repo.commit(message, opts.get('user'), opts.get('date'),
> > -                                   match,
> > -                                   editor=editor,
> > -                                   extra=extra)
> > -            finally:
> > -                ui.restoreconfig(backup)
> > -                repo.baseui.restoreconfig(basebackup)
> > -
> > +            with baseui.configoverride(configoverride, 'commit'):
> > +                with ui.configoverride(configoverride, 'commit'):
> > +                    editform = cmdutil.mergeeditform(repo[None],
> > +                                                     'commit.normal')
> > +                    editor = cmdutil.getcommiteditor(editform=editform, **opts)
> > +                    return repo.commit(message, opts.get('user'),
> 
> I wrapped after the first argument too (yes, I know it was
> inconsistent before too).
> 
> > +                                       opts.get('date'),
> > +                                       match,
> > +                                       editor=editor,
> > +                                       extra=extra)
> >
> >          node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
> > _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel@mercurial-scm.org
> > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1703,23 +1703,19 @@  def _docommit(ui, repo, *pats, **opts):
     else:
         def commitfunc(ui, repo, message, match, opts):
-            backup = ui.backupconfig('phases', 'new-commit')
+            configoverride = {}
+            if opts.get('secret'):
+                configoverride[('phases', 'new-commit')] = 'secret'
+
             baseui = repo.baseui
-            basebackup = baseui.backupconfig('phases', 'new-commit')
-            try:
-                if opts.get('secret'):
-                    ui.setconfig('phases', 'new-commit', 'secret', 'commit')
-                    # Propagate to subrepos
-                    baseui.setconfig('phases', 'new-commit', 'secret', 'commit')
-
-                editform = cmdutil.mergeeditform(repo[None], 'commit.normal')
-                editor = cmdutil.getcommiteditor(editform=editform, **opts)
-                return repo.commit(message, opts.get('user'), opts.get('date'),
-                                   match,
-                                   editor=editor,
-                                   extra=extra)
-            finally:
-                ui.restoreconfig(backup)
-                repo.baseui.restoreconfig(basebackup)
-
+            with baseui.configoverride(configoverride, 'commit'):
+                with ui.configoverride(configoverride, 'commit'):
+                    editform = cmdutil.mergeeditform(repo[None],
+                                                     'commit.normal')
+                    editor = cmdutil.getcommiteditor(editform=editform, **opts)
+                    return repo.commit(message, opts.get('user'),
+                                       opts.get('date'),
+                                       match,
+                                       editor=editor,
+                                       extra=extra)
 
         node = cmdutil.commit(ui, repo, commitfunc, pats, opts)