[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 17:31:20 CST 2014



On 11/14/2014 09:43 PM, Matt Mackall wrote:
> On Fri, 2014-11-14 at 18:58 +0000, Pierre-Yves David wrote:
>> # 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)
>
> vfs.join??

(I'm confused about your quoting range.)

The code around there is responsible for one things: building the name 
of the backup file:

   "bookmarks" → "journal.backups.bookmarks"

The patch here is making this code handle directory properly.

   old-code: "cache/hidden" → "journal.backups.cache/hidden" (crash of 
missing directory

   new-code: "cache/hidden" → "cache/journal.backup.cache" (happy panda)


To achieve this result, we need to:

(1) detach the filename part from the directory part
(2) add the backup prefix to the filename part
(3) re-attach the directory name

Nothing in the vfs help do to so. And as we never do any file system 
access in the process, using a vfs is not necessary.

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list