Skip to content
Snippets Groups Projects
Commit 88a7c211 authored by Martin von Zweigbergk's avatar Martin von Zweigbergk
Browse files

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
parent b1ea9061
No related branches found
No related tags found
No related merge requests found
......@@ -190,8 +190,10 @@
def restorewcbackup(repo, backupname):
if repository.NARROW_REQUIREMENT not in repo.requirements:
return
util.rename(repo.vfs.join(backupname), repo.vfs.join(DIRSTATE_FILENAME))
# It may not exist in old repos
if repo.vfs.exists(backupname):
util.rename(repo.vfs.join(backupname), repo.vfs.join(DIRSTATE_FILENAME))
def clearwcbackup(repo, backupname):
if repository.NARROW_REQUIREMENT not in repo.requirements:
return
......@@ -194,8 +196,8 @@
def clearwcbackup(repo, backupname):
if repository.NARROW_REQUIREMENT not in repo.requirements:
return
repo.vfs.unlink(backupname)
repo.vfs.tryunlink(backupname)
def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes):
r""" Restricts the patterns according to repo settings,
......
......@@ -166,7 +166,7 @@
R d7/f
Make it look like a repo from before narrow+share was supported
$ rm .hg/narrowspec.dirstate
$ hg st
$ hg ci -Am test
abort: working copy's narrowspec is stale
(run 'hg tracked --update-working-copy')
[255]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment