[PATCH 2 of 5 main-line-of-work (12 more to go)] addbackup: handle file in subdirectory

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Nov 14 12:58:22 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1415924063 0
#      Fri Nov 14 00:14:23 2014 +0000
# Node ID c2cab5ae84793c412e33db75ce41c030a4f5cedc
# Parent  ff306c25475d36509de0d0ab8802a9b7d5967d87
addbackup: handle file in subdirectory

The current naming scheme ('journal.backups.<file>') resulted is bad directory
name when 'file' was in a subdirectory. We now extract the directory name and
create the backupfile within it.

We plan to use file in a subdirectory for cachefile.

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -10,10 +10,11 @@
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
+import os
 import errno
 import error, util
 
 version = 2
 
@@ -201,11 +202,14 @@ class transaction(object):
             msg = 'cannot use transaction.addbackup inside "group"'
             raise RuntimeError(msg)
 
         if file in self.map or file in self._backupmap:
             return
-        backupfile = "%s.backup.%s" % (self.journal, file)
+        dirname, filename = os.path.split(file)
+
+        backupfilename = "%s.backup.%s" % (self.journal, filename)
+        backupfile = os.path.join(dirname, backupfilename)
         if vfs is None:
             vfs = self.opener
         if vfs.exists(file):
             filepath = vfs.join(file)
             backuppath = vfs.join(backupfile)


More information about the Mercurial-devel mailing list