# HG changeset patch # User Martin von Zweigbergk # Date 2018-12-30 06:27:39 # Node ID b744810384384ac73a1cf2ed2452f40c8572edd3 # Parent 0f2b8d51bfdf143dcca3e6ab3cf9ddb5392af90f narrow: make dirstateguard back up and restore working copy narrowspec instead We used to have only one narrowspec for the store and the working copy, but now that we have one narrowspec for each, it seems clear that the dirstateguard was supposed to back up and restore the narrowspec associated with the working copy, not the one associated with the store. clearbackup() (for the store narrowspec) is not needed because the presence of the file in localrepository._journalfiles() takes care of that. Differential Revision: https://phab.mercurial-scm.org/D5504 diff --git a/mercurial/dirstateguard.py b/mercurial/dirstateguard.py --- a/mercurial/dirstateguard.py +++ b/mercurial/dirstateguard.py @@ -37,7 +37,7 @@ class dirstateguard(util.transactional): 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 @@ class dirstateguard(util.transactional): 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 diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py --- a/mercurial/narrowspec.py +++ b/mercurial/narrowspec.py @@ -185,10 +185,25 @@ def restorebackup(repo, backupname): 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,