narrow: when narrowing, write new narrowspec before removing revlogs
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 05 Dec 2018 15:30:56 -0800
changeset 41028 095a0a63ad88
parent 41027 74e023f5a922
child 41029 b2de94e59702
narrow: when narrowing, write new narrowspec before removing revlogs If revlogs were removed and then the process crashed before the narrowspec was written, the repo would be corrupt. Differential Revision: https://phab.mercurial-scm.org/D5467
hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py	Fri Nov 23 22:12:04 2018 -0800
+++ b/hgext/narrow/narrowcommands.py	Wed Dec 05 15:30:56 2018 -0800
@@ -242,6 +242,10 @@
         repo.destroying()
 
         with repo.transaction("narrowing"):
+            # Update narrowspec before removing revlogs, so repo won't be
+            # corrupt in case of crash
+            repo.setnarrowpats(newincludes, newexcludes)
+
             for f in todelete:
                 ui.status(_('deleting %s\n') % f)
                 util.unlinkpath(repo.svfs.join(f))
@@ -249,7 +253,6 @@
 
             _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes,
                                newexcludes, oldmatch, newmatch)
-            repo.setnarrowpats(newincludes, newexcludes)
 
         repo.destroyed()