Patchwork D7807: hgrc: introduce HGRCSKIPREPO to skip reading the hgrc's repository

login
register
mail settings
Submitter phabricator
Date Jan. 7, 2020, 11:05 a.m.
Message ID <differential-rev-PHID-DREV-fdtncge36oglplp3aieh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44170/
State Superseded
Headers show

Comments

phabricator - Jan. 7, 2020, 11:05 a.m.
marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We had a way to change the behavior regarding reading the global and user
  config, but we had nothing regarding the repository hgrc itself.
  
  This option is useful in situation where scripts need to be able to work around
  strange configuration set by the user in his repository. (and were HGPLAIN is
  not enough).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7807

AFFECTED FILES
  mercurial/helptext/environment.txt
  mercurial/helptext/scripting.txt
  mercurial/localrepo.py
  tests/test-hgrc.t

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 8, 2020, 11:54 a.m.
pulkit added a comment.


  > hgrc: introduce HGRCSKIPREPO to skip reading the hgrc's repository
  
  s/ hgrc's repository/repository's hgrc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7807/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7807

To: marmoute, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - Jan. 8, 2020, 4:31 p.m.
durin42 added inline comments.
durin42 added subscribers: krbullock, durin42.

INLINE COMMENTS

> scripting.txt:80
> +
> +    Note that these approaches can have unintended consequences, as the
> +    repository config files might define things like extensions that may

Awkward. Maybe:

Note that not reading the repository's configuration is likely to have unintended consequences, as the repository config files can define things like extensions that are required for access to the repository.

(I don't love that either. Maybe @krbullock has an idea?)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7807/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7807

To: marmoute, #hg-reviewers
Cc: durin42, krbullock, pulkit, mercurial-devel

Patch

diff --git a/tests/test-hgrc.t b/tests/test-hgrc.t
--- a/tests/test-hgrc.t
+++ b/tests/test-hgrc.t
@@ -258,3 +258,16 @@ 
   plain: True
   read config from: $TESTTMP/hgrc
   $TESTTMP/hgrc:17: paths.foo=$TESTTMP/bar
+
+Test we can skip the user configuration
+
+  $ cat >> .hg/hgrc <<EOF
+  > [paths]
+  > elephant = babar
+  > EOF
+  $ hg path
+  elephant = $TESTTMP/babar
+  foo = $TESTTMP/bar
+  $ HGRCSKIPREPO=1 hg path
+  foo = $TESTTMP/bar
+
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -676,6 +676,8 @@ 
     configs are loaded. For example, an extension may wish to pull in
     configs from alternate files or sources.
     """
+    if b'HGRCSKIPREPO' in encoding.environ:
+        return False
     try:
         ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
         return True
diff --git a/mercurial/helptext/scripting.txt b/mercurial/helptext/scripting.txt
--- a/mercurial/helptext/scripting.txt
+++ b/mercurial/helptext/scripting.txt
@@ -74,6 +74,13 @@ 
     like the username and extensions that may be required to interface
     with a repository.
 
+HGRCSKIPREPO
+    When set, the .hg/hgrc from repositories are not read.
+
+    Note that these approaches can have unintended consequences, as the
+    repository config files might define things like extensions that may
+    be required to interface with a repository.
+
 Command-line Flags
 ==================
 
diff --git a/mercurial/helptext/environment.txt b/mercurial/helptext/environment.txt
--- a/mercurial/helptext/environment.txt
+++ b/mercurial/helptext/environment.txt
@@ -49,6 +49,9 @@ 
     - if it's a directory, all files ending with .rc are added
     - otherwise, the file itself will be added
 
+HGRCSKIPREPO
+    When set, the .hg/hgrc from repositories are not read.
+
 HGPLAIN
     When set, this disables any configuration settings that might
     change Mercurial's default output. This includes encoding,