##// END OF EJS Templates
transaction: allow generating file outside of store...
Pierre-Yves David -
r22663:4c619873 default
parent child Browse files
Show More
@@ -144,7 +144,7 b' class transaction(object):'
144 144 self.file.flush()
145 145
146 146 @active
147 def addbackup(self, file, hardlink=True):
147 def addbackup(self, file, hardlink=True, vfs=None):
148 148 """Adds a backup of the file to the transaction
149 149
150 150 Calling addbackup() creates a hardlink backup of the specified file
@@ -158,8 +158,10 b' class transaction(object):'
158 158 if file in self.map or file in self.backupmap:
159 159 return
160 160 backupfile = "%s.backup.%s" % (self.journal, file)
161 if self.opener.exists(file):
162 filepath = self.opener.join(file)
161 if vfs is None:
162 vfs = self.opener
163 if vfs.exists(file):
164 filepath = vfs.join(file)
163 165 backuppath = self.opener.join(backupfile)
164 166 util.copyfiles(filepath, backuppath, hardlink=hardlink)
165 167 else:
@@ -176,7 +178,7 b' class transaction(object):'
176 178 self.backupsfile.flush()
177 179
178 180 @active
179 def addfilegenerator(self, genid, filenames, genfunc, order=0):
181 def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None):
180 182 """add a function to generates some files at transaction commit
181 183
182 184 The `genfunc` argument is a function capable of generating proper
@@ -195,7 +197,10 b' class transaction(object):'
195 197 The `order` argument may be used to control the order in which multiple
196 198 generator will be executed.
197 199 """
198 self._filegenerators[genid] = (order, filenames, genfunc)
200 # For now, we are unable to do proper backup and restore of custom vfs
201 # but for bookmarks that are handled outside this mechanism.
202 assert vfs is None or filenames == ('bookmarks',)
203 self._filegenerators[genid] = (order, filenames, genfunc, vfs)
199 204
200 205 @active
201 206 def find(self, file):
@@ -239,16 +244,19 b' class transaction(object):'
239 244 def close(self):
240 245 '''commit the transaction'''
241 246 # write files registered for generation
242 for order, filenames, genfunc in sorted(self._filegenerators.values()):
247 for entry in sorted(self._filegenerators.values()):
248 order, filenames, genfunc, vfs = entry
249 if vfs is None:
250 vfs = self.opener
243 251 files = []
244 252 try:
245 253 for name in filenames:
246 254 # Some files are already backed up when creating the
247 255 # localrepo. Until this is properly fixed we disable the
248 256 # backup for them.
249 if name not in ('phaseroots',):
257 if name not in ('phaseroots', 'bookmarks'):
250 258 self.addbackup(name)
251 files.append(self.opener(name, 'w', atomictemp=True))
259 files.append(vfs(name, 'w', atomictemp=True))
252 260 genfunc(*files)
253 261 finally:
254 262 for f in files:
General Comments 0
You need to be logged in to leave comments. Login now