Mercurial > hg
comparison mercurial/dirstate.py @ 34940:c2b30348930f stable
dirstate: clean up when restoring identical backups
When a dirstate backup is restored, it is possible that no actual changes to
the dirstate have been made. In this case, the backup is still a hardlink
to the original dirstate.
Unfortunately, `os.rename` silently fails (nothing happens, and no error
occurs) when `src` and `dst` are hardlinks to the same file. As a result,
the backup is left lying around. Over time, these files accumulate.
When restoring dirstate backups, check if the backup and the dirstate are
the same file, and if so, just delete the backup.
Differential Revision: https://phab.mercurial-scm.org/D1201
author | Mark Thomas <mbthomas@fb.com> |
---|---|
date | Fri, 20 Oct 2017 05:53:35 -0700 |
parents | ffeea2406276 |
children | ecede5263adb |
comparison
equal
deleted
inserted
replaced
34939:2c80a864e83e | 34940:c2b30348930f |
---|---|
1185 '''Restore dirstate by backup file''' | 1185 '''Restore dirstate by backup file''' |
1186 # this "invalidate()" prevents "wlock.release()" from writing | 1186 # this "invalidate()" prevents "wlock.release()" from writing |
1187 # changes of dirstate out after restoring from backup file | 1187 # changes of dirstate out after restoring from backup file |
1188 self.invalidate() | 1188 self.invalidate() |
1189 filename = self._actualfilename(tr) | 1189 filename = self._actualfilename(tr) |
1190 self._opener.rename(backupname, filename, checkambig=True) | 1190 o = self._opener |
1191 if util.samefile(o.join(backupname), o.join(filename)): | |
1192 o.unlink(backupname) | |
1193 else: | |
1194 o.rename(backupname, filename, checkambig=True) | |
1191 | 1195 |
1192 def clearbackup(self, tr, backupname): | 1196 def clearbackup(self, tr, backupname): |
1193 '''Clear backup file''' | 1197 '''Clear backup file''' |
1194 self._opener.unlink(backupname) | 1198 self._opener.unlink(backupname) |
1195 | 1199 |