Patchwork record: --user/-u now works with record when ui.username not set (issue3857)

login
register
mail settings
Submitter Prasoon Shukla
Date Dec. 10, 2013, 8:47 a.m.
Message ID <662044cd452faa1e39a6.1386665277@jimmypage>
Download mbox | patch
Permalink /patch/3209/
State Superseded
Commit a765611e06dc8e0ce9be4f25ee8e18d72f1b9580
Headers show

Comments

Prasoon Shukla - Dec. 10, 2013, 8:47 a.m.
# HG changeset patch
# User Prasoon Shukla <prasoon92.iitr@gmail.com>
# Date 1386665165 -19800
#      Tue Dec 10 14:16:05 2013 +0530
# Node ID 662044cd452faa1e39a633a3fbf7daa5b07a1830
# Parent  1c92524c37cdd251c1a36b2da0fb4148b0e6ba09
record: --user/-u now works with record when ui.username not set (issue3857)

The -u flag didn't work when ui.username was not set and resulted in an
abort message. This was fixed.
Pierre-Yves David - Dec. 10, 2013, 9:28 a.m.
On 12/10/2013 12:47 AM, Prasoon Shukla wrote:
> # HG changeset patch
> # User Prasoon Shukla <prasoon92.iitr@gmail.com>
> # Date 1386665165 -19800
> #      Tue Dec 10 14:16:05 2013 +0530
> # Node ID 662044cd452faa1e39a633a3fbf7daa5b07a1830
> # Parent  1c92524c37cdd251c1a36b2da0fb4148b0e6ba09
> record: --user/-u now works with record when ui.username not set (issue3857)
>
> The -u flag didn't work when ui.username was not set and resulted in an
> abort message. This was fixed.
>
> diff -r 1c92524c37cd -r 662044cd452f hgext/record.py
> --- a/hgext/record.py	Sun Dec 01 21:24:48 2013 -0600
> +++ b/hgext/record.py	Tue Dec 10 14:16:05 2013 +0530
> @@ -502,7 +502,14 @@
>                            cmdsuggest)
>   
>       # make sure username is set before going interactive
> -    ui.username()
> +    try:
> +        ui.username()
> +    except:
> +        # username not set so we check whether --user was provided
> +        if opts.has_key('user'):
> +            ui.setconfig('ui', 'username', opts['user'])
> +        # check again, abort if username not set
> +        ui.username()

I believe it is not necessary to overwrite the value in ui to have this 
working

It is even a bad idea to overwrite le configuration.

(note: you should check the `get` method of dictionary)

>       def recordfunc(ui, repo, message, match, opts):
>           """This is generic record driver.
> diff -r 1c92524c37cd -r 662044cd452f tests/test-record.t
> --- a/tests/test-record.t	Sun Dec 01 21:24:48 2013 -0600
> +++ b/tests/test-record.t	Tue Dec 10 14:16:05 2013 +0530
> @@ -1277,5 +1277,20 @@
>      c
>     +d
>     
> +Test -u flag when ui.username not set
> +  $ echo e >> subdir/f1
> +  $ hg record --config ui.username= -d '8 0' -m "user flag" <<EOF
> +  > y
> +  > y
> +  > EOF
> +  diff --git a/subdir/f1 b/subdir/f1
> +  1 hunks, 1 lines changed
> +  examine changes to 'subdir/f1'? [Ynesfdaq?]
> +  @@ -4,3 +4,4 @@
> +   b
> +   c
> +   d
> +  +e
> +  record this change to 'subdir/f1'? [Ynesfdaq?]
>   
>     $ cd ..

How come I do not see any --user in your test ?
(note we usually prefer long version of argument in test for readability 
purpose)
Prasoon Shukla - Dec. 10, 2013, 11:29 a.m.
Hmm. Very well then. So I suppose the other option is to set the
HGUSER environment variable. I'll modify the test too.
Also, should I create a new thread (as unlikely as that seems to me)
or just reply on this thread with the patch? I've used Github pull
requests before but never really discussed patches on email, so please
forgive any noob mistakes.

Patch

diff -r 1c92524c37cd -r 662044cd452f hgext/record.py
--- a/hgext/record.py	Sun Dec 01 21:24:48 2013 -0600
+++ b/hgext/record.py	Tue Dec 10 14:16:05 2013 +0530
@@ -502,7 +502,14 @@ 
                          cmdsuggest)
 
     # make sure username is set before going interactive
-    ui.username()
+    try:
+        ui.username()
+    except:
+        # username not set so we check whether --user was provided
+        if opts.has_key('user'):
+            ui.setconfig('ui', 'username', opts['user'])
+        # check again, abort if username not set
+        ui.username()
 
     def recordfunc(ui, repo, message, match, opts):
         """This is generic record driver.
diff -r 1c92524c37cd -r 662044cd452f tests/test-record.t
--- a/tests/test-record.t	Sun Dec 01 21:24:48 2013 -0600
+++ b/tests/test-record.t	Tue Dec 10 14:16:05 2013 +0530
@@ -1277,5 +1277,20 @@ 
    c
   +d
   
+Test -u flag when ui.username not set
+  $ echo e >> subdir/f1
+  $ hg record --config ui.username= -d '8 0' -m "user flag" <<EOF
+  > y
+  > y
+  > EOF
+  diff --git a/subdir/f1 b/subdir/f1
+  1 hunks, 1 lines changed
+  examine changes to 'subdir/f1'? [Ynesfdaq?] 
+  @@ -4,3 +4,4 @@
+   b
+   c
+   d
+  +e
+  record this change to 'subdir/f1'? [Ynesfdaq?] 
 
   $ cd ..