##// END OF EJS Templates
narrow: add a --narrowspec flag to clone command...
Pulkit Goyal -
r39523:f4d4bd8c default
parent child Browse files
Show More
@@ -1,403 +1,428 b''
1 1 # narrowcommands.py - command modifications for narrowhg extension
2 2 #
3 3 # Copyright 2017 Google, Inc.
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7 from __future__ import absolute_import
8 8
9 9 import itertools
10 import os
10 11
11 12 from mercurial.i18n import _
12 13 from mercurial import (
13 14 cmdutil,
14 15 commands,
15 16 discovery,
16 17 error,
17 18 exchange,
18 19 extensions,
19 20 hg,
20 21 merge,
21 22 narrowspec,
22 23 node,
23 24 pycompat,
24 25 registrar,
25 26 repair,
26 27 repository,
27 28 repoview,
29 sparse,
28 30 util,
29 31 )
30 32
31 33 from . import (
32 34 narrowbundle2,
33 35 )
34 36
35 37 table = {}
36 38 command = registrar.command(table)
37 39
38 40 def setup():
39 41 """Wraps user-facing mercurial commands with narrow-aware versions."""
40 42
41 43 entry = extensions.wrapcommand(commands.table, 'clone', clonenarrowcmd)
42 44 entry[1].append(('', 'narrow', None,
43 45 _("create a narrow clone of select files")))
44 46 entry[1].append(('', 'depth', '',
45 47 _("limit the history fetched by distance from heads")))
48 entry[1].append(('', 'narrowspec', '',
49 _("read narrowspecs from file")))
46 50 # TODO(durin42): unify sparse/narrow --include/--exclude logic a bit
47 51 if 'sparse' not in extensions.enabled():
48 52 entry[1].append(('', 'include', [],
49 53 _("specifically fetch this file/directory")))
50 54 entry[1].append(
51 55 ('', 'exclude', [],
52 56 _("do not fetch this file/directory, even if included")))
53 57
54 58 entry = extensions.wrapcommand(commands.table, 'pull', pullnarrowcmd)
55 59 entry[1].append(('', 'depth', '',
56 60 _("limit the history fetched by distance from heads")))
57 61
58 62 extensions.wrapcommand(commands.table, 'archive', archivenarrowcmd)
59 63
60 64 def expandpull(pullop, includepats, excludepats):
61 65 if not narrowspec.needsexpansion(includepats):
62 66 return includepats, excludepats
63 67
64 68 heads = pullop.heads or pullop.rheads
65 69 includepats, excludepats = pullop.remote.expandnarrow(
66 70 includepats, excludepats, heads)
67 71 pullop.repo.ui.debug('Expanded narrowspec to inc=%s, exc=%s\n' % (
68 72 includepats, excludepats))
69 73 return set(includepats), set(excludepats)
70 74
71 75 def clonenarrowcmd(orig, ui, repo, *args, **opts):
72 76 """Wraps clone command, so 'hg clone' first wraps localrepo.clone()."""
73 77 opts = pycompat.byteskwargs(opts)
74 78 wrappedextraprepare = util.nullcontextmanager()
75 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 101 if opts_narrow:
77 102 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
78 103 # Create narrow spec patterns from clone flags
79 104 includepats = narrowspec.parsepatterns(opts['include'])
80 105 excludepats = narrowspec.parsepatterns(opts['exclude'])
81 106
82 107 # If necessary, ask the server to expand the narrowspec.
83 108 includepats, excludepats = expandpull(
84 109 pullop, includepats, excludepats)
85 110
86 111 if not includepats and excludepats:
87 112 # If nothing was included, we assume the user meant to include
88 113 # everything, except what they asked to exclude.
89 114 includepats = {'path:.'}
90 115
91 116 pullop.repo.setnarrowpats(includepats, excludepats)
92 117
93 118 # This will populate 'includepats' etc with the values from the
94 119 # narrowspec we just saved.
95 120 orig(pullop, kwargs)
96 121
97 122 if opts.get('depth'):
98 123 kwargs['depth'] = opts['depth']
99 124 wrappedextraprepare = extensions.wrappedfunction(exchange,
100 125 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
101 126
102 127 def pullnarrow(orig, repo, *args, **kwargs):
103 128 if opts_narrow:
104 129 repo.requirements.add(repository.NARROW_REQUIREMENT)
105 130 repo._writerequirements()
106 131
107 132 return orig(repo, *args, **kwargs)
108 133
109 134 wrappedpull = extensions.wrappedfunction(exchange, 'pull', pullnarrow)
110 135
111 136 with wrappedextraprepare, wrappedpull:
112 137 return orig(ui, repo, *args, **pycompat.strkwargs(opts))
113 138
114 139 def pullnarrowcmd(orig, ui, repo, *args, **opts):
115 140 """Wraps pull command to allow modifying narrow spec."""
116 141 wrappedextraprepare = util.nullcontextmanager()
117 142 if repository.NARROW_REQUIREMENT in repo.requirements:
118 143
119 144 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
120 145 orig(pullop, kwargs)
121 146 if opts.get(r'depth'):
122 147 kwargs['depth'] = opts[r'depth']
123 148 wrappedextraprepare = extensions.wrappedfunction(exchange,
124 149 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
125 150
126 151 with wrappedextraprepare:
127 152 return orig(ui, repo, *args, **opts)
128 153
129 154 def archivenarrowcmd(orig, ui, repo, *args, **opts):
130 155 """Wraps archive command to narrow the default includes."""
131 156 if repository.NARROW_REQUIREMENT in repo.requirements:
132 157 repo_includes, repo_excludes = repo.narrowpats
133 158 includes = set(opts.get(r'include', []))
134 159 excludes = set(opts.get(r'exclude', []))
135 160 includes, excludes, unused_invalid = narrowspec.restrictpatterns(
136 161 includes, excludes, repo_includes, repo_excludes)
137 162 if includes:
138 163 opts[r'include'] = includes
139 164 if excludes:
140 165 opts[r'exclude'] = excludes
141 166 return orig(ui, repo, *args, **opts)
142 167
143 168 def pullbundle2extraprepare(orig, pullop, kwargs):
144 169 repo = pullop.repo
145 170 if repository.NARROW_REQUIREMENT not in repo.requirements:
146 171 return orig(pullop, kwargs)
147 172
148 173 if narrowbundle2.NARROWCAP not in pullop.remotebundle2caps:
149 174 raise error.Abort(_("server doesn't support narrow clones"))
150 175 orig(pullop, kwargs)
151 176 kwargs['narrow'] = True
152 177 include, exclude = repo.narrowpats
153 178 kwargs['oldincludepats'] = include
154 179 kwargs['oldexcludepats'] = exclude
155 180 kwargs['includepats'] = include
156 181 kwargs['excludepats'] = exclude
157 182 kwargs['known'] = [node.hex(ctx.node()) for ctx in
158 183 repo.set('::%ln', pullop.common)
159 184 if ctx.node() != node.nullid]
160 185 if not kwargs['known']:
161 186 # Mercurial serialized an empty list as '' and deserializes it as
162 187 # [''], so delete it instead to avoid handling the empty string on the
163 188 # server.
164 189 del kwargs['known']
165 190
166 191 extensions.wrapfunction(exchange,'_pullbundle2extraprepare',
167 192 pullbundle2extraprepare)
168 193
169 194 def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
170 195 newincludes, newexcludes, force):
171 196 oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
172 197 newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
173 198
174 199 # This is essentially doing "hg outgoing" to find all local-only
175 200 # commits. We will then check that the local-only commits don't
176 201 # have any changes to files that will be untracked.
177 202 unfi = repo.unfiltered()
178 203 outgoing = discovery.findcommonoutgoing(unfi, remote,
179 204 commoninc=commoninc)
180 205 ui.status(_('looking for local changes to affected paths\n'))
181 206 localnodes = []
182 207 for n in itertools.chain(outgoing.missing, outgoing.excluded):
183 208 if any(oldmatch(f) and not newmatch(f) for f in unfi[n].files()):
184 209 localnodes.append(n)
185 210 revstostrip = unfi.revs('descendants(%ln)', localnodes)
186 211 hiddenrevs = repoview.filterrevs(repo, 'visible')
187 212 visibletostrip = list(repo.changelog.node(r)
188 213 for r in (revstostrip - hiddenrevs))
189 214 if visibletostrip:
190 215 ui.status(_('The following changeset(s) or their ancestors have '
191 216 'local changes not on the remote:\n'))
192 217 maxnodes = 10
193 218 if ui.verbose or len(visibletostrip) <= maxnodes:
194 219 for n in visibletostrip:
195 220 ui.status('%s\n' % node.short(n))
196 221 else:
197 222 for n in visibletostrip[:maxnodes]:
198 223 ui.status('%s\n' % node.short(n))
199 224 ui.status(_('...and %d more, use --verbose to list all\n') %
200 225 (len(visibletostrip) - maxnodes))
201 226 if not force:
202 227 raise error.Abort(_('local changes found'),
203 228 hint=_('use --force-delete-local-changes to '
204 229 'ignore'))
205 230
206 231 with ui.uninterruptable():
207 232 if revstostrip:
208 233 tostrip = [unfi.changelog.node(r) for r in revstostrip]
209 234 if repo['.'].node() in tostrip:
210 235 # stripping working copy, so move to a different commit first
211 236 urev = max(repo.revs('(::%n) - %ln + null',
212 237 repo['.'].node(), visibletostrip))
213 238 hg.clean(repo, urev)
214 239 repair.strip(ui, unfi, tostrip, topic='narrow')
215 240
216 241 todelete = []
217 242 for f, f2, size in repo.store.datafiles():
218 243 if f.startswith('data/'):
219 244 file = f[5:-2]
220 245 if not newmatch(file):
221 246 todelete.append(f)
222 247 elif f.startswith('meta/'):
223 248 dir = f[5:-13]
224 249 dirs = ['.'] + sorted(util.dirs({dir})) + [dir]
225 250 include = True
226 251 for d in dirs:
227 252 visit = newmatch.visitdir(d)
228 253 if not visit:
229 254 include = False
230 255 break
231 256 if visit == 'all':
232 257 break
233 258 if not include:
234 259 todelete.append(f)
235 260
236 261 repo.destroying()
237 262
238 263 with repo.transaction("narrowing"):
239 264 for f in todelete:
240 265 ui.status(_('deleting %s\n') % f)
241 266 util.unlinkpath(repo.svfs.join(f))
242 267 repo.store.markremoved(f)
243 268
244 269 for f in repo.dirstate:
245 270 if not newmatch(f):
246 271 repo.dirstate.drop(f)
247 272 repo.wvfs.unlinkpath(f)
248 273 repo.setnarrowpats(newincludes, newexcludes)
249 274
250 275 repo.destroyed()
251 276
252 277 def _widen(ui, repo, remote, commoninc, newincludes, newexcludes):
253 278 newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
254 279
255 280 # TODO(martinvonz): Get expansion working with widening/narrowing.
256 281 if narrowspec.needsexpansion(newincludes):
257 282 raise error.Abort('Expansion not yet supported on pull')
258 283
259 284 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
260 285 orig(pullop, kwargs)
261 286 # The old{in,ex}cludepats have already been set by orig()
262 287 kwargs['includepats'] = newincludes
263 288 kwargs['excludepats'] = newexcludes
264 289 wrappedextraprepare = extensions.wrappedfunction(exchange,
265 290 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
266 291
267 292 # define a function that narrowbundle2 can call after creating the
268 293 # backup bundle, but before applying the bundle from the server
269 294 def setnewnarrowpats():
270 295 repo.setnarrowpats(newincludes, newexcludes)
271 296 repo.setnewnarrowpats = setnewnarrowpats
272 297
273 298 with ui.uninterruptable():
274 299 ds = repo.dirstate
275 300 p1, p2 = ds.p1(), ds.p2()
276 301 with ds.parentchange():
277 302 ds.setparents(node.nullid, node.nullid)
278 303 common = commoninc[0]
279 304 with wrappedextraprepare:
280 305 exchange.pull(repo, remote, heads=common)
281 306 with ds.parentchange():
282 307 ds.setparents(p1, p2)
283 308
284 309 actions = {k: [] for k in 'a am f g cd dc r dm dg m e k p pr'.split()}
285 310 addgaction = actions['g'].append
286 311
287 312 mf = repo['.'].manifest().matches(newmatch)
288 313 for f, fn in mf.iteritems():
289 314 if f not in repo.dirstate:
290 315 addgaction((f, (mf.flags(f), False),
291 316 "add from widened narrow clone"))
292 317
293 318 merge.applyupdates(repo, actions, wctx=repo[None],
294 319 mctx=repo['.'], overwrite=False)
295 320 merge.recordupdates(repo, actions, branchmerge=False)
296 321
297 322 # TODO(rdamazio): Make new matcher format and update description
298 323 @command('tracked',
299 324 [('', 'addinclude', [], _('new paths to include')),
300 325 ('', 'removeinclude', [], _('old paths to no longer include')),
301 326 ('', 'addexclude', [], _('new paths to exclude')),
302 327 ('', 'removeexclude', [], _('old paths to no longer exclude')),
303 328 ('', 'clear', False, _('whether to replace the existing narrowspec')),
304 329 ('', 'force-delete-local-changes', False,
305 330 _('forces deletion of local changes when narrowing')),
306 331 ] + commands.remoteopts,
307 332 _('[OPTIONS]... [REMOTE]'),
308 333 inferrepo=True)
309 334 def trackedcmd(ui, repo, remotepath=None, *pats, **opts):
310 335 """show or change the current narrowspec
311 336
312 337 With no argument, shows the current narrowspec entries, one per line. Each
313 338 line will be prefixed with 'I' or 'X' for included or excluded patterns,
314 339 respectively.
315 340
316 341 The narrowspec is comprised of expressions to match remote files and/or
317 342 directories that should be pulled into your client.
318 343 The narrowspec has *include* and *exclude* expressions, with excludes always
319 344 trumping includes: that is, if a file matches an exclude expression, it will
320 345 be excluded even if it also matches an include expression.
321 346 Excluding files that were never included has no effect.
322 347
323 348 Each included or excluded entry is in the format described by
324 349 'hg help patterns'.
325 350
326 351 The options allow you to add or remove included and excluded expressions.
327 352
328 353 If --clear is specified, then all previous includes and excludes are DROPPED
329 354 and replaced by the new ones specified to --addinclude and --addexclude.
330 355 If --clear is specified without any further options, the narrowspec will be
331 356 empty and will not match any files.
332 357 """
333 358 opts = pycompat.byteskwargs(opts)
334 359 if repository.NARROW_REQUIREMENT not in repo.requirements:
335 360 ui.warn(_('The narrow command is only supported on respositories cloned'
336 361 ' with --narrow.\n'))
337 362 return 1
338 363
339 364 # Before supporting, decide whether it "hg tracked --clear" should mean
340 365 # tracking no paths or all paths.
341 366 if opts['clear']:
342 367 ui.warn(_('The --clear option is not yet supported.\n'))
343 368 return 1
344 369
345 370 if narrowspec.needsexpansion(opts['addinclude'] + opts['addexclude']):
346 371 raise error.Abort('Expansion not yet supported on widen/narrow')
347 372
348 373 addedincludes = narrowspec.parsepatterns(opts['addinclude'])
349 374 removedincludes = narrowspec.parsepatterns(opts['removeinclude'])
350 375 addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
351 376 removedexcludes = narrowspec.parsepatterns(opts['removeexclude'])
352 377 widening = addedincludes or removedexcludes
353 378 narrowing = removedincludes or addedexcludes
354 379 only_show = not widening and not narrowing
355 380
356 381 # Only print the current narrowspec.
357 382 if only_show:
358 383 include, exclude = repo.narrowpats
359 384
360 385 ui.pager('tracked')
361 386 fm = ui.formatter('narrow', opts)
362 387 for i in sorted(include):
363 388 fm.startitem()
364 389 fm.write('status', '%s ', 'I', label='narrow.included')
365 390 fm.write('pat', '%s\n', i, label='narrow.included')
366 391 for i in sorted(exclude):
367 392 fm.startitem()
368 393 fm.write('status', '%s ', 'X', label='narrow.excluded')
369 394 fm.write('pat', '%s\n', i, label='narrow.excluded')
370 395 fm.end()
371 396 return 0
372 397
373 398 with repo.wlock(), repo.lock():
374 399 cmdutil.bailifchanged(repo)
375 400
376 401 # Find the revisions we have in common with the remote. These will
377 402 # be used for finding local-only changes for narrowing. They will
378 403 # also define the set of revisions to update for widening.
379 404 remotepath = ui.expandpath(remotepath or 'default')
380 405 url, branches = hg.parseurl(remotepath)
381 406 ui.status(_('comparing with %s\n') % util.hidepassword(url))
382 407 remote = hg.peer(repo, opts, url)
383 408 commoninc = discovery.findcommonincoming(repo, remote)
384 409
385 410 oldincludes, oldexcludes = repo.narrowpats
386 411 if narrowing:
387 412 newincludes = oldincludes - removedincludes
388 413 newexcludes = oldexcludes | addedexcludes
389 414 _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
390 415 newincludes, newexcludes,
391 416 opts['force_delete_local_changes'])
392 417 # _narrow() updated the narrowspec and _widen() below needs to
393 418 # use the updated values as its base (otherwise removed includes
394 419 # and addedexcludes will be lost in the resulting narrowspec)
395 420 oldincludes = newincludes
396 421 oldexcludes = newexcludes
397 422
398 423 if widening:
399 424 newincludes = oldincludes | addedincludes
400 425 newexcludes = oldexcludes - removedexcludes
401 426 _widen(ui, repo, remote, commoninc, newincludes, newexcludes)
402 427
403 428 return 0
@@ -1,125 +1,161 b''
1 1 $ . "$TESTDIR/narrow-library.sh"
2 2
3 3 $ hg init master
4 4 $ cd master
5 5 $ mkdir dir
6 6 $ mkdir dir/src
7 7 $ cd dir/src
8 8 $ for x in `$TESTDIR/seq.py 20`; do echo $x > "f$x"; hg add "f$x"; hg commit -m "Commit src $x"; done
9 9 $ cd ..
10 10 $ mkdir tests
11 11 $ cd tests
12 12 $ for x in `$TESTDIR/seq.py 20`; do echo $x > "t$x"; hg add "t$x"; hg commit -m "Commit test $x"; done
13 13 $ cd ../../..
14 14
15 15 narrow clone a file, f10
16 16
17 17 $ hg clone --narrow ssh://user@dummy/master narrow --noupdate --include "dir/src/f10"
18 18 requesting all changes
19 19 adding changesets
20 20 adding manifests
21 21 adding file changes
22 22 added 40 changesets with 1 changes to 1 files
23 23 new changesets *:* (glob)
24 24 $ cd narrow
25 25 $ cat .hg/requires | grep -v generaldelta
26 26 dotencode
27 27 fncache
28 28 narrowhg-experimental
29 29 revlogv1
30 30 store
31 31 testonly-simplestore (reposimplestore !)
32 32
33 33 $ hg tracked
34 34 I path:dir/src/f10
35 35 $ hg update
36 36 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
37 37 $ find * | sort
38 38 dir
39 39 dir/src
40 40 dir/src/f10
41 41 $ cat dir/src/f10
42 42 10
43 43
44 44 $ cd ..
45 45
46 46 narrow clone a directory, tests/, except tests/t19
47 47
48 48 $ hg clone --narrow ssh://user@dummy/master narrowdir --noupdate --include "dir/tests/" --exclude "dir/tests/t19"
49 49 requesting all changes
50 50 adding changesets
51 51 adding manifests
52 52 adding file changes
53 53 added 40 changesets with 19 changes to 19 files
54 54 new changesets *:* (glob)
55 55 $ cd narrowdir
56 56 $ hg tracked
57 57 I path:dir/tests
58 58 X path:dir/tests/t19
59 59 $ hg update
60 60 19 files updated, 0 files merged, 0 files removed, 0 files unresolved
61 61 $ find * | sort
62 62 dir
63 63 dir/tests
64 64 dir/tests/t1
65 65 dir/tests/t10
66 66 dir/tests/t11
67 67 dir/tests/t12
68 68 dir/tests/t13
69 69 dir/tests/t14
70 70 dir/tests/t15
71 71 dir/tests/t16
72 72 dir/tests/t17
73 73 dir/tests/t18
74 74 dir/tests/t2
75 75 dir/tests/t20
76 76 dir/tests/t3
77 77 dir/tests/t4
78 78 dir/tests/t5
79 79 dir/tests/t6
80 80 dir/tests/t7
81 81 dir/tests/t8
82 82 dir/tests/t9
83 83
84 84 $ cd ..
85 85
86 86 narrow clone everything but a directory (tests/)
87 87
88 88 $ hg clone --narrow ssh://user@dummy/master narrowroot --noupdate --exclude "dir/tests"
89 89 requesting all changes
90 90 adding changesets
91 91 adding manifests
92 92 adding file changes
93 93 added 40 changesets with 20 changes to 20 files
94 94 new changesets *:* (glob)
95 95 $ cd narrowroot
96 96 $ hg tracked
97 97 I path:.
98 98 X path:dir/tests
99 99 $ hg update
100 100 20 files updated, 0 files merged, 0 files removed, 0 files unresolved
101 101 $ find * | sort
102 102 dir
103 103 dir/src
104 104 dir/src/f1
105 105 dir/src/f10
106 106 dir/src/f11
107 107 dir/src/f12
108 108 dir/src/f13
109 109 dir/src/f14
110 110 dir/src/f15
111 111 dir/src/f16
112 112 dir/src/f17
113 113 dir/src/f18
114 114 dir/src/f19
115 115 dir/src/f2
116 116 dir/src/f20
117 117 dir/src/f3
118 118 dir/src/f4
119 119 dir/src/f5
120 120 dir/src/f6
121 121 dir/src/f7
122 122 dir/src/f8
123 123 dir/src/f9
124 124
125 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 ..
@@ -1,220 +1,256 b''
1 1 $ . "$TESTDIR/narrow-library.sh"
2 2
3 3 $ hg init master
4 4 $ cd master
5 5 $ cat >> .hg/hgrc <<EOF
6 6 > [narrow]
7 7 > serveellipses=True
8 8 > EOF
9 9 $ mkdir dir
10 10 $ mkdir dir/src
11 11 $ cd dir/src
12 12 $ for x in `$TESTDIR/seq.py 20`; do echo $x > "f$x"; hg add "f$x"; hg commit -m "Commit src $x"; done
13 13 $ cd ..
14 14 $ mkdir tests
15 15 $ cd tests
16 16 $ for x in `$TESTDIR/seq.py 20`; do echo $x > "t$x"; hg add "t$x"; hg commit -m "Commit test $x"; done
17 17 $ cd ../../..
18 18
19 19 narrow clone a file, f10
20 20
21 21 $ hg clone --narrow ssh://user@dummy/master narrow --noupdate --include "dir/src/f10"
22 22 requesting all changes
23 23 adding changesets
24 24 adding manifests
25 25 adding file changes
26 26 added 3 changesets with 1 changes to 1 files
27 27 new changesets *:* (glob)
28 28 $ cd narrow
29 29 $ cat .hg/requires | grep -v generaldelta
30 30 dotencode
31 31 fncache
32 32 narrowhg-experimental
33 33 revlogv1
34 34 store
35 35 testonly-simplestore (reposimplestore !)
36 36
37 37 $ hg tracked
38 38 I path:dir/src/f10
39 39 $ hg tracked
40 40 I path:dir/src/f10
41 41 $ hg update
42 42 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
43 43 $ find * | sort
44 44 dir
45 45 dir/src
46 46 dir/src/f10
47 47 $ cat dir/src/f10
48 48 10
49 49
50 50 $ cd ..
51 51
52 52 narrow clone with a newline should fail
53 53
54 54 $ hg clone --narrow ssh://user@dummy/master narrow_fail --noupdate --include 'dir/src/f10
55 55 > '
56 56 requesting all changes
57 57 abort: newlines are not allowed in narrowspec paths
58 58 [255]
59 59
60 60 narrow clone a directory, tests/, except tests/t19
61 61
62 62 $ hg clone --narrow ssh://user@dummy/master narrowdir --noupdate --include "dir/tests/" --exclude "dir/tests/t19"
63 63 requesting all changes
64 64 adding changesets
65 65 adding manifests
66 66 adding file changes
67 67 added 21 changesets with 19 changes to 19 files
68 68 new changesets *:* (glob)
69 69 $ cd narrowdir
70 70 $ hg tracked
71 71 I path:dir/tests
72 72 X path:dir/tests/t19
73 73 $ hg tracked
74 74 I path:dir/tests
75 75 X path:dir/tests/t19
76 76 $ hg update
77 77 19 files updated, 0 files merged, 0 files removed, 0 files unresolved
78 78 $ find * | sort
79 79 dir
80 80 dir/tests
81 81 dir/tests/t1
82 82 dir/tests/t10
83 83 dir/tests/t11
84 84 dir/tests/t12
85 85 dir/tests/t13
86 86 dir/tests/t14
87 87 dir/tests/t15
88 88 dir/tests/t16
89 89 dir/tests/t17
90 90 dir/tests/t18
91 91 dir/tests/t2
92 92 dir/tests/t20
93 93 dir/tests/t3
94 94 dir/tests/t4
95 95 dir/tests/t5
96 96 dir/tests/t6
97 97 dir/tests/t7
98 98 dir/tests/t8
99 99 dir/tests/t9
100 100
101 101 $ cd ..
102 102
103 103 narrow clone everything but a directory (tests/)
104 104
105 105 $ hg clone --narrow ssh://user@dummy/master narrowroot --noupdate --exclude "dir/tests"
106 106 requesting all changes
107 107 adding changesets
108 108 adding manifests
109 109 adding file changes
110 110 added 21 changesets with 20 changes to 20 files
111 111 new changesets *:* (glob)
112 112 $ cd narrowroot
113 113 $ hg tracked
114 114 I path:.
115 115 X path:dir/tests
116 116 $ hg tracked
117 117 I path:.
118 118 X path:dir/tests
119 119 $ hg update
120 120 20 files updated, 0 files merged, 0 files removed, 0 files unresolved
121 121 $ find * | sort
122 122 dir
123 123 dir/src
124 124 dir/src/f1
125 125 dir/src/f10
126 126 dir/src/f11
127 127 dir/src/f12
128 128 dir/src/f13
129 129 dir/src/f14
130 130 dir/src/f15
131 131 dir/src/f16
132 132 dir/src/f17
133 133 dir/src/f18
134 134 dir/src/f19
135 135 dir/src/f2
136 136 dir/src/f20
137 137 dir/src/f3
138 138 dir/src/f4
139 139 dir/src/f5
140 140 dir/src/f6
141 141 dir/src/f7
142 142 dir/src/f8
143 143 dir/src/f9
144 144
145 145 $ cd ..
146 146
147 147 narrow clone no paths at all
148 148
149 149 $ hg clone --narrow ssh://user@dummy/master narrowempty --noupdate
150 150 requesting all changes
151 151 adding changesets
152 152 adding manifests
153 153 adding file changes
154 154 added 1 changesets with 0 changes to 0 files
155 155 new changesets * (glob)
156 156 $ cd narrowempty
157 157 $ hg tracked
158 158 $ hg update
159 159 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
160 160 $ ls
161 161
162 162 $ cd ..
163 163
164 164 simple clone
165 165 $ hg clone ssh://user@dummy/master simpleclone
166 166 requesting all changes
167 167 adding changesets
168 168 adding manifests
169 169 adding file changes
170 170 added 40 changesets with 40 changes to 40 files
171 171 new changesets * (glob)
172 172 updating to branch default
173 173 40 files updated, 0 files merged, 0 files removed, 0 files unresolved
174 174 $ cd simpleclone
175 175 $ find * | sort
176 176 dir
177 177 dir/src
178 178 dir/src/f1
179 179 dir/src/f10
180 180 dir/src/f11
181 181 dir/src/f12
182 182 dir/src/f13
183 183 dir/src/f14
184 184 dir/src/f15
185 185 dir/src/f16
186 186 dir/src/f17
187 187 dir/src/f18
188 188 dir/src/f19
189 189 dir/src/f2
190 190 dir/src/f20
191 191 dir/src/f3
192 192 dir/src/f4
193 193 dir/src/f5
194 194 dir/src/f6
195 195 dir/src/f7
196 196 dir/src/f8
197 197 dir/src/f9
198 198 dir/tests
199 199 dir/tests/t1
200 200 dir/tests/t10
201 201 dir/tests/t11
202 202 dir/tests/t12
203 203 dir/tests/t13
204 204 dir/tests/t14
205 205 dir/tests/t15
206 206 dir/tests/t16
207 207 dir/tests/t17
208 208 dir/tests/t18
209 209 dir/tests/t19
210 210 dir/tests/t2
211 211 dir/tests/t20
212 212 dir/tests/t3
213 213 dir/tests/t4
214 214 dir/tests/t5
215 215 dir/tests/t6
216 216 dir/tests/t7
217 217 dir/tests/t8
218 218 dir/tests/t9
219 219
220 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