Patchwork config: allow 'user' in .hgrc ui section (issue3169)

login
register
mail settings
Submitter anatoly techtonik
Date July 26, 2014, 6:27 a.m.
Message ID <7c1a32d12c36165253c4.1406356076@BlackBox>
Download mbox | patch
Permalink /patch/5203/
State Superseded
Commit 6dfb78f18bdba03067c7060cbe5b4ca2e757dde9
Headers show

Comments

anatoly techtonik - July 26, 2014, 6:27 a.m.
# HG changeset patch
# User anatoly techtonik <techtonik@gmail.com>
# Date 1406356031 -10800
#      Sat Jul 26 09:27:11 2014 +0300
# Node ID 7c1a32d12c36165253c48f947ef7ccf0fe090e7b
# Parent  7142e04b438eab39685e63085503b8af0e42b31e
config: allow 'user' in .hgrc ui section (issue3169)
Augie Fackler - July 26, 2014, 2:36 p.m.
On Jul 26, 2014, at 2:27 AM, anatoly techtonik <techtonik@gmail.com> wrote:

> # HG changeset patch
> # User anatoly techtonik <techtonik@gmail.com>
> # Date 1406356031 -10800
> #      Sat Jul 26 09:27:11 2014 +0300
> # Node ID 7c1a32d12c36165253c48f947ef7ccf0fe090e7b
> # Parent  7142e04b438eab39685e63085503b8af0e42b31e
> config: allow 'user' in .hgrc ui section (issue3169)
> 
> diff -r 7142e04b438e -r 7c1a32d12c36 mercurial/ui.py
> --- a/mercurial/ui.py	Fri Jul 18 19:46:56 2014 -0400
> +++ b/mercurial/ui.py	Sat Jul 26 09:27:11 2014 +0300
> @@ -438,6 +438,8 @@
>         user = os.environ.get("HGUSER")
>         if user is None:
>             user = self.config("ui", "username")
> +            if user is None:
> +                user = self.config("ui", "user")

You could actually do

self.config('ui', ['username', 'user'])

instead. See:

http://selenic.com/hg/file/868e2cea3ea0/mercurial/ui.py#l174

(I have no feelings one way or the other on accepting this patch - I'll leave that to others, but it might be nice to use the alternates support built into ui.ui.config.)

>             if user is not None:
>                 user = os.path.expandvars(user)
>         if user is None:
> diff -r 7142e04b438e -r 7c1a32d12c36 tests/test-committer.t
> --- a/tests/test-committer.t	Fri Jul 18 19:46:56 2014 -0400
> +++ b/tests/test-committer.t	Sat Jul 26 09:27:11 2014 +0300
> @@ -63,4 +63,17 @@
>   abort: empty username!
>   [255]
> 
> +  $ echo 1234 > asdf
> +  $ echo "[ui]" > .hg/hgrc
> +  $ echo "user = Foo Bar II <foo2@bar.com>" >> .hg/hgrc
> +  $ hg commit -m commit-1
> +  $ hg tip
> +  changeset:   5:83fd986938c3
> +  tag:         tip
> +  user:        Foo Bar II <foo2@bar.com>
> +  date:        Thu Jan 01 00:00:00 1970 +0000
> +  summary:     commit-1
> +  
> +  $ rm .hg/hgrc
> +
>   $ cd ..
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r 7142e04b438e -r 7c1a32d12c36 mercurial/ui.py
--- a/mercurial/ui.py	Fri Jul 18 19:46:56 2014 -0400
+++ b/mercurial/ui.py	Sat Jul 26 09:27:11 2014 +0300
@@ -438,6 +438,8 @@ 
         user = os.environ.get("HGUSER")
         if user is None:
             user = self.config("ui", "username")
+            if user is None:
+                user = self.config("ui", "user")
             if user is not None:
                 user = os.path.expandvars(user)
         if user is None:
diff -r 7142e04b438e -r 7c1a32d12c36 tests/test-committer.t
--- a/tests/test-committer.t	Fri Jul 18 19:46:56 2014 -0400
+++ b/tests/test-committer.t	Sat Jul 26 09:27:11 2014 +0300
@@ -63,4 +63,17 @@ 
   abort: empty username!
   [255]
 
+  $ echo 1234 > asdf
+  $ echo "[ui]" > .hg/hgrc
+  $ echo "user = Foo Bar II <foo2@bar.com>" >> .hg/hgrc
+  $ hg commit -m commit-1
+  $ hg tip
+  changeset:   5:83fd986938c3
+  tag:         tip
+  user:        Foo Bar II <foo2@bar.com>
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     commit-1
+  
+  $ rm .hg/hgrc
+
   $ cd ..