Mercurial > public > mercurial-scm > hg
comparison mercurial/subrepo.py @ 14281:ccb7240acf32
subrepo: create subrepos using clone instead of pull
Subrepositories used to be created empty and then filled with data
using pull. This is wasteful when you do a clone from a local source
since it means that no hardlinks are created for the subrepos.
This patch make the hgsubrepo._get method check for an empty subrepo
and in that case do a clone instead of a pull. This brings in the same
data as before, but creates hardlinks when possible.
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Mon, 09 May 2011 17:15:44 +0200 |
parents | 680c3c6fcb48 |
children | ba883fa211f3 |
comparison
equal
deleted
inserted
replaced
14280:98e4d3914c2e | 14281:ccb7240acf32 |
---|---|
340 create = False | 340 create = False |
341 if not os.path.exists(os.path.join(root, '.hg')): | 341 if not os.path.exists(os.path.join(root, '.hg')): |
342 create = True | 342 create = True |
343 util.makedirs(root) | 343 util.makedirs(root) |
344 self._repo = hg.repository(r.ui, root, create=create) | 344 self._repo = hg.repository(r.ui, root, create=create) |
345 self._repo._subparent = r | 345 self._initrepo(r, state[0], create) |
346 self._repo._subsource = state[0] | 346 |
347 def _initrepo(self, parentrepo, source, create): | |
348 self._repo._subparent = parentrepo | |
349 self._repo._subsource = source | |
347 | 350 |
348 if create: | 351 if create: |
349 fp = self._repo.opener("hgrc", "w", text=True) | 352 fp = self._repo.opener("hgrc", "w", text=True) |
350 fp.write('[paths]\n') | 353 fp.write('[paths]\n') |
351 | 354 |
429 def _get(self, state): | 432 def _get(self, state): |
430 source, revision, kind = state | 433 source, revision, kind = state |
431 if revision not in self._repo: | 434 if revision not in self._repo: |
432 self._repo._subsource = source | 435 self._repo._subsource = source |
433 srcurl = _abssource(self._repo) | 436 srcurl = _abssource(self._repo) |
434 self._repo.ui.status(_('pulling subrepo %s from %s\n') | |
435 % (subrelpath(self), srcurl)) | |
436 other = hg.repository(self._repo.ui, srcurl) | 437 other = hg.repository(self._repo.ui, srcurl) |
437 self._repo.pull(other) | 438 if len(self._repo) == 0: |
439 self._repo.ui.status(_('cloning subrepo %s from %s\n') | |
440 % (subrelpath(self), srcurl)) | |
441 parentrepo = self._repo._subparent | |
442 shutil.rmtree(self._repo.root) | |
443 other, self._repo = hg.clone(self._repo._subparent.ui, other, | |
444 self._repo.root, update=False) | |
445 self._initrepo(parentrepo, source, create=True) | |
446 else: | |
447 self._repo.ui.status(_('pulling subrepo %s from %s\n') | |
448 % (subrelpath(self), srcurl)) | |
449 self._repo.pull(other) | |
438 bookmarks.updatefromremote(self._repo.ui, self._repo, other) | 450 bookmarks.updatefromremote(self._repo.ui, self._repo, other) |
439 | 451 |
440 def get(self, state, overwrite=False): | 452 def get(self, state, overwrite=False): |
441 self._get(state) | 453 self._get(state) |
442 source, revision, kind = state | 454 source, revision, kind = state |