4 # |
4 # |
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 import copy |
8 import copy |
9 import errno, os, re, shutil, posixpath, sys |
9 import errno, os, re, posixpath, sys |
10 import xml.dom.minidom |
10 import xml.dom.minidom |
11 import stat, subprocess, tarfile |
11 import stat, subprocess, tarfile |
12 from i18n import _ |
12 from i18n import _ |
13 import config, util, node, error, cmdutil, scmutil, match as matchmod |
13 import config, util, node, error, cmdutil, scmutil, match as matchmod |
14 import phases |
14 import phases |
777 other = hg.peer(self._repo, {}, srcurl) |
777 other = hg.peer(self._repo, {}, srcurl) |
778 if len(self._repo) == 0: |
778 if len(self._repo) == 0: |
779 self.ui.status(_('cloning subrepo %s from %s\n') |
779 self.ui.status(_('cloning subrepo %s from %s\n') |
780 % (subrelpath(self), srcurl)) |
780 % (subrelpath(self), srcurl)) |
781 parentrepo = self._repo._subparent |
781 parentrepo = self._repo._subparent |
782 shutil.rmtree(self._repo.path) |
782 # use self._repo.vfs instead of self.wvfs to remove .hg only |
|
783 self._repo.vfs.rmtree() |
783 other, cloned = hg.clone(self._repo._subparent.baseui, {}, |
784 other, cloned = hg.clone(self._repo._subparent.baseui, {}, |
784 other, self._repo.root, |
785 other, self._repo.root, |
785 update=False) |
786 update=False) |
786 self._repo = cloned.local() |
787 self._repo = cloned.local() |
787 self._initrepo(parentrepo, source, create=True) |
788 self._initrepo(parentrepo, source, create=True) |
1112 self.ui.warn(_('not removing repo %s because ' |
1113 self.ui.warn(_('not removing repo %s because ' |
1113 'it has changes.\n') % self._path) |
1114 'it has changes.\n') % self._path) |
1114 return |
1115 return |
1115 self.ui.note(_('removing subrepo %s\n') % self._path) |
1116 self.ui.note(_('removing subrepo %s\n') % self._path) |
1116 |
1117 |
1117 def onerror(function, path, excinfo): |
|
1118 if function is not os.remove: |
|
1119 raise |
|
1120 # read-only files cannot be unlinked under Windows |
|
1121 s = os.stat(path) |
|
1122 if (s.st_mode & stat.S_IWRITE) != 0: |
|
1123 raise |
|
1124 os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE) |
|
1125 os.remove(path) |
|
1126 |
|
1127 path = self._ctx.repo().wjoin(self._path) |
1118 path = self._ctx.repo().wjoin(self._path) |
1128 shutil.rmtree(path, onerror=onerror) |
1119 self.wvfs.rmtree(forcibly=True) |
1129 try: |
1120 try: |
1130 os.removedirs(os.path.dirname(path)) |
1121 os.removedirs(os.path.dirname(path)) |
1131 except OSError: |
1122 except OSError: |
1132 pass |
1123 pass |
1133 |
1124 |
1635 for f, kind in self.wvfs.readdir(): |
1626 for f, kind in self.wvfs.readdir(): |
1636 if f == '.git': |
1627 if f == '.git': |
1637 continue |
1628 continue |
1638 path = os.path.join(self._abspath, f) |
1629 path = os.path.join(self._abspath, f) |
1639 if kind == stat.S_IFDIR: |
1630 if kind == stat.S_IFDIR: |
1640 shutil.rmtree(path) |
1631 self.wvfs.rmtree(f) |
1641 else: |
1632 else: |
1642 os.remove(path) |
1633 os.remove(path) |
1643 |
1634 |
1644 def archive(self, archiver, prefix, match=None): |
1635 def archive(self, archiver, prefix, match=None): |
1645 total = 0 |
1636 total = 0 |