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