diff --git a/hgext/fastcheckout.py b/hgext/fastcheckout.py --- a/hgext/fastcheckout.py +++ b/hgext/fastcheckout.py @@ -26,9 +26,12 @@ error, exchange, hg, + localrepo, merge as mergemod, + narrowspec, pycompat, registrar, + repository, scmutil, util, vfs as vfsmod, @@ -47,6 +50,8 @@ 'fastcheckout', [ ('C', 'clean', False, _('discard uncommitted changes (no backup)')), + ('', 'include', [], _('pattern of files to include in checkout')), + ('', 'exclude', [], _('pattern of files to not include in checkout')), ('', 'purge', False, _('purge the working directory of untracked files'), ), @@ -75,6 +80,14 @@ purge the working directory of both untracked and ignored files, similar to running :hg:`purge --all`. + ``include`` and ``exclude`` define patterns of paths to include and + exclude in the working directory, respectively. A path is included in + the working directory if it matches a pattern in ``include`` but not + ``exclude``. Only ``path`` and ``rootfilesin`` patterns are supported. + If the pattern doesn't contain a ``:`` / prefix, it is assumed to be a + ``path`` pattern. If ``include`` is not provided, it defaults to all + paths. + The source repository must support modern versions of the Mercurial wire protocol. """ @@ -94,6 +107,9 @@ destvfs = vfsmod.vfs(dest, expandpath=True) + includepats = narrowspec.parsepatterns(opts['include']) + excludepats = narrowspec.parsepatterns(opts['exclude']) + overrides = { ('experimental', 'httppeer.advertise-v2'): True, } @@ -102,7 +118,9 @@ return dofastcheckout(ui, source, rev, destvfs, purge=opts.get('purge', False), purgeall=opts.get('purgeall', False), - clean=opts.get('clean', False)) + clean=opts.get('clean', False), + includepats=includepats, + excludepats=excludepats) def getpeer(ui, source): peer = hg.peer(ui, {}, source) @@ -114,7 +132,11 @@ return peer def dofastcheckout(ui, source, rev, destvfs, purge=False, purgeall=False, - clean=False): + clean=False, includepats=None, excludepats=None): + + # Empty sets need to be None to force a full clone/checkout. + if not includepats and not excludepats: + includepats, excludepats = None, None createdrepo = False peer = None @@ -124,7 +146,8 @@ peer = getpeer(ui, source) ui.write(_('fetching data from %s\n') % peer.url()) hg.clone(ui, {}, peer, destvfs.base, pull=True, - update=False, revs=[rev]) + update=False, revs=[rev], + storeincludepats=includepats, storeexcludepats=excludepats) createdrepo = True @@ -145,7 +168,8 @@ with peer.commandexecutor() as e: pullrev = e.callcommand('lookup', {'key': rev}).result() - exchange.pull(repo, peer, heads=[pullrev]) + exchange.pull(repo, peer, heads=[pullrev], + includepats=includepats, excludepats=excludepats) if not createdrepo and (purge or purgeall): ui.write(_('purging working directory\n')) @@ -164,3 +188,9 @@ clean=clean, updatecheck='none') return ret + +def featuresetup(ui, features): + features.add(repository.NARROW_REQUIREMENT) + +def extsetup(ui): + localrepo.featuresetupfuncs.add(featuresetup) diff --git a/tests/test-fastcheckout.t b/tests/test-fastcheckout.t --- a/tests/test-fastcheckout.t +++ b/tests/test-fastcheckout.t @@ -118,6 +118,59 @@ $ cat dest0/dir1/py3.py 0 +Bad value to --include results in error + + $ hg fastcheckout --include glob:* http://localhost:$HGPORT 6a9937924 badinclude + abort: invalid prefix on narrow pattern: glob:* + (narrow patterns must begin with one of the following: path:, rootfilesin:) + [255] + + $ hg fastcheckout --include glob:* http://localhost:$HGPORT 6a9937924 dest0 + abort: invalid prefix on narrow pattern: glob:* + (narrow patterns must begin with one of the following: path:, rootfilesin:) + [255] + +Bad value to --exclude results in error + + $ hg fastcheckout --exclude glob:* http://localhost:$HGPORT 6a9937924 badexclude + abort: invalid prefix on narrow pattern: glob:* + (narrow patterns must begin with one of the following: path:, rootfilesin:) + [255] + + $ hg fastcheckout --exclude glob:* http://localhost:$HGPORT 6a9937924 dest0 + abort: invalid prefix on narrow pattern: glob:* + (narrow patterns must begin with one of the following: path:, rootfilesin:) + [255] + +Narrow file clone works + + $ hg fastcheckout --include path:dir0 http://localhost:$HGPORT 15c769176a narrow-dest0 + fetching data from http://localhost:$HGPORT + new changesets 6a9937924083:15c769176aab + updating to 15c769176aab + 5 files updated, 0 files merged, 0 files removed, 0 files unresolved + +#if reporevlogstore + $ find narrow-dest0/.hg/store -type f | sort + narrow-dest0/.hg/store/00changelog.i + narrow-dest0/.hg/store/00manifest.i + narrow-dest0/.hg/store/data/dir0/child0/c.c.i + narrow-dest0/.hg/store/data/dir0/child0/py0.py.i + narrow-dest0/.hg/store/data/dir0/child1/py1.py.i + narrow-dest0/.hg/store/data/dir0/child1/py2.py.i + narrow-dest0/.hg/store/data/dir0/file0.txt.i + narrow-dest0/.hg/store/data/dir1/file1.txt.i + narrow-dest0/.hg/store/data/dir1/file2.txt.i + narrow-dest0/.hg/store/data/dir1/py3.py.i + narrow-dest0/.hg/store/data/foo.i + narrow-dest0/.hg/store/fncache + narrow-dest0/.hg/store/narrowspec + narrow-dest0/.hg/store/phaseroots + narrow-dest0/.hg/store/undo + narrow-dest0/.hg/store/undo.backupfiles + narrow-dest0/.hg/store/undo.phaseroots +#endif + Should not have any server-side errors $ cat error.log