comparison mercurial/narrowspec.py @ 41298:88a7c211b21e stable

narrow: fix crash when restoring backup in legacy repo Using --addremove when committing in an old repo (before we started keeping .hg/narrowspec.dirstate) results in a crash. The test case modified in this patch would crash like this: abort: $ENOENT$ The issue is that when the dirstateguard is aborted, it tries to restore the backup of .hg/narrowspec.dirstate. However, since we were in an old repo, that file did not get created when the dirstateguard was created. Note that the dirstateguard is not used unless --addremove is passed. This patch fixes the bug by making restorewcbackup() not fail if the backup doesn't exist. I also made clearwcbackup() safe, just in case. Differential Revision: https://phab.mercurial-scm.org/D5634
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 18 Jan 2019 23:32:26 -0800
parents 8c366af085f4
children 0531dff73d0b
comparison
equal deleted inserted replaced
41297:b1ea90613af3 41298:88a7c211b21e
188 hardlink=True) 188 hardlink=True)
189 189
190 def restorewcbackup(repo, backupname): 190 def restorewcbackup(repo, backupname):
191 if repository.NARROW_REQUIREMENT not in repo.requirements: 191 if repository.NARROW_REQUIREMENT not in repo.requirements:
192 return 192 return
193 util.rename(repo.vfs.join(backupname), repo.vfs.join(DIRSTATE_FILENAME)) 193 # It may not exist in old repos
194 if repo.vfs.exists(backupname):
195 util.rename(repo.vfs.join(backupname), repo.vfs.join(DIRSTATE_FILENAME))
194 196
195 def clearwcbackup(repo, backupname): 197 def clearwcbackup(repo, backupname):
196 if repository.NARROW_REQUIREMENT not in repo.requirements: 198 if repository.NARROW_REQUIREMENT not in repo.requirements:
197 return 199 return
198 repo.vfs.unlink(backupname) 200 repo.vfs.tryunlink(backupname)
199 201
200 def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes): 202 def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes):
201 r""" Restricts the patterns according to repo settings, 203 r""" Restricts the patterns according to repo settings,
202 results in a logical AND operation 204 results in a logical AND operation
203 205