dirstate: remove the dedicated backup logic
When alone, the dirstate can now take care of its commit/rollback pattern
itself.
When in a transaction, the transaction deal with commit/rollback pattern quite
fine.
Why did you have a dedicated backup logic?
--- a/hgext/git/dirstate.py Thu Feb 16 04:02:36 2023 +0100
+++ b/hgext/git/dirstate.py Thu Feb 16 04:49:35 2023 +0100
@@ -327,14 +327,6 @@
r[path] = s
return r
- def savebackup(self, tr, backupname):
- # TODO: figure out a strategy for saving index backups.
- pass
-
- def restorebackup(self, tr, backupname):
- # TODO: figure out a strategy for saving index backups.
- pass
-
def set_tracked(self, f, reset_copy=False):
# TODO: support copies and reset_copy=True
uf = pycompat.fsdecode(f)
@@ -397,10 +389,6 @@
# TODO: should this be added to the dirstate interface?
self._plchangecallbacks[category] = callback
- def clearbackup(self, tr, backupname):
- # TODO
- pass
-
def setbranch(self, branch):
raise error.Abort(
b'git repos do not support branches. try using bookmarks'
--- a/mercurial/dirstate.py Thu Feb 16 04:02:36 2023 +0100
+++ b/mercurial/dirstate.py Thu Feb 16 04:49:35 2023 +0100
@@ -31,7 +31,6 @@
)
from .dirstateutils import (
- docket as docketmod,
timestamp,
)
@@ -1631,123 +1630,6 @@
else:
return (self._filename,)
- def data_backup_filename(self, backupname):
- if not self._use_dirstate_v2:
- return None
- return backupname + b'.v2-data'
-
- def _new_backup_data_filename(self, backupname):
- """return a filename to backup a data-file or None"""
- if not self._use_dirstate_v2:
- return None
- if self._map.docket.uuid is None:
- # not created yet, nothing to backup
- return None
- data_filename = self._map.docket.data_filename()
- return data_filename, self.data_backup_filename(backupname)
-
- def backup_data_file(self, backupname):
- if not self._use_dirstate_v2:
- return None
- docket = docketmod.DirstateDocket.parse(
- self._opener.read(backupname),
- self._nodeconstants,
- )
- return self.data_backup_filename(backupname), docket.data_filename()
-
- def savebackup(self, tr, backupname):
- '''Save current dirstate into backup file'''
- filename = self._actualfilename(tr)
- assert backupname != filename
-
- # use '_writedirstate' instead of 'write' to write changes certainly,
- # because the latter omits writing out if transaction is running.
- # output file will be used to create backup of dirstate at this point.
- if self._dirty:
- self._writedirstate(
- tr,
- self._opener(filename, b"w", atomictemp=True, checkambig=True),
- )
-
- if tr:
- # ensure that subsequent tr.writepending returns True for
- # changes written out above, even if dirstate is never
- # changed after this
- tr.addfilegenerator(
- b'dirstate-1-main',
- (self._filename,),
- lambda f: self._writedirstate(tr, f),
- location=b'plain',
- post_finalize=True,
- )
-
- self._opener.tryunlink(backupname)
- if self._opener.exists(filename):
- # hardlink backup is okay because _writedirstate is always called
- # with an "atomictemp=True" file.
- util.copyfile(
- self._opener.join(filename),
- self._opener.join(backupname),
- hardlink=True,
- )
- data_pair = self._new_backup_data_filename(backupname)
- if data_pair is not None:
- data_filename, bck_data_filename = data_pair
- util.copyfile(
- self._opener.join(data_filename),
- self._opener.join(bck_data_filename),
- hardlink=True,
- )
- if tr is not None:
- # ensure that pending file written above is unlinked at
- # failure, even if tr.writepending isn't invoked until the
- # end of this transaction
- tr.registertmp(bck_data_filename, location=b'plain')
-
- def restorebackup(self, tr, backupname):
- '''Restore dirstate by backup file'''
- # this "invalidate()" prevents "wlock.release()" from writing
- # changes of dirstate out after restoring from backup file
- self.invalidate()
- o = self._opener
- if not o.exists(backupname):
- # there was no file backup, delete existing files
- filename = self._actualfilename(tr)
- data_file = None
- if self._use_dirstate_v2 and self._map.docket.uuid is not None:
- data_file = self._map.docket.data_filename()
- if o.exists(filename):
- o.unlink(filename)
- if data_file is not None and o.exists(data_file):
- o.unlink(data_file)
- return
- filename = self._actualfilename(tr)
- data_pair = self.backup_data_file(backupname)
- if o.exists(filename) and util.samefile(
- o.join(backupname), o.join(filename)
- ):
- o.unlink(backupname)
- else:
- o.rename(backupname, filename, checkambig=True)
-
- if data_pair is not None:
- data_backup, target = data_pair
- if o.exists(target) and util.samefile(
- o.join(data_backup), o.join(target)
- ):
- o.unlink(data_backup)
- else:
- o.rename(data_backup, target, checkambig=True)
-
- def clearbackup(self, tr, backupname):
- '''Clear backup file'''
- o = self._opener
- if o.exists(backupname):
- data_backup = self.backup_data_file(backupname)
- o.unlink(backupname)
- if data_backup is not None:
- o.unlink(data_backup[0])
-
def verify(self, m1, m2, p1, narrow_matcher=None):
"""
check the dirstate contents against the parent manifest and yield errors
--- a/mercurial/interfaces/dirstate.py Thu Feb 16 04:02:36 2023 +0100
+++ b/mercurial/interfaces/dirstate.py Thu Feb 16 04:49:35 2023 +0100
@@ -220,15 +220,6 @@
return files in the dirstate (in whatever state) filtered by match
"""
- def savebackup(tr, backupname):
- '''Save current dirstate into backup file'''
-
- def restorebackup(tr, backupname):
- '''Restore dirstate by backup file'''
-
- def clearbackup(tr, backupname):
- '''Clear backup file'''
-
def verify(m1, m2, p1, narrow_matcher=None):
"""
check the dirstate contents against the parent manifest and yield errors