[PATCH 4 of 5 STABLE] subrepo: avoid sanitizing ".hg/hgrc" in meta data area for non-hg subrepos

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon May 5 06:15:55 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1399219390 -32400
#      Mon May 05 01:03:10 2014 +0900
# Branch stable
# Node ID 76b049cd41f77aebf34e6ca65b73c367e3eee219
# Parent  3814f3e2e6dd1db3f7c6a8a0395705ba008062fa
subrepo: avoid sanitizing ".hg/hgrc" in meta data area for non-hg subrepos

Before this patch, sanitizing ".hg/hgrc" scans directories and files
also in meta data area for non-hg subrepos: under ".svn" for
Subversion subrepo, for example.

This may cause not only performance impact (especially in large scale
subrepos) but also unexpected removing meta data files.

This patch avoids sanitizing ".hg/hgrc" in meta data area for non-hg
subrepos.

This patch stops checking "ignore" target at the first
(case-insensitive) appearance of it, because continuation of scanning
is meaningless in almost all cases.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -314,8 +314,12 @@
     if abort:
         raise util.Abort(_("default path for subrepository not found"))
 
-def _sanitize(ui, path):
+def _sanitize(ui, path, ignore):
     for dirname, dirs, names in os.walk(path):
+        for i, d in enumerate(dirs):
+            if d.lower() == ignore:
+                del dirs[i]
+                break
         if os.path.basename(dirname).lower() != '.hg':
             continue
         for f in names:
@@ -1050,7 +1054,7 @@
         # 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._ctx._repo.wjoin(self._path))
+        _sanitize(self._ui, self._ctx._repo.wjoin(self._path), '.svn')
         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 +1347,7 @@
                 self._gitcommand(['reset', 'HEAD'])
                 cmd.append('-f')
             self._gitcommand(cmd + args)
-            _sanitize(self._ui, self._abspath)
+            _sanitize(self._ui, self._abspath, '.git')
 
         def rawcheckout():
             # no branch to checkout, check it out with no branch
@@ -1392,7 +1396,7 @@
             if tracking[remote] != self._gitcurrentbranch():
                 checkout([tracking[remote]])
             self._gitcommand(['merge', '--ff', remote])
-            _sanitize(self._ui, self._abspath)
+            _sanitize(self._ui, self._abspath, '.git')
         else:
             # a real merge would be required, just checkout the revision
             rawcheckout()
@@ -1428,7 +1432,7 @@
                 self.get(state) # fast forward merge
             elif base != self._state[1]:
                 self._gitcommand(['merge', '--no-commit', revision])
-            _sanitize(self._ui, self._abspath)
+            _sanitize(self._ui, self._abspath, '.git')
 
         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
@@ -658,4 +658,13 @@
   $ cat s/sub/.hg/hgrc
   cat: s/sub/.hg/hgrc: No such file or directory
   [1]
-  $ cd ..
+
+Test that sanitizing is omitted in meta data area:
+
+  $ mkdir s/.git/.hg
+  $ echo '.hg/hgrc in git metadata area' > s/.git/.hg/hgrc
+  $ hg update -q -C af6d2edbb0d3
+  checking out detached HEAD in subrepo s
+  check out a git branch if you intend to make changes
+
+  $ cd ..
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
@@ -676,4 +676,10 @@
   cat: s/sub/.hg/hgrc: No such file or directory
   [1]
 
+Test that sanitizing is omitted in meta data area:
+
+  $ mkdir s/.svn/.hg
+  $ echo '.hg/hgrc in svn metadata area' > s/.svn/.hg/hgrc
+  $ hg update -q -C '.^1'
+
   $ cd ../..


More information about the Mercurial-devel mailing list