Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates-src > by-pkgid > 41c8e355a9bd3d5f7cc6c68d108cb600 > files > 4

mercurial-4.1.3-1.2.mga6.src.rpm

# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1509884527 -32400
#      Sun Nov 05 21:22:07 2017 +0900
# Branch stable
# Node ID 5e27afeddaee6754de902c5615afded32c6d87a3
# Parent  071cbeba421217d722a69a5d614ec934684d62d5
subrepo: add config option to reject any subrepo operations (SEC)

This is an alternative workaround for the issue5730.

Perhaps this is the simplest way of disabling subrepo operations. It does
nothing clever, but just aborts if Mercurial starts accessing to a subrepo.

I think Greg's patch is more useful since it allows us to at least check
out the parent repository. However, that would be confusing if the default
is flipped to checkout=False and subrepos are silently ignored.

I don't like the config name 'allowed', but I couldn't get any better name.

---
 mercurial/help/config.txt |   13 +++++++++++++
 mercurial/subrepo.py      |   19 +++++++++++++------
 tests/test-subrepo-git.t  |   20 ++++++++++++++++++++
 tests/test-subrepo.t      |   20 ++++++++++++++++++++
 4 files changed, 66 insertions(+), 6 deletions(-)

--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1779,6 +1779,19 @@ rewrite rules are then applied on the fu
 doesn't match the full path, an attempt is made to apply it on the
 relative path alone. The rules are applied in definition order.
 
+``subrepos``
+------------
+
+This section contains options that control the behavior of the
+subrepositories feature. See also :hg:`help subrepos`.
+
+``allowed``
+    Whether subrepository operation in the working directory is allowed.
+
+    When disabled, any commands including :hg:`update` will fail if
+    subrepositories are involved.
+    (default: True)
+
 ``templatealias``
 -----------------
 
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -365,6 +365,13 @@ def _auditsubrepopath(repo, path):
     if repo.wvfs.islink(path):
         raise error.Abort(_("subrepo '%s' traverses symbolic link") % path)
 
+def _checktype(ui, kind):
+    if not ui.configbool('subrepos', 'allowed', True):
+        raise error.Abort(_("subrepo not allowed"),
+                          hint=_("see 'hg help config.subrepos' for details"))
+    if kind not in types:
+        raise error.Abort(_('unknown subrepo type %s') % kind)
+
 def subrepo(ctx, path, allowwdir=False, allowcreate=True):
     """return instance of the right subrepo class for subrepo in path"""
     # subrepo inherently violates our import layering rules
@@ -375,10 +382,10 @@ def subrepo(ctx, path, allowwdir=False,
     from . import hg as h
     hg = h
 
-    _auditsubrepopath(ctx.repo(), path)
+    repo = ctx.repo()
+    _auditsubrepopath(repo, path)
     state = ctx.substate[path]
-    if state[2] not in types:
-        raise error.Abort(_('unknown subrepo type %s') % state[2])
+    _checktype(repo.ui, state[2])
     if allowwdir:
         state = (state[0], ctx.subrev(path), state[2])
     return types[state[2]](ctx, path, state[:2], allowcreate)
@@ -393,10 +400,10 @@ def nullsubrepo(ctx, path, pctx):
     from . import hg as h
     hg = h
 
-    _auditsubrepopath(ctx.repo(), path)
+    repo = ctx.repo()
+    _auditsubrepopath(repo, path)
     state = ctx.substate[path]
-    if state[2] not in types:
-        raise error.Abort(_('unknown subrepo type %s') % state[2])
+    _checktype(repo.ui, state[2])
     subrev = ''
     if state[2] == 'hg':
         subrev = "0" * 40
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -81,9 +81,29 @@ clone root
   path s
    source   ../gitroot
    revision 126f2a14290cd5ce061fdedc430170e8d39e1c5a
+  $ cd ..
+
+clone with subrepo disabled (update should fail)
+
+  $ hg clone t -U tc2 --config subrepos.allowed=false
+  $ hg update -R tc2 --config subrepos.allowed=false
+  abort: subrepo not allowed
+  (see 'hg help config.subrepos' for details)
+  [255]
+  $ ls tc2
+  a
+
+  $ hg clone t tc3 --config subrepos.allowed=false
+  updating to branch default
+  abort: subrepo not allowed
+  (see 'hg help config.subrepos' for details)
+  [255]
+  $ ls tc3
+  a
 
 update to previous substate
 
+  $ cd tc
   $ hg update 1 -q
   $ cat s/g
   g
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -484,9 +484,29 @@ clone
   path t
    source   t
    revision 20a0db6fbf6c3d2836e6519a642ae929bfc67c0e
+  $ cd ..
+
+clone with subrepo disabled (update should fail)
+
+  $ hg clone t -U tc2 --config subrepos.allowed=false
+  $ hg update -R tc2 --config subrepos.allowed=false
+  abort: subrepo not allowed
+  (see 'hg help config.subrepos' for details)
+  [255]
+  $ ls tc2
+  a
+
+  $ hg clone t tc3 --config subrepos.allowed=false
+  updating to branch default
+  abort: subrepo not allowed
+  (see 'hg help config.subrepos' for details)
+  [255]
+  $ ls tc3
+  a
 
 push
 
+  $ cd tc
   $ echo bah > t/t
   $ hg ci -m11
   committing subrepository t