Patchwork D1201: dirstate: clean up when restoring identical backups

login
register
mail settings
Submitter phabricator
Date Oct. 30, 2017, 9:30 p.m.
Message ID <e078312212b8cb41e384998efb55972d@localhost.localdomain>
Download mbox | patch
Permalink /patch/25309/
State Not Applicable
Headers show

Comments

phabricator - Oct. 30, 2017, 9:30 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGc2b30348930f: dirstate: clean up when restoring identical backups (authored by mbthomas, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1201?vs=3048&id=3159

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

AFFECTED FILES
  mercurial/dirstate.py
  tests/test-dirstate-backup.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-dirstate-backup.t b/tests/test-dirstate-backup.t
--- a/tests/test-dirstate-backup.t
+++ b/tests/test-dirstate-backup.t
@@ -11,9 +11,8 @@ 
   abort: stdin: no diffs found
   [255]
 
-A dirstate backup is left behind
+No dirstate backups are left behind
 
   $ ls .hg/dirstate* | sort
   .hg/dirstate
-  .hg/dirstate.backup.import.* (glob)
 
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1187,7 +1187,11 @@ 
         # changes of dirstate out after restoring from backup file
         self.invalidate()
         filename = self._actualfilename(tr)
-        self._opener.rename(backupname, filename, checkambig=True)
+        o = self._opener
+        if util.samefile(o.join(backupname), o.join(filename)):
+            o.unlink(backupname)
+        else:
+            o.rename(backupname, filename, checkambig=True)
 
     def clearbackup(self, tr, backupname):
         '''Clear backup file'''