diff 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
line wrap: on
line diff
--- a/hgext/narrow/narrowcommands.py	Fri Jul 13 11:26:46 2018 -0700
+++ b/hgext/narrow/narrowcommands.py	Fri Dec 21 10:13:49 2018 -0800
@@ -339,6 +339,8 @@
      ('', 'clear', False, _('whether to replace the existing narrowspec')),
      ('', 'force-delete-local-changes', False,
        _('forces deletion of local changes when narrowing')),
+     ('', 'update-working-copy', False,
+      _('update working copy when the store has changed')),
     ] + commands.remoteopts,
     _('[OPTIONS]... [REMOTE]'),
     inferrepo=True)
@@ -398,8 +400,9 @@
     addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
     removedexcludes = narrowspec.parsepatterns(opts['removeexclude'])
 
+    update_working_copy = opts['update_working_copy']
     only_show = not (addedincludes or removedincludes or addedexcludes or
-                     removedexcludes or newrules)
+                     removedexcludes or newrules or update_working_copy)
 
     oldincludes, oldexcludes = repo.narrowpats
 
@@ -428,6 +431,12 @@
         fm.end()
         return 0
 
+    if update_working_copy:
+        with repo.wlock(), repo.lock(), repo.transaction('narrow-wc') as tr:
+            narrowspec.updateworkingcopy(repo, tr)
+            narrowspec.copytoworkingcopy(repo, tr)
+        return 0
+
     if not widening and not narrowing:
         ui.status(_("nothing to widen or narrow\n"))
         return 0