##// END OF EJS Templates
transaction: change list of journal entries into a dictionary...
Joerg Sonnenberger -
r46483:a985c4fb default
parent child Browse files
Show More
@@ -209,7 +209,7 b' def strip(ui, repo, nodelist, backup=Tru'
209 # transaction and makes assumptions that file storage is
209 # transaction and makes assumptions that file storage is
210 # using append-only files. We'll need some kind of storage
210 # using append-only files. We'll need some kind of storage
211 # API to handle stripping for us.
211 # API to handle stripping for us.
212 offset = len(tr._entries)
212 oldfiles = set(tr._offsetmap.keys())
213
213
214 tr.startgroup()
214 tr.startgroup()
215 cl.strip(striprev, tr)
215 cl.strip(striprev, tr)
@@ -219,8 +219,11 b' def strip(ui, repo, nodelist, backup=Tru'
219 repo.file(fn).strip(striprev, tr)
219 repo.file(fn).strip(striprev, tr)
220 tr.endgroup()
220 tr.endgroup()
221
221
222 for i in pycompat.xrange(offset, len(tr._entries)):
222 entries = tr.readjournal()
223 file, troffset = tr._entries[i]
223
224 for file, troffset in entries:
225 if file in oldfiles:
226 continue
224 with repo.svfs(file, b'a', checkambig=True) as fp:
227 with repo.svfs(file, b'a', checkambig=True) as fp:
225 fp.truncate(troffset)
228 fp.truncate(troffset)
226 if troffset == 0:
229 if troffset == 0:
@@ -158,8 +158,7 b' class transaction(util.transactional):'
158 vfsmap[b''] = opener # set default value
158 vfsmap[b''] = opener # set default value
159 self._vfsmap = vfsmap
159 self._vfsmap = vfsmap
160 self._after = after
160 self._after = after
161 self._entries = []
161 self._offsetmap = {}
162 self._map = {}
163 self._journal = journalname
162 self._journal = journalname
164 self._undoname = undoname
163 self._undoname = undoname
165 self._queue = []
164 self._queue = []
@@ -180,7 +179,7 b' class transaction(util.transactional):'
180
179
181 # a dict of arguments to be passed to hooks
180 # a dict of arguments to be passed to hooks
182 self.hookargs = {}
181 self.hookargs = {}
183 self._file = opener.open(self._journal, b"w")
182 self._file = opener.open(self._journal, b"w+")
184
183
185 # a list of ('location', 'path', 'backuppath', cache) entries.
184 # a list of ('location', 'path', 'backuppath', cache) entries.
186 # - if 'backuppath' is empty, no file existed at backup time
185 # - if 'backuppath' is empty, no file existed at backup time
@@ -249,7 +248,7 b' class transaction(util.transactional):'
249 @active
248 @active
250 def add(self, file, offset):
249 def add(self, file, offset):
251 """record the state of an append-only file before update"""
250 """record the state of an append-only file before update"""
252 if file in self._map or file in self._backupmap:
251 if file in self._offsetmap or file in self._backupmap:
253 return
252 return
254 if self._queue:
253 if self._queue:
255 self._queue[-1].append((file, offset))
254 self._queue[-1].append((file, offset))
@@ -259,10 +258,9 b' class transaction(util.transactional):'
259
258
260 def _addentry(self, file, offset):
259 def _addentry(self, file, offset):
261 """add a append-only entry to memory and on-disk state"""
260 """add a append-only entry to memory and on-disk state"""
262 if file in self._map or file in self._backupmap:
261 if file in self._offsetmap or file in self._backupmap:
263 return
262 return
264 self._entries.append((file, offset))
263 self._offsetmap[file] = offset
265 self._map[file] = len(self._entries) - 1
266 # add enough data to the journal to do the truncate
264 # add enough data to the journal to do the truncate
267 self._file.write(b"%s\0%d\n" % (file, offset))
265 self._file.write(b"%s\0%d\n" % (file, offset))
268 self._file.flush()
266 self._file.flush()
@@ -282,7 +280,7 b' class transaction(util.transactional):'
282 msg = b'cannot use transaction.addbackup inside "group"'
280 msg = b'cannot use transaction.addbackup inside "group"'
283 raise error.ProgrammingError(msg)
281 raise error.ProgrammingError(msg)
284
282
285 if file in self._map or file in self._backupmap:
283 if file in self._offsetmap or file in self._backupmap:
286 return
284 return
287 vfs = self._vfsmap[location]
285 vfs = self._vfsmap[location]
288 dirname, filename = vfs.split(file)
286 dirname, filename = vfs.split(file)
@@ -396,9 +394,16 b' class transaction(util.transactional):'
396
394
397 @active
395 @active
398 def findoffset(self, file):
396 def findoffset(self, file):
399 if file in self._map:
397 return self._offsetmap.get(file)
400 return self._entries[self._map[file]][1]
398
401 return None
399 @active
400 def readjournal(self):
401 self._file.seek(0)
402 entries = []
403 for l in self._file:
404 file, troffset = l.split(b'\0')
405 entries.append((file, int(troffset)))
406 return entries
402
407
403 @active
408 @active
404 def replace(self, file, offset):
409 def replace(self, file, offset):
@@ -407,10 +412,9 b' class transaction(util.transactional):'
407 that are not pending in the queue
412 that are not pending in the queue
408 '''
413 '''
409
414
410 if file not in self._map:
415 if file not in self._offsetmap:
411 raise KeyError(file)
416 raise KeyError(file)
412 index = self._map[file]
417 self._offsetmap[file] = offset
413 self._entries[index] = (file, offset)
414 self._file.write(b"%s\0%d\n" % (file, offset))
418 self._file.write(b"%s\0%d\n" % (file, offset))
415 self._file.flush()
419 self._file.flush()
416
420
@@ -550,7 +554,7 b' class transaction(util.transactional):'
550 self._report(
554 self._report(
551 b"couldn't remove %s: %s\n" % (vfs.join(b), inst)
555 b"couldn't remove %s: %s\n" % (vfs.join(b), inst)
552 )
556 )
553 self._entries = []
557 self._offsetmap = {}
554 self._writeundo()
558 self._writeundo()
555 if self._after:
559 if self._after:
556 self._after()
560 self._after()
@@ -627,13 +631,14 b' class transaction(util.transactional):'
627 undobackupfile.close()
631 undobackupfile.close()
628
632
629 def _abort(self):
633 def _abort(self):
634 entries = self.readjournal()
630 self._count = 0
635 self._count = 0
631 self._usages = 0
636 self._usages = 0
632 self._file.close()
637 self._file.close()
633 self._backupsfile.close()
638 self._backupsfile.close()
634
639
635 try:
640 try:
636 if not self._entries and not self._backupentries:
641 if not self._offsetmap and not self._backupentries:
637 if self._backupjournal:
642 if self._backupjournal:
638 self._opener.unlink(self._backupjournal)
643 self._opener.unlink(self._backupjournal)
639 if self._journal:
644 if self._journal:
@@ -652,7 +657,7 b' class transaction(util.transactional):'
652 self._report,
657 self._report,
653 self._opener,
658 self._opener,
654 self._vfsmap,
659 self._vfsmap,
655 self._entries,
660 entries,
656 self._backupentries,
661 self._backupentries,
657 False,
662 False,
658 checkambigfiles=self._checkambigfiles,
663 checkambigfiles=self._checkambigfiles,
General Comments 0
You need to be logged in to leave comments. Login now