Patchwork [3,of,5,STABLE,V2] subrepo: make "_sanitize()" take absolute path to the root of subrepo

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 8, 2014, 10:31 a.m.
Message ID <ba63db29ee8ed4720361.1399545078@juju>
Download mbox | patch
Permalink /patch/4668/
State Accepted
Commit a01988cd9b614bdad385147e8361f9b8a75d0529
Headers show

Comments

Katsunori FUJIWARA - May 8, 2014, 10:31 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1399543380 -32400
#      Thu May 08 19:03:00 2014 +0900
# Branch stable
# Node ID ba63db29ee8ed472036188f19e1509828c871e22
# Parent  71d41d30008defac379a29ffa857bb39b45c743b
subrepo: make "_sanitize()" take absolute path to the root of subrepo

Before this patch, "hg update" doesn't sanitize ".hg/hgrc" in non-hg
subrepos correctly, if "hg update" is executed not at the root of the
parent repository.

"_sanitize()" takes relative path to subrepo from the root of the
parent repository, and passes it to "os.walk()". In this case,
"os.walk()" expects CWD to be equal to the root of the parent
repository.

So, "os.walk()" can't find specified path (or may scan unexpected
path), if CWD isn't equal to the root of the parent repository.

Non-hg subrepo under nested hg-subrepos may cause same problem, too:
CWD may be equal to the root of the outer most repository, or so.

This patch makes "_sanitize()" take absolute path to the root of
subrepo to sanitize correctly in such cases.

This patch doesn't normalize the path to hostile files as the one
relative to CWD (or the root of the outer most repository), to fix the
problem in the simple way suitable for "stable".

Normalizing should be done in the future: maybe as a part of the
migration to vfs.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1050,7 +1050,7 @@  class svnsubrepo(abstractsubrepo):
         # update to a directory which has since been deleted and recreated.
         args.append('%s@%s' % (state[0], state[1]))
         status, err = self._svncommand(args, failok=True)
-        _sanitize(self._ui, self._path)
+        _sanitize(self._ui, self._ctx._repo.wjoin(self._path))
         if not re.search('Checked out revision [0-9]+.', status):
             if ('is already a working copy for a different URL' in err
                 and (self._wcchanged()[:2] == (False, False))):
@@ -1343,7 +1343,7 @@  class gitsubrepo(abstractsubrepo):
                 self._gitcommand(['reset', 'HEAD'])
                 cmd.append('-f')
             self._gitcommand(cmd + args)
-            _sanitize(self._ui, self._path)
+            _sanitize(self._ui, self._abspath)
 
         def rawcheckout():
             # no branch to checkout, check it out with no branch
@@ -1392,7 +1392,7 @@  class gitsubrepo(abstractsubrepo):
             if tracking[remote] != self._gitcurrentbranch():
                 checkout([tracking[remote]])
             self._gitcommand(['merge', '--ff', remote])
-            _sanitize(self._ui, self._path)
+            _sanitize(self._ui, self._abspath)
         else:
             # a real merge would be required, just checkout the revision
             rawcheckout()
@@ -1428,7 +1428,7 @@  class gitsubrepo(abstractsubrepo):
                 self.get(state) # fast forward merge
             elif base != self._state[1]:
                 self._gitcommand(['merge', '--no-commit', revision])
-            _sanitize(self._ui, self._path)
+            _sanitize(self._ui, self._abspath)
 
         if self.dirty():
             if self._gitstate() != revision:
diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -592,11 +592,11 @@  Test sanitizing ".hg/hgrc" in subrepo
   c4069473b459cf27fd4d7c2f50c4346b4e936599 s
   $ cd ..
 
+  $ hg -R tc pull -q
+  $ hg -R tc update -q -C 3473d20bddcf 2>&1 | sort
+  warning: removing potentially hostile 'hgrc' in '$TESTTMP/tc/s/.hg' (glob)
+  warning: removing potentially hostile 'hgrc' in '$TESTTMP/tc/s/sub/.hg' (glob)
   $ cd tc
-  $ hg pull -q
-  $ hg update -q -C 3473d20bddcf 2>&1 | sort
-  warning: removing potentially hostile 'hgrc' in 's/.hg' (glob)
-  warning: removing potentially hostile 'hgrc' in 's/sub/.hg' (glob)
   $ hg parents -q
   8:3473d20bddcf
   $ grep ' s$' .hgsubstate
@@ -642,10 +642,12 @@  additional test for "git merge --ff" rou
   $ cat s/sub/.hg/hgrc
   cat: s/sub/.hg/hgrc: No such file or directory
   [1]
-  $ hg pull -q
-  $ hg update -q -C ed23f7fe024e 2>&1 | sort
-  warning: removing potentially hostile 'hgrc' in 's/.hg' (glob)
-  warning: removing potentially hostile 'hgrc' in 's/sub/.hg' (glob)
+  $ cd ..
+  $ hg -R tc pull -q
+  $ hg -R tc update -q -C ed23f7fe024e 2>&1 | sort
+  warning: removing potentially hostile 'hgrc' in '$TESTTMP/tc/s/.hg' (glob)
+  warning: removing potentially hostile 'hgrc' in '$TESTTMP/tc/s/sub/.hg' (glob)
+  $ cd tc
   $ hg parents -q
   9:ed23f7fe024e
   $ grep ' s$' .hgsubstate
diff --git a/tests/test-subrepo-svn.t b/tests/test-subrepo-svn.t
--- a/tests/test-subrepo-svn.t
+++ b/tests/test-subrepo-svn.t
@@ -663,10 +663,10 @@  Test sanitizing ".hg/hgrc" in subrepo
   16 s
   $ cd ..
 
+  $ hg -R tc pull -u -q 2>&1 | sort
+  warning: removing potentially hostile 'hgrc' in '$TESTTMP/sub/tc/s/.hg' (glob)
+  warning: removing potentially hostile 'hgrc' in '$TESTTMP/sub/tc/s/sub/.hg' (glob)
   $ cd tc
-  $ hg pull -u -q 2>&1 | sort
-  warning: removing potentially hostile 'hgrc' in 's/.hg' (glob)
-  warning: removing potentially hostile 'hgrc' in 's/sub/.hg' (glob)
   $ grep ' s$' .hgsubstate
   16 s
   $ cat s/.hg/hgrc