Patchwork [3,of,5,main-line-of-work] addbackup: add cache support

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 20, 2014, 3:30 a.m.
Message ID <2968a06bb0f4ba98e81d.1416454229@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6802/
State Changes Requested
Headers show

Comments

Pierre-Yves David - Nov. 20, 2014, 3:30 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.
Matt Mackall - Nov. 22, 2014, 1:16 a.m.
On Wed, 2014-11-19 at 19:30 -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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.

Probably needs a docstring addition.

> @@ -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

This doesn't seem to agree with the summary?

Patch

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