Patchwork hg: add standard Windows paths LOCALAPPDATA and APPDATA to config search path

login
register
mail settings
Submitter James May
Date March 28, 2019, 2:55 a.m.
Message ID <06c0bf445f7fe0ab7d1d.1553741730@LAU7777.corp.draeger.global>
Download mbox | patch
Permalink /patch/39411/
State New
Headers show

Comments

James May - March 28, 2019, 2:55 a.m.
# HG changeset patch
# User James May <james.may@draeger.com>
# Date 1553736615 -39600
#      Thu Mar 28 12:30:15 2019 +1100
# Node ID 06c0bf445f7fe0ab7d1d1a186e37a8ff38d893d5
# Parent  eec20025ada33889233e553c5825aac36b708f6c
hg: add standard Windows paths LOCALAPPDATA and APPDATA to config search path

In the spirit of changeset 354020079723 this adds:
  - %LOCALAPPDATA%\hg\{mecurial.ini, hgrc} and
  - %APPDATA%\hg\{mecurial.ini, hgrc}
to the existing location:
  - %USERPROFILE%\{mecurial.ini, .hgrc}
read for configuration.

%USERPROFILE% is used directly rather than using expanduser('~'), as they are
the same on every version Windows from this century.

For backward compatibility, %USERPROFILE%\mercurial.ini is still first and will
be created by hg config --edit on Windows.

---
This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthaelt vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfaenger dieser E-mail sein, senden Sie bitte diese an den Absender zurueck und loeschen Sie die E-mail aus Ihrem System.
Matt Harbison - March 30, 2019, 12:26 a.m.
On Wed, 27 Mar 2019 22:55:30 -0400, <james.may@draeger.com> wrote:

> # HG changeset patch
> # User James May <james.may@draeger.com>
> # Date 1553736615 -39600
> #      Thu Mar 28 12:30:15 2019 +1100
> # Node ID 06c0bf445f7fe0ab7d1d1a186e37a8ff38d893d5
> # Parent  eec20025ada33889233e553c5825aac36b708f6c
> hg: add standard Windows paths LOCALAPPDATA and APPDATA to config search  
> path

> diff -r eec20025ada3 -r 06c0bf445f7f mercurial/help/config.txt
> --- a/mercurial/help/config.txt Tue Mar 26 17:35:28 2019 +0100
> +++ b/mercurial/help/config.txt Thu Mar 28 12:30:15 2019 +1100
> @@ -67,12 +67,16 @@
>
>    On Windows, the following files are consulted:
>
> -  - ``<repo>/.hg/hgrc`` (per-repository)
> -  - ``%USERPROFILE%\.hgrc`` (per-user)
> -  - ``%USERPROFILE%\Mercurial.ini`` (per-user)
> -  - ``%HOME%\.hgrc`` (per-user)
> -  - ``%HOME%\Mercurial.ini`` (per-user)
> -  - ``HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial`` (per-installation)
> +  - ``<repo>\.hg\hgrc`` (per-repository)
> +  - ``%USERPROFILE%\mercurial.ini`` (per-user)
> +  - ``%USERPROFILE%\.hgrc`` (per-user) - note the leading ``.``
> +  - ``%LOCALAPPDATA%\hg\mercurial.ini`` (per-user and machine)
> +  - ``%LOCALAPPDATA%\hg\hgrc`` (per-user and machine)
> +  - ``%APPDATA%\hg\mercurial.ini`` (per-user)
> +  - ``%APPDATA%\hg\hgrc`` (per-user)
> +  - Either of the below specified in the registry key  
> ``HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial`` (per-installation):
> +    - `mecurial.ini`
> +    - `*.rc`, if a directory
>    - ``<install-dir>\hgrc.d\*.rc`` (per-installation)
>    - ``<install-dir>\Mercurial.ini`` (per-installation)
>    - ``<internal>/default.d/*.rc`` (defaults)
> diff -r eec20025ada3 -r 06c0bf445f7f mercurial/scmwindows.py
> --- a/mercurial/scmwindows.py   Tue Mar 26 17:35:28 2019 +0100
> +++ b/mercurial/scmwindows.py   Thu Mar 28 12:30:15 2019 +1100
> @@ -48,14 +48,13 @@
>
>  def userrcpath():
>      '''return os-specific hgrc search path to the user dir'''
> -    home = os.path.expanduser('~')
> -    path = [os.path.join(home, 'mercurial.ini'),
> -            os.path.join(home, '.hgrc')]
> -    userprofile = encoding.environ.get('USERPROFILE')
> -    if userprofile and userprofile != home:
> -        path.append(os.path.join(userprofile, 'mercurial.ini'))
> -        path.append(os.path.join(userprofile, '.hgrc'))
> -    return path
> +    paths = [os.path.join(encoding.environ.get('USERPROFILE'),         
> 'mercurial.ini'),
> +             os.path.join(encoding.environ.get('USERPROFILE'),         
> '.hgrc')
> +             os.path.join(encoding.environ.get('LOCALAPPDATA'), 'hg',  
> 'mercurial.ini'),
> +             os.path.join(encoding.environ.get('LOCALAPPDATA'), 'hg',  
> 'hgrc'),
> +             os.path.join(encoding.environ.get('APPDATA'),      'hg',  
> 'mercurial.ini'),
> +             os.path.join(encoding.environ.get('APPDATA'),      'hg',  
> 'hgrc')]
> +    return paths

It looks like %HOME% got lost in the shuffle here, and in the  
documentation.  It doesn't matter in cmd.exe, but it does do something  
under MSYS.  Can you restore that please?

Patch

diff -r eec20025ada3 -r 06c0bf445f7f mercurial/help/config.txt
--- a/mercurial/help/config.txt Tue Mar 26 17:35:28 2019 +0100
+++ b/mercurial/help/config.txt Thu Mar 28 12:30:15 2019 +1100
@@ -67,12 +67,16 @@ 

   On Windows, the following files are consulted:

-  - ``<repo>/.hg/hgrc`` (per-repository)
-  - ``%USERPROFILE%\.hgrc`` (per-user)
-  - ``%USERPROFILE%\Mercurial.ini`` (per-user)
-  - ``%HOME%\.hgrc`` (per-user)
-  - ``%HOME%\Mercurial.ini`` (per-user)
-  - ``HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial`` (per-installation)
+  - ``<repo>\.hg\hgrc`` (per-repository)
+  - ``%USERPROFILE%\mercurial.ini`` (per-user)
+  - ``%USERPROFILE%\.hgrc`` (per-user) - note the leading ``.``
+  - ``%LOCALAPPDATA%\hg\mercurial.ini`` (per-user and machine)
+  - ``%LOCALAPPDATA%\hg\hgrc`` (per-user and machine)
+  - ``%APPDATA%\hg\mercurial.ini`` (per-user)
+  - ``%APPDATA%\hg\hgrc`` (per-user)
+  - Either of the below specified in the registry key ``HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial`` (per-installation):
+    - `mecurial.ini`
+    - `*.rc`, if a directory
   - ``<install-dir>\hgrc.d\*.rc`` (per-installation)
   - ``<install-dir>\Mercurial.ini`` (per-installation)
   - ``<internal>/default.d/*.rc`` (defaults)
diff -r eec20025ada3 -r 06c0bf445f7f mercurial/scmwindows.py
--- a/mercurial/scmwindows.py   Tue Mar 26 17:35:28 2019 +0100
+++ b/mercurial/scmwindows.py   Thu Mar 28 12:30:15 2019 +1100
@@ -48,14 +48,13 @@ 

 def userrcpath():
     '''return os-specific hgrc search path to the user dir'''
-    home = os.path.expanduser('~')
-    path = [os.path.join(home, 'mercurial.ini'),
-            os.path.join(home, '.hgrc')]
-    userprofile = encoding.environ.get('USERPROFILE')
-    if userprofile and userprofile != home:
-        path.append(os.path.join(userprofile, 'mercurial.ini'))
-        path.append(os.path.join(userprofile, '.hgrc'))
-    return path
+    paths = [os.path.join(encoding.environ.get('USERPROFILE'),        'mercurial.ini'),
+             os.path.join(encoding.environ.get('USERPROFILE'),        '.hgrc')
+             os.path.join(encoding.environ.get('LOCALAPPDATA'), 'hg', 'mercurial.ini'),
+             os.path.join(encoding.environ.get('LOCALAPPDATA'), 'hg', 'hgrc'),
+             os.path.join(encoding.environ.get('APPDATA'),      'hg', 'mercurial.ini'),
+             os.path.join(encoding.environ.get('APPDATA'),      'hg', 'hgrc')]
+    return paths

 def termsize(ui):
     return win32.termsize()