Skip to content
Snippets Groups Projects
Commit f4d4bd8c8911 authored by Pulkit Goyal's avatar Pulkit Goyal
Browse files

narrow: add a --narrowspec flag to clone command

This patch adds a --narrowspec flag to `hg clone` command in narrow extension
which can be used to read a file and parse narrowspecs from it and use it while
cloning a repository.

The --narrowspec flag assumes that the user wanted to narrow the clone.

Tests are added both for ellipsis and non-ellipsis mode.

Differential Revision: https://phab.mercurial-scm.org/D4156
parent 61700d525a3b
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import itertools import itertools
import os
from mercurial.i18n import _ from mercurial.i18n import _
from mercurial import ( from mercurial import (
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
repair, repair,
repository, repository,
repoview, repoview,
sparse,
util, util,
) )
...@@ -43,6 +45,8 @@ ...@@ -43,6 +45,8 @@
_("create a narrow clone of select files"))) _("create a narrow clone of select files")))
entry[1].append(('', 'depth', '', entry[1].append(('', 'depth', '',
_("limit the history fetched by distance from heads"))) _("limit the history fetched by distance from heads")))
entry[1].append(('', 'narrowspec', '',
_("read narrowspecs from file")))
# TODO(durin42): unify sparse/narrow --include/--exclude logic a bit # TODO(durin42): unify sparse/narrow --include/--exclude logic a bit
if 'sparse' not in extensions.enabled(): if 'sparse' not in extensions.enabled():
entry[1].append(('', 'include', [], entry[1].append(('', 'include', [],
...@@ -73,6 +77,27 @@ ...@@ -73,6 +77,27 @@
opts = pycompat.byteskwargs(opts) opts = pycompat.byteskwargs(opts)
wrappedextraprepare = util.nullcontextmanager() wrappedextraprepare = util.nullcontextmanager()
opts_narrow = opts['narrow'] opts_narrow = opts['narrow']
narrowspecfile = opts['narrowspec']
if narrowspecfile:
filepath = os.path.join(pycompat.getcwd(), narrowspecfile)
ui.status(_("reading narrowspec from '%s'\n") % filepath)
try:
fp = open(filepath, 'rb')
except IOError:
raise error.Abort(_("file '%s' not found") % filepath)
includes, excludes, profiles = sparse.parseconfig(ui, fp.read(),
'narrow')
if profiles:
raise error.Abort(_("cannot specify other files using '%include' in"
" narrowspec"))
# narrowspec is passed so we should assume that user wants narrow clone
opts_narrow = True
opts['include'].extend(includes)
opts['exclude'].extend(excludes)
if opts_narrow: if opts_narrow:
def pullbundle2extraprepare_widen(orig, pullop, kwargs): def pullbundle2extraprepare_widen(orig, pullop, kwargs):
# Create narrow spec patterns from clone flags # Create narrow spec patterns from clone flags
......
...@@ -123,3 +123,39 @@ ...@@ -123,3 +123,39 @@
dir/src/f9 dir/src/f9
$ cd .. $ cd ..
Testing the --narrowspec flag to clone
$ cat >> narrowspecs <<EOF
> %include foo
> [include]
> path:dir/tests/
> file:dir/src/f12
> EOF
$ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
reading narrowspec from '$TESTTMP/narrowspecs'
abort: cannot specify other files using '%include' in narrowspec
[255]
$ cat > narrowspecs <<EOF
> [include]
> path:dir/tests/
> file:dir/src/f12
> EOF
$ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
reading narrowspec from '$TESTTMP/narrowspecs'
requesting all changes
adding changesets
adding manifests
adding file changes
added 40 changesets with 20 changes to 20 files
new changesets 681085829a73:26ce255d5b5d
updating to branch default
20 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd specfile
$ hg tracked
I path:dir/tests
I path:file:dir/src/f12
$ cd ..
...@@ -218,3 +218,39 @@ ...@@ -218,3 +218,39 @@
dir/tests/t9 dir/tests/t9
$ cd .. $ cd ..
Testing the --narrowspec flag to clone
$ cat >> narrowspecs <<EOF
> %include foo
> [include]
> path:dir/tests/
> dir/src/f12
> EOF
$ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
reading narrowspec from '$TESTTMP/narrowspecs'
abort: cannot specify other files using '%include' in narrowspec
[255]
$ cat > narrowspecs <<EOF
> [include]
> path:dir/tests/
> file:dir/src/f12
> EOF
$ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
reading narrowspec from '$TESTTMP/narrowspecs'
requesting all changes
adding changesets
adding manifests
adding file changes
added 21 changesets with 20 changes to 20 files
new changesets f93383bb3e99:26ce255d5b5d
updating to branch default
20 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd specfile
$ hg tracked
I path:dir/tests
I path:file:dir/src/f12
$ cd ..
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment