Patchwork [V3] record: make hg record always use the non curses interface

login
register
mail settings
Submitter Laurent Charignon
Date May 14, 2015, 3:36 a.m.
Message ID <a245678708a810f8fdbb.1431574579@lcharignon-mbp.local>
Download mbox | patch
Permalink /patch/9066/
State Superseded
Commit 29be0450b667ddd66a7d1356793f1f40c19fdf33
Headers show

Comments

Laurent Charignon - May 14, 2015, 3:36 a.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1431574212 25200
#      Wed May 13 20:30:12 2015 -0700
# Node ID a245678708a810f8fdbbc35ce4fe0a672ea8cfb0
# Parent  7c324f65e4efb3310f7664df3da94363bef76765
record: make hg record always use the non curses interface

Before this patch, hg record was running hg commit -i, therefore with the
experimental.crecord=True flag, hg record was actually launching the curses
record interface. Some of our users could be confused by that.
This patch makes the hg record command set this flag to False, ensuring that
hg record never shows the curses interface.
commit -i, shelve -i and revert -i remain unchanged and use the curses
interface if the experimental.crecord flag is set.
Pierre-Yves David - May 14, 2015, 5:25 a.m.
On 05/13/2015 08:36 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1431574212 25200
> #      Wed May 13 20:30:12 2015 -0700
> # Node ID a245678708a810f8fdbbc35ce4fe0a672ea8cfb0
> # Parent  7c324f65e4efb3310f7664df3da94363bef76765
> record: make hg record always use the non curses interface
>
> Before this patch, hg record was running hg commit -i, therefore with the
> experimental.crecord=True flag, hg record was actually launching the curses
> record interface. Some of our users could be confused by that.
> This patch makes the hg record command set this flag to False, ensuring that
> hg record never shows the curses interface.
> commit -i, shelve -i and revert -i remain unchanged and use the curses
> interface if the experimental.crecord flag is set.
>
> diff --git a/hgext/record.py b/hgext/record.py
> --- a/hgext/record.py
> +++ b/hgext/record.py
> @@ -50,7 +50,12 @@
>       This command is not available when committing a merge.'''
>
>       opts["interactive"] = True
> -    commands.commit(ui, repo, *pats, **opts)
> +    try:
> +        backup = ui.backupconfig('experimental', 'crecord')
> +        ui.setconfig('experimental', 'crecord', False, 'record')
> +        commands.commit(ui, repo, *pats, **opts)
> +    finally:
> +        ui.restoreconfig(backup)

wrong pattern usage here:

backup config have no side effect and can be safely called outside of 
the try. However with your current code, if backupconfig were to fail, 
the "backup" variable would not exist and the finally would crash. 
shadowing the original error.

You should use:

   backup
   try:
     set
     use
   finally:
     restore

Patch

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -50,7 +50,12 @@ 
     This command is not available when committing a merge.'''
 
     opts["interactive"] = True
-    commands.commit(ui, repo, *pats, **opts)
+    try:
+        backup = ui.backupconfig('experimental', 'crecord')
+        ui.setconfig('experimental', 'crecord', False, 'record')
+        commands.commit(ui, repo, *pats, **opts)
+    finally:
+        ui.restoreconfig(backup)
 
 def qrefresh(origfn, ui, repo, *pats, **opts):
     if not opts['interactive']:
@@ -66,8 +71,13 @@ 
         mq.refresh(ui, repo, **opts)
 
     # backup all changed files
-    cmdutil.dorecord(ui, repo, committomq, 'qrefresh', True,
+    try:
+        backup = ui.backupconfig('experimental', 'crecord')
+        ui.setconfig('experimental', 'crecord', False, 'record')
+        cmdutil.dorecord(ui, repo, committomq, 'qrefresh', True,
                     cmdutil.recordfilter, *pats, **opts)
+    finally:
+        ui.restoreconfig(backup)
 
 # This command registration is replaced during uisetup().
 @command('qrecord',
@@ -92,8 +102,13 @@ 
         opts['checkname'] = False
         mq.new(ui, repo, patch, *pats, **opts)
 
-    cmdutil.dorecord(ui, repo, committomq, 'qnew', False,
+    try:
+        backup = ui.backupconfig('experimental', 'crecord')
+        ui.setconfig('experimental', 'crecord', False, 'record')
+        cmdutil.dorecord(ui, repo, committomq, 'qnew', False,
                     cmdutil.recordfilter, *pats, **opts)
+    finally:
+        ui.restoreconfig(backup)
 
 def qnew(origfn, ui, repo, patch, *args, **opts):
     if opts['interactive']: