comparison hgext/narrow/narrowcommands.py @ 41043:ce0bc2952e2a

narrow: detect if narrowspec was changed in a different share With this commit, `hg share` should be usable with narrow repos. Design explained on https://www.mercurial-scm.org/wiki/NarrowSharePlan I was running into cache invalidation problems when updating the narrowspec. After spending a day trying to figure out a good solution, I resorted to just assigning repo.narrowpats and repo._narrowmatch after invalidating them. Differential Revision: https://phab.mercurial-scm.org/D5278
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 21 Dec 2018 10:13:49 -0800
parents 54c3b4bd01f2
children 8ecb17b7f432
comparison
equal deleted inserted replaced
41042:7db1619af061 41043:ce0bc2952e2a
337 ('', 'import-rules', '', _('import narrowspecs from a file')), 337 ('', 'import-rules', '', _('import narrowspecs from a file')),
338 ('', 'removeexclude', [], _('old paths to no longer exclude')), 338 ('', 'removeexclude', [], _('old paths to no longer exclude')),
339 ('', 'clear', False, _('whether to replace the existing narrowspec')), 339 ('', 'clear', False, _('whether to replace the existing narrowspec')),
340 ('', 'force-delete-local-changes', False, 340 ('', 'force-delete-local-changes', False,
341 _('forces deletion of local changes when narrowing')), 341 _('forces deletion of local changes when narrowing')),
342 ('', 'update-working-copy', False,
343 _('update working copy when the store has changed')),
342 ] + commands.remoteopts, 344 ] + commands.remoteopts,
343 _('[OPTIONS]... [REMOTE]'), 345 _('[OPTIONS]... [REMOTE]'),
344 inferrepo=True) 346 inferrepo=True)
345 def trackedcmd(ui, repo, remotepath=None, *pats, **opts): 347 def trackedcmd(ui, repo, remotepath=None, *pats, **opts):
346 """show or change the current narrowspec 348 """show or change the current narrowspec
396 addedincludes = narrowspec.parsepatterns(opts['addinclude']) 398 addedincludes = narrowspec.parsepatterns(opts['addinclude'])
397 removedincludes = narrowspec.parsepatterns(opts['removeinclude']) 399 removedincludes = narrowspec.parsepatterns(opts['removeinclude'])
398 addedexcludes = narrowspec.parsepatterns(opts['addexclude']) 400 addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
399 removedexcludes = narrowspec.parsepatterns(opts['removeexclude']) 401 removedexcludes = narrowspec.parsepatterns(opts['removeexclude'])
400 402
403 update_working_copy = opts['update_working_copy']
401 only_show = not (addedincludes or removedincludes or addedexcludes or 404 only_show = not (addedincludes or removedincludes or addedexcludes or
402 removedexcludes or newrules) 405 removedexcludes or newrules or update_working_copy)
403 406
404 oldincludes, oldexcludes = repo.narrowpats 407 oldincludes, oldexcludes = repo.narrowpats
405 408
406 # filter the user passed additions and deletions into actual additions and 409 # filter the user passed additions and deletions into actual additions and
407 # deletions of excludes and includes 410 # deletions of excludes and includes
426 fm.write('status', '%s ', 'X', label='narrow.excluded') 429 fm.write('status', '%s ', 'X', label='narrow.excluded')
427 fm.write('pat', '%s\n', i, label='narrow.excluded') 430 fm.write('pat', '%s\n', i, label='narrow.excluded')
428 fm.end() 431 fm.end()
429 return 0 432 return 0
430 433
434 if update_working_copy:
435 with repo.wlock(), repo.lock(), repo.transaction('narrow-wc') as tr:
436 narrowspec.updateworkingcopy(repo, tr)
437 narrowspec.copytoworkingcopy(repo, tr)
438 return 0
439
431 if not widening and not narrowing: 440 if not widening and not narrowing:
432 ui.status(_("nothing to widen or narrow\n")) 441 ui.status(_("nothing to widen or narrow\n"))
433 return 0 442 return 0
434 443
435 with repo.wlock(), repo.lock(): 444 with repo.wlock(), repo.lock():