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

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 14, 2014, 6:58 p.m.
Message ID <c2cab5ae84793c412e33.1415991502@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6735/
State Accepted
Commit 66275ecc73c1a744319eda29277e7ceec462bd87
Headers show

Comments

Pierre-Yves David - Nov. 14, 2014, 6:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.
Matt Mackall - Nov. 14, 2014, 9:43 p.m.
On Fri, 2014-11-14 at 18:58 +0000, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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)

vfs.join??

Patch

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)