##// END OF EJS Templates
narrow: add a --narrowspec flag to clone command...
Pulkit Goyal -
r39523:f4d4bd8c default
parent child Browse files
Show More
@@ -7,6 +7,7 b''
7 from __future__ import absolute_import
7 from __future__ import absolute_import
8
8
9 import itertools
9 import itertools
10 import os
10
11
11 from mercurial.i18n import _
12 from mercurial.i18n import _
12 from mercurial import (
13 from mercurial import (
@@ -25,6 +26,7 b' from mercurial import ('
25 repair,
26 repair,
26 repository,
27 repository,
27 repoview,
28 repoview,
29 sparse,
28 util,
30 util,
29 )
31 )
30
32
@@ -43,6 +45,8 b' def setup():'
43 _("create a narrow clone of select files")))
45 _("create a narrow clone of select files")))
44 entry[1].append(('', 'depth', '',
46 entry[1].append(('', 'depth', '',
45 _("limit the history fetched by distance from heads")))
47 _("limit the history fetched by distance from heads")))
48 entry[1].append(('', 'narrowspec', '',
49 _("read narrowspecs from file")))
46 # TODO(durin42): unify sparse/narrow --include/--exclude logic a bit
50 # TODO(durin42): unify sparse/narrow --include/--exclude logic a bit
47 if 'sparse' not in extensions.enabled():
51 if 'sparse' not in extensions.enabled():
48 entry[1].append(('', 'include', [],
52 entry[1].append(('', 'include', [],
@@ -73,6 +77,27 b' def clonenarrowcmd(orig, ui, repo, *args'
73 opts = pycompat.byteskwargs(opts)
77 opts = pycompat.byteskwargs(opts)
74 wrappedextraprepare = util.nullcontextmanager()
78 wrappedextraprepare = util.nullcontextmanager()
75 opts_narrow = opts['narrow']
79 opts_narrow = opts['narrow']
80 narrowspecfile = opts['narrowspec']
81
82 if narrowspecfile:
83 filepath = os.path.join(pycompat.getcwd(), narrowspecfile)
84 ui.status(_("reading narrowspec from '%s'\n") % filepath)
85 try:
86 fp = open(filepath, 'rb')
87 except IOError:
88 raise error.Abort(_("file '%s' not found") % filepath)
89
90 includes, excludes, profiles = sparse.parseconfig(ui, fp.read(),
91 'narrow')
92 if profiles:
93 raise error.Abort(_("cannot specify other files using '%include' in"
94 " narrowspec"))
95
96 # narrowspec is passed so we should assume that user wants narrow clone
97 opts_narrow = True
98 opts['include'].extend(includes)
99 opts['exclude'].extend(excludes)
100
76 if opts_narrow:
101 if opts_narrow:
77 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
102 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
78 # Create narrow spec patterns from clone flags
103 # Create narrow spec patterns from clone flags
@@ -123,3 +123,39 b' narrow clone everything but a directory '
123 dir/src/f9
123 dir/src/f9
124
124
125 $ cd ..
125 $ cd ..
126
127 Testing the --narrowspec flag to clone
128
129 $ cat >> narrowspecs <<EOF
130 > %include foo
131 > [include]
132 > path:dir/tests/
133 > file:dir/src/f12
134 > EOF
135
136 $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
137 reading narrowspec from '$TESTTMP/narrowspecs'
138 abort: cannot specify other files using '%include' in narrowspec
139 [255]
140
141 $ cat > narrowspecs <<EOF
142 > [include]
143 > path:dir/tests/
144 > file:dir/src/f12
145 > EOF
146
147 $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
148 reading narrowspec from '$TESTTMP/narrowspecs'
149 requesting all changes
150 adding changesets
151 adding manifests
152 adding file changes
153 added 40 changesets with 20 changes to 20 files
154 new changesets 681085829a73:26ce255d5b5d
155 updating to branch default
156 20 files updated, 0 files merged, 0 files removed, 0 files unresolved
157 $ cd specfile
158 $ hg tracked
159 I path:dir/tests
160 I path:file:dir/src/f12
161 $ cd ..
@@ -218,3 +218,39 b' simple clone'
218 dir/tests/t9
218 dir/tests/t9
219
219
220 $ cd ..
220 $ cd ..
221
222 Testing the --narrowspec flag to clone
223
224 $ cat >> narrowspecs <<EOF
225 > %include foo
226 > [include]
227 > path:dir/tests/
228 > dir/src/f12
229 > EOF
230
231 $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
232 reading narrowspec from '$TESTTMP/narrowspecs'
233 abort: cannot specify other files using '%include' in narrowspec
234 [255]
235
236 $ cat > narrowspecs <<EOF
237 > [include]
238 > path:dir/tests/
239 > file:dir/src/f12
240 > EOF
241
242 $ hg clone ssh://user@dummy/master specfile --narrowspec narrowspecs
243 reading narrowspec from '$TESTTMP/narrowspecs'
244 requesting all changes
245 adding changesets
246 adding manifests
247 adding file changes
248 added 21 changesets with 20 changes to 20 files
249 new changesets f93383bb3e99:26ce255d5b5d
250 updating to branch default
251 20 files updated, 0 files merged, 0 files removed, 0 files unresolved
252 $ cd specfile
253 $ hg tracked
254 I path:dir/tests
255 I path:file:dir/src/f12
256 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now