[PATCH 3 of 5 main-line-of-work] addbackup: add cache support
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Wed Nov 19 21:30:29 CST 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1415877482 0
# Thu Nov 13 11:18:02 2014 +0000
# Node ID 2968a06bb0f4ba98e81dfd561444cab20a9af683
# Parent bb387f9638d0ee5321f2ea85f8cd2bd745ac5243
addbackup: add cache support
One can now marks a backup as "cache" failure to back it up or to restore it
will be ignored.
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -186,11 +186,11 @@ class transaction(object):
# add enough data to the journal to do the truncate
self.file.write("%s\0%d\n" % (file, offset))
self.file.flush()
@active
- def addbackup(self, file, hardlink=True, location=''):
+ def addbackup(self, file, hardlink=True, location='', cache=False):
"""Adds a backup of the file to the transaction
Calling addbackup() creates a hardlink backup of the specified file
that is used to recover the file in the event of the transaction
aborting.
@@ -205,19 +205,23 @@ class transaction(object):
if file in self.map or file in self._backupmap:
return
dirname, filename = os.path.split(file)
backupfilename = "%s.backup.%s" % (self.journal, filename)
backupfile = os.path.join(dirname, backupfilename)
+ if location not in self._vfsmap and cache:
+ self.report("couldn't backup %s: unknown cache location %s\n"
+ % (file, location))
+ return
vfs = self._vfsmap[location]
if vfs.exists(file):
filepath = vfs.join(file)
backuppath = vfs.join(backupfile)
util.copyfiles(filepath, backuppath, hardlink=hardlink)
else:
backupfile = ''
- self._addbackupentry((location, file, backupfile, False))
+ self._addbackupentry((location, file, backupfile, cache))
def _addbackupentry(self, entry):
"""register a new backup entry and write it to disk"""
self._backupentries.append(entry)
self._backupmap[file] = len(self._backupentries) - 1
More information about the Mercurial-devel
mailing list