Patchwork D5634: narrow: fix crash when restoring backup in legacy repo

login
register
mail settings
Submitter phabricator
Date Jan. 19, 2019, 11:39 a.m.
Message ID <23236f60dd8b4721d0d671f203482df6@localhost.localdomain>
Download mbox | patch
Permalink /patch/37885/
State Not Applicable
Headers show

Comments

phabricator - Jan. 19, 2019, 11:39 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG88a7c211b21e: narrow: fix crash when restoring backup in legacy repo (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5634?vs=13327&id=13328

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

AFFECTED FILES
  mercurial/narrowspec.py
  tests/test-narrow-share.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-narrow-share.t b/tests/test-narrow-share.t
--- a/tests/test-narrow-share.t
+++ b/tests/test-narrow-share.t
@@ -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]
diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -190,12 +190,14 @@ 
 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
-    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,