Patchwork D5504: narrow: make dirstateguard back up and restore working copy narrowspec instead

login
register
mail settings
Submitter phabricator
Date Jan. 10, 2019, 9:50 p.m.
Message ID <be5d2bc79b2fc6854f5fb0b9fe316fe0@localhost.localdomain>
Download mbox | patch
Permalink /patch/37630/
State Not Applicable
Headers show

Comments

phabricator - Jan. 10, 2019, 9:50 p.m.
martinvonz updated this revision to Diff 13144.
martinvonz edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5504?vs=13053&id=13144

REVISION DETAIL
  https://phab.mercurial-scm.org/D5504

AFFECTED FILES
  mercurial/dirstateguard.py
  mercurial/narrowspec.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: pulkit, mercurial-devel

Patch

diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -185,10 +185,25 @@ 
         return
     util.rename(repo.svfs.join(backupname), repo.svfs.join(FILENAME))
 
-def clearbackup(repo, backupname):
+def savewcbackup(repo, backupname):
     if repository.NARROW_REQUIREMENT not in repo.requirements:
         return
-    repo.svfs.unlink(backupname)
+    vfs = repo.vfs
+    vfs.tryunlink(backupname)
+    # It may not exist in old repos
+    if vfs.exists(DIRSTATE_FILENAME):
+        util.copyfile(vfs.join(DIRSTATE_FILENAME), vfs.join(backupname),
+                      hardlink=True)
+
+def restorewcbackup(repo, backupname):
+    if repository.NARROW_REQUIREMENT not in repo.requirements:
+        return
+    util.rename(repo.vfs.join(backupname), repo.vfs.join(DIRSTATE_FILENAME))
+
+def clearwcbackup(repo, backupname):
+    if repository.NARROW_REQUIREMENT not in repo.requirements:
+        return
+    repo.vfs.unlink(backupname)
 
 def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes):
     r""" Restricts the patterns according to repo settings,
diff --git a/mercurial/dirstateguard.py b/mercurial/dirstateguard.py
--- a/mercurial/dirstateguard.py
+++ b/mercurial/dirstateguard.py
@@ -37,7 +37,7 @@ 
         self._narrowspecbackupname = ('narrowspec.backup.%s.%d' %
                                       (name, id(self)))
         repo.dirstate.savebackup(repo.currenttransaction(), self._backupname)
-        narrowspec.savebackup(repo, self._narrowspecbackupname)
+        narrowspec.savewcbackup(repo, self._narrowspecbackupname)
         self._active = True
 
     def __del__(self):
@@ -56,12 +56,12 @@ 
 
         self._repo.dirstate.clearbackup(self._repo.currenttransaction(),
                                          self._backupname)
-        narrowspec.clearbackup(self._repo, self._narrowspecbackupname)
+        narrowspec.clearwcbackup(self._repo, self._narrowspecbackupname)
         self._active = False
         self._closed = True
 
     def _abort(self):
-        narrowspec.restorebackup(self._repo, self._narrowspecbackupname)
+        narrowspec.restorewcbackup(self._repo, self._narrowspecbackupname)
         self._repo.dirstate.restorebackup(self._repo.currenttransaction(),
                                            self._backupname)
         self._active = False