Patchwork D8656: localrepo: load the share source .hg/hgrc also in share-safe mode

login
register
mail settings
Submitter phabricator
Date June 24, 2020, 2:31 p.m.
Message ID <differential-rev-PHID-DREV-mjybaai7pf2wzdwmq62r-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46557/
State New
Headers show

Comments

phabricator - June 24, 2020, 2:31 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If the repo has 'exp-sharesafe' requirement, this means we are sharing
  requirements of the source repository.
  
  The second part of the Share Safe Plan is to share source repo config also.
  
  This patch adds logic to load the source repo .hg/hgrc if we are in share safe
  mode.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/localrepo.py
  tests/test-share-safe.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -66,4 +66,23 @@ 
   $ echo c > c
   $ hg ci -Aqm "added c"
 
+Check that config of the source repository is also loaded
+
+  $ hg showconfig ui.curses
+  [1]
+
+  $ echo "[ui]" >> ../source/.hg/hgrc
+  $ echo "curses=true" >> ../source/.hg/hgrc
+
+  $ hg showconfig ui.curses
+  true
+
+However, local .hg/hgrc should override the config set by share source
+
+  $ echo "[ui]" >> .hg/hgrc
+  $ echo "curses=false" >> .hg/hgrc
+
+  $ hg showconfig ui.curses
+  false
+
   $ hg unshare
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -568,7 +568,7 @@ 
     # The .hg/hgrc file may load extensions or contain config options
     # that influence repository construction. Attempt to load it and
     # process any new extensions that it may have pulled in.
-    if loadhgrc(ui, wdirvfs, hgvfs, requirements):
+    if loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs):
         afterhgrcload(ui, wdirvfs, hgvfs, requirements)
         extensions.loadall(ui)
         extensions.populateui(ui)
@@ -697,7 +697,7 @@ 
     )
 
 
-def loadhgrc(ui, wdirvfs, hgvfs, requirements):
+def loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs=None):
     """Load hgrc files/content into a ui instance.
 
     This is called during repository opening to load any additional
@@ -708,9 +708,20 @@ 
     Extensions should monkeypatch this function to modify how per-repo
     configs are loaded. For example, an extension may wish to pull in
     configs from alternate files or sources.
+
+    sharedvfs is vfs object pointing to source repo if the current one is a
+    shared one
     """
     if not rcutil.use_repo_hgrc():
         return False
+
+    # first load config from shared source if we has to
+    if SHARESAFE_REQUIREMENT in requirements and sharedvfs:
+        try:
+            ui.readconfig(sharedvfs.join(b'hgrc'), root=sharedvfs.base)
+        except IOError:
+            pass
+
     try:
         ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
         return True