##// END OF EJS Templates
transaction: change the on disk format for backupentries...
Pierre-Yves David -
r23309:7eb520f5 default
parent child Browse files
Show More
@@ -15,7 +15,7 b' from i18n import _'
15 import errno
15 import errno
16 import error, util
16 import error, util
17
17
18 version = 1
18 version = 0
19
19
20 def active(func):
20 def active(func):
21 def _active(self, *args, **kwds):
21 def _active(self, *args, **kwds):
@@ -43,7 +43,7 b' def _playback(journal, report, opener, e'
43 raise
43 raise
44
44
45 backupfiles = []
45 backupfiles = []
46 for f, b in backupentries:
46 for l, f, b, c in backupentries:
47 if f and b:
47 if f and b:
48 filepath = opener.join(f)
48 filepath = opener.join(f)
49 backuppath = opener.join(b)
49 backuppath = opener.join(b)
@@ -99,9 +99,10 b' class transaction(object):'
99 self.hookargs = {}
99 self.hookargs = {}
100 self.file = opener.open(self.journal, "w")
100 self.file = opener.open(self.journal, "w")
101
101
102 # a list of ('path', 'backuppath') entries.
102 # a list of ('location', 'path', 'backuppath', cache) entries.
103 # if 'backuppath' is empty, no file existed at backup time
103 # if 'backuppath' is empty, no file existed at backup time
104 # if 'path' is empty, this is a temporary transaction file
104 # if 'path' is empty, this is a temporary transaction file
105 # (location, and cache are current unused)
105 self._backupentries = []
106 self._backupentries = []
106 self._backupmap = {}
107 self._backupmap = {}
107 self._backupjournal = "%s.backupfiles" % journal
108 self._backupjournal = "%s.backupfiles" % journal
@@ -193,13 +194,13 b' class transaction(object):'
193 else:
194 else:
194 backupfile = ''
195 backupfile = ''
195
196
196 self._addbackupentry((file, backupfile))
197 self._addbackupentry(('', file, backupfile, False))
197
198
198 def _addbackupentry(self, entry):
199 def _addbackupentry(self, entry):
199 """register a new backup entry and write it to disk"""
200 """register a new backup entry and write it to disk"""
200 self._backupentries.append(entry)
201 self._backupentries.append(entry)
201 self._backupmap[file] = len(self._backupentries) - 1
202 self._backupmap[file] = len(self._backupentries) - 1
202 self._backupsfile.write("%s\0%s\n" % entry)
203 self._backupsfile.write("%s\0%s\0%s\0%d\n" % entry)
203 self._backupsfile.flush()
204 self._backupsfile.flush()
204
205
205 @active
206 @active
@@ -209,7 +210,7 b' class transaction(object):'
209 Such file will be delete when the transaction exit (on both failure and
210 Such file will be delete when the transaction exit (on both failure and
210 success).
211 success).
211 """
212 """
212 self._addbackupentry(('', tmpfile))
213 self._addbackupentry(('', '', tmpfile, False))
213
214
214 @active
215 @active
215 def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None):
216 def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None):
@@ -355,7 +356,7 b' class transaction(object):'
355 self.file.close()
356 self.file.close()
356 self._backupsfile.close()
357 self._backupsfile.close()
357 # cleanup temporary files
358 # cleanup temporary files
358 for f, b in self._backupentries:
359 for _l, f, b, _c in self._backupentries:
359 if not f and b and self.opener.exists(b):
360 if not f and b and self.opener.exists(b):
360 self.opener.unlink(b)
361 self.opener.unlink(b)
361 self.entries = []
362 self.entries = []
@@ -365,7 +366,7 b' class transaction(object):'
365 self.opener.unlink(self.journal)
366 self.opener.unlink(self.journal)
366 if self.opener.isfile(self._backupjournal):
367 if self.opener.isfile(self._backupjournal):
367 self.opener.unlink(self._backupjournal)
368 self.opener.unlink(self._backupjournal)
368 for _f, b in self._backupentries:
369 for _l, _f, b, _c in self._backupentries:
369 if b and self.opener.exists(b):
370 if b and self.opener.exists(b):
370 self.opener.unlink(b)
371 self.opener.unlink(b)
371 self._backupentries = []
372 self._backupentries = []
@@ -447,10 +448,10 b' def rollback(opener, file, report):'
447 if line:
448 if line:
448 # Shave off the trailing newline
449 # Shave off the trailing newline
449 line = line[:-1]
450 line = line[:-1]
450 f, b = line.split('\0')
451 l, f, b, c = line.split('\0')
451 backupentries.append((f, b))
452 backupentries.append((l, f, b, bool(c)))
452 else:
453 else:
453 report(_("journal was created by a newer version of "
454 report(_("journal was created by a different version of "
454 "Mercurial"))
455 "Mercurial"))
455
456
456 _playback(file, report, opener, entries, backupentries)
457 _playback(file, report, opener, entries, backupentries)
General Comments 0
You need to be logged in to leave comments. Login now