Patchwork D9047: dispatch: load shared source repository config in share-safe mode

login
register
mail settings
Submitter phabricator
Date Sept. 18, 2020, 2:41 p.m.
Message ID <differential-rev-PHID-DREV-yhflbyh4tleusoq3pjpg-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47222/
State Superseded
Headers show

Comments

phabricator - Sept. 18, 2020, 2:41 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It seems to me now that there are two steps when config is loaded:
  
  1. on dispatch
  2. repository object creation
  
  Recent patches added functionality that there can be shares in share-safe mode
  where config of the source repository is shared with the the shares. However we
  missed adding logic to read the source config on dispatch. This leads to
  extensions not being loaded on dispatch and hence extensions command not being
  recognized.
  
  This patch fixes it by reading the shared source config on dispatch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dispatch.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
@@ -102,21 +102,14 @@ 
   share
   $ hg extdiff -R ../source -p echo
 
-BROKEN: the command below does not work but debugextensions says that extension
+BROKEN: the command below will not work if config of shared source is not loaded
+on dispatch but debugextensions says that extension
 is loaded
   $ hg debugextensions
   extdiff
   share
 
-BROKEN: extdiff command should work here
   $ hg extdiff -p echo
-  hg: unknown command 'extdiff'
-  'extdiff' is provided by the following extension:
-  
-      extdiff       command to allow external programs to compare revisions
-  
-  (use 'hg help extensions' for information on enabling extensions)
-  [255]
 
 However, local .hg/hgrc should override the config set by share source
 
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -36,13 +36,16 @@ 
     help,
     hg,
     hook,
+    localrepo,
     profiling,
     pycompat,
     rcutil,
     registrar,
+    requirements as requirementsmod,
     scmutil,
     ui as uimod,
     util,
+    vfs,
 )
 
 from .utils import (
@@ -941,6 +944,29 @@ 
     return ret
 
 
+def _readsharedsourceconfig(ui, path):
+    """if the current repository is shared one, this tries to read
+    .hg/hgrc of shared source if we are in share-safe mode
+
+    Config read is loaded into the ui object passed
+
+    This should be called before reading .hg/hgrc or the main repo
+    as that overrides config set in shared source"""
+    try:
+        with open(os.path.join(path, b".hg", b"requires"), "rb") as fp:
+            requirements = set(fp.read().splitlines())
+            if not (
+                requirementsmod.SHARESAFE_REQUIREMENT in requirements
+                and requirementsmod.SHARED_REQUIREMENT in requirements
+            ):
+                return
+            hgvfs = vfs.vfs(os.path.join(path, b".hg"))
+            sharedvfs = localrepo._getsharedvfs(hgvfs, requirements)
+            ui.readconfig(sharedvfs.join(b"hgrc"), path)
+    except IOError:
+        pass
+
+
 def _getlocal(ui, rpath, wd=None):
     """Return (path, local ui object) for the given target path.
 
@@ -961,12 +987,14 @@ 
     else:
         lui = ui.copy()
         if rcutil.use_repo_hgrc():
+            _readsharedsourceconfig(lui, path)
             lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path)
 
     if rpath:
         path = lui.expandpath(rpath)
         lui = ui.copy()
         if rcutil.use_repo_hgrc():
+            _readsharedsourceconfig(lui, path)
             lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path)
 
     return path, lui