Patchwork [3,of,4] config: add a .hg/hgrc-not-shared which won't be shared in share-safe mode

login
register
mail settings
Submitter Pulkit Goyal
Date Oct. 16, 2020, 7:56 a.m.
Message ID <aea9b1e5192225f9d887.1602834993@workspace>
Download mbox | patch
Permalink /patch/47485/
State New
Headers show

Comments

Pulkit Goyal - Oct. 16, 2020, 7:56 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1593596699 -19800
#      Wed Jul 01 15:14:59 2020 +0530
# Node ID aea9b1e5192225f9d88773b3c3039dd307b3ad89
# Parent  03bb891ad7fffc564b5af73f8887c41f4eb0a7f3
# EXP-Topic share-safe
config: add a .hg/hgrc-not-shared which won't be shared in share-safe mode

Previous patches add a safe mode for sharing repositories which involve sharing
of source requirements and config files.

In certain situations we might need to add a config to source repository which
we does not want to share. For this, we add a `.hg/hgrc-not-shared` which won't
be shared.

This also adds a `--non-shared` flag to `hg config` command to see the
non-shared config.

Differential Revision: https://phab.mercurial-scm.org/D8673
Yuya Nishihara - Oct. 16, 2020, 10:56 a.m.
On Fri, 16 Oct 2020 13:26:33 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1593596699 -19800
> #      Wed Jul 01 15:14:59 2020 +0530
> # Node ID aea9b1e5192225f9d88773b3c3039dd307b3ad89
> # Parent  03bb891ad7fffc564b5af73f8887c41f4eb0a7f3
> # EXP-Topic share-safe
> config: add a .hg/hgrc-not-shared which won't be shared in share-safe mode
> 
> Previous patches add a safe mode for sharing repositories which involve sharing
> of source requirements and config files.
> 
> In certain situations we might need to add a config to source repository which
> we does not want to share. For this, we add a `.hg/hgrc-not-shared` which won't
> be shared.

Can you elaborate the "certain situations" more?

I feel it would be tedious job to sort out shared/unshared configs manually.
Pulkit Goyal - Oct. 16, 2020, 12:42 p.m.
On Fri, Oct 16, 2020 at 4:27 PM Yuya Nishihara <yuya@tcha.org> wrote:
>
> On Fri, 16 Oct 2020 13:26:33 +0530, Pulkit Goyal wrote:
> > # HG changeset patch
> > # User Pulkit Goyal <7895pulkit@gmail.com>
> > # Date 1593596699 -19800
> > #      Wed Jul 01 15:14:59 2020 +0530
> > # Node ID aea9b1e5192225f9d88773b3c3039dd307b3ad89
> > # Parent  03bb891ad7fffc564b5af73f8887c41f4eb0a7f3
> > # EXP-Topic share-safe
> > config: add a .hg/hgrc-not-shared which won't be shared in share-safe mode
> >
> > Previous patches add a safe mode for sharing repositories which involve sharing
> > of source requirements and config files.
> >
> > In certain situations we might need to add a config to source repository which
> > we does not want to share. For this, we add a `.hg/hgrc-not-shared` which won't
> > be shared.
>
> Can you elaborate the "certain situations" more?

Things like usernames, paths, wdir specific extension like sparse.
>
> I feel it would be tedious job to sort out shared/unshared configs manually.

With this series and previous series which got pushed, the workflow is
something like follows now:

* Check if exp-sharesafe requirement is there, if no, we do things old way.
* If yes, first read current repo `.hg/requires` and check whether
it's a shared repo. If it's not, go back old way.
* If it's shared repo, read `.hg/hgrc` of share-source and then
current repository config.

For unshared configs, we introduce this `hgrc-not-shared` which won't be shared.
Yuya Nishihara - Oct. 16, 2020, 1:16 p.m.
On Fri, 16 Oct 2020 18:12:06 +0530, Pulkit Goyal wrote:
> On Fri, Oct 16, 2020 at 4:27 PM Yuya Nishihara <yuya@tcha.org> wrote:
> > On Fri, 16 Oct 2020 13:26:33 +0530, Pulkit Goyal wrote:
> > > # HG changeset patch
> > > # User Pulkit Goyal <7895pulkit@gmail.com>
> > > # Date 1593596699 -19800
> > > #      Wed Jul 01 15:14:59 2020 +0530
> > > # Node ID aea9b1e5192225f9d88773b3c3039dd307b3ad89
> > > # Parent  03bb891ad7fffc564b5af73f8887c41f4eb0a7f3
> > > # EXP-Topic share-safe
> > > config: add a .hg/hgrc-not-shared which won't be shared in share-safe mode
> > >
> > > Previous patches add a safe mode for sharing repositories which involve sharing
> > > of source requirements and config files.
> > >
> > > In certain situations we might need to add a config to source repository which
> > > we does not want to share. For this, we add a `.hg/hgrc-not-shared` which won't
> > > be shared.
> >
> > Can you elaborate the "certain situations" more?
> 
> Things like usernames, paths, wdir specific extension like sparse.

I fell it's fine to share usernames and paths across repositories, which can
be overridden if needed.

For sparse, I don't know the current implementation, but I think it should be
gated by repo requirements. Extension will be loaded, but turned off if
requirements don't match.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2140,6 +2140,7 @@  def _docommit(ui, repo, *pats, **opts):
             None,
             _(b'edit shared source repository config (EXPERIMENTAL)'),
         ),
+        (b'', b'non-shared', None, _(b'edit non shared config (EXPERIMENTAL)')),
         (b'g', b'global', None, _(b'edit global config')),
     ]
     + formatteropts,
@@ -2170,6 +2171,9 @@  def config(ui, repo, *values, **opts):
 
     .. container:: verbose
 
+      --non-shared flag is used to edit `.hg/hgrc-not-shared` config file.
+      This file is not shared across shares when in share-safe mode.
+
       Template:
 
       The following keywords are supported. See also :hg:`help templates`.
@@ -2187,7 +2191,7 @@  def config(ui, repo, *values, **opts):
     """
 
     opts = pycompat.byteskwargs(opts)
-    editopts = (b'edit', b'local', b'global', b'shared')
+    editopts = (b'edit', b'local', b'global', b'shared', b'non_shared')
     if any(opts.get(o) for o in editopts):
         cmdutil.check_at_most_one_arg(opts, *editopts[1:])
         if opts.get(b'local'):
@@ -2209,6 +2213,8 @@  def config(ui, repo, *values, **opts):
                         )
                     )
             paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')]
+        elif opts.get(b'non_shared'):
+            paths = [repo.vfs.join(b'hgrc-not-shared')]
         else:
             paths = rcutil.userrcpath()
 
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -989,6 +989,7 @@  def _getlocal(ui, rpath, wd=None):
         if rcutil.use_repo_hgrc():
             _readsharedsourceconfig(lui, path)
             lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path)
+            lui.readconfig(os.path.join(path, b".hg", b"hgrc-not-shared"), path)
 
     if rpath:
         path = lui.expandpath(rpath)
@@ -996,6 +997,7 @@  def _getlocal(ui, rpath, wd=None):
         if rcutil.use_repo_hgrc():
             _readsharedsourceconfig(lui, path)
             lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path)
+            lui.readconfig(os.path.join(path, b".hg", b"hgrc-not-shared"), path)
 
     return path, lui
 
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -715,18 +715,28 @@  def loadhgrc(ui, wdirvfs, hgvfs, require
     if not rcutil.use_repo_hgrc():
         return False
 
+    ret = False
     # first load config from shared source if we has to
     if requirementsmod.SHARESAFE_REQUIREMENT in requirements and sharedvfs:
         try:
             ui.readconfig(sharedvfs.join(b'hgrc'), root=sharedvfs.base)
+            ret = True
         except IOError:
             pass
 
     try:
         ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
-        return True
+        ret = True
     except IOError:
-        return False
+        pass
+
+    try:
+        ui.readconfig(hgvfs.join(b'hgrc-not-shared'), root=wdirvfs.base)
+        ret = True
+    except IOError:
+        pass
+
+    return ret
 
 
 def afterhgrcload(ui, wdirvfs, hgvfs, requirements):
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -259,7 +259,7 @@  Show all commands + options
   cat: output, rev, decode, include, exclude, template
   clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure
   commit: addremove, close-branch, amend, secret, edit, force-close-branch, interactive, include, exclude, message, logfile, date, user, subrepos
-  config: untrusted, edit, local, shared, global, template
+  config: untrusted, edit, local, shared, non-shared, global, template
   continue: dry-run
   copy: forget, after, at-rev, force, include, exclude, dry-run
   debugancestor: 
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
@@ -253,6 +253,25 @@  Shared one should work
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     added c
   
+
+Testing that nonsharedrc is loaded for source and not shared
+
+  $ cd ../source
+  $ touch .hg/hgrc-not-shared
+  $ echo "[ui]" >> .hg/hgrc-not-shared
+  $ echo "traceback=true" >> .hg/hgrc-not-shared
+
+  $ hg showconfig ui.traceback
+  true
+
+  $ HGEDITOR=cat hg config --non-shared
+  [ui]
+  traceback=true
+
+  $ cd ../shared1
+  $ hg showconfig ui.traceback
+  [1]
+
 Unsharing works
 
   $ hg unshare