##// END OF EJS Templates
transaction: make journal a private attribute...
Gregory Szorc -
r39712:77c4e2ae default
parent child Browse files
Show More
@@ -131,7 +131,7 b' class transaction(util.transactional):'
131 self.after = after
131 self.after = after
132 self.entries = []
132 self.entries = []
133 self.map = {}
133 self.map = {}
134 self.journal = journalname
134 self._journal = journalname
135 self._undoname = undoname
135 self._undoname = undoname
136 self._queue = []
136 self._queue = []
137 # A callback to validate transaction content before closing it.
137 # A callback to validate transaction content before closing it.
@@ -157,7 +157,7 b' class transaction(util.transactional):'
157
157
158 # a dict of arguments to be passed to hooks
158 # a dict of arguments to be passed to hooks
159 self.hookargs = {}
159 self.hookargs = {}
160 self.file = opener.open(self.journal, "w")
160 self.file = opener.open(self._journal, "w")
161
161
162 # a list of ('location', 'path', 'backuppath', cache) entries.
162 # a list of ('location', 'path', 'backuppath', cache) entries.
163 # - if 'backuppath' is empty, no file existed at backup time
163 # - if 'backuppath' is empty, no file existed at backup time
@@ -167,12 +167,12 b' class transaction(util.transactional):'
167 # (cache is currently unused)
167 # (cache is currently unused)
168 self._backupentries = []
168 self._backupentries = []
169 self._backupmap = {}
169 self._backupmap = {}
170 self._backupjournal = "%s.backupfiles" % self.journal
170 self._backupjournal = "%s.backupfiles" % self._journal
171 self._backupsfile = opener.open(self._backupjournal, 'w')
171 self._backupsfile = opener.open(self._backupjournal, 'w')
172 self._backupsfile.write('%d\n' % version)
172 self._backupsfile.write('%d\n' % version)
173
173
174 if createmode is not None:
174 if createmode is not None:
175 opener.chmod(self.journal, createmode & 0o666)
175 opener.chmod(self._journal, createmode & 0o666)
176 opener.chmod(self._backupjournal, createmode & 0o666)
176 opener.chmod(self._backupjournal, createmode & 0o666)
177
177
178 # hold file generations to be performed on commit
178 # hold file generations to be performed on commit
@@ -194,7 +194,7 b' class transaction(util.transactional):'
194 (name, self._count, self._usages))
194 (name, self._count, self._usages))
195
195
196 def __del__(self):
196 def __del__(self):
197 if self.journal:
197 if self._journal:
198 self._abort()
198 self._abort()
199
199
200 @active
200 @active
@@ -255,7 +255,7 b' class transaction(util.transactional):'
255 return
255 return
256 vfs = self._vfsmap[location]
256 vfs = self._vfsmap[location]
257 dirname, filename = vfs.split(file)
257 dirname, filename = vfs.split(file)
258 backupfilename = "%s.backup.%s" % (self.journal, filename)
258 backupfilename = "%s.backup.%s" % (self._journal, filename)
259 backupfile = vfs.reljoin(dirname, backupfilename)
259 backupfile = vfs.reljoin(dirname, backupfilename)
260 if vfs.exists(file):
260 if vfs.exists(file):
261 filepath = vfs.join(file)
261 filepath = vfs.join(file)
@@ -493,8 +493,8 b' class transaction(util.transactional):'
493 self.after = None # Help prevent cycles.
493 self.after = None # Help prevent cycles.
494 if self.opener.isfile(self._backupjournal):
494 if self.opener.isfile(self._backupjournal):
495 self.opener.unlink(self._backupjournal)
495 self.opener.unlink(self._backupjournal)
496 if self.opener.isfile(self.journal):
496 if self.opener.isfile(self._journal):
497 self.opener.unlink(self.journal)
497 self.opener.unlink(self._journal)
498 for l, _f, b, c in self._backupentries:
498 for l, _f, b, c in self._backupentries:
499 if l not in self._vfsmap and c:
499 if l not in self._vfsmap and c:
500 self.report("couldn't remove %s: unknown cache location"
500 self.report("couldn't remove %s: unknown cache location"
@@ -511,7 +511,7 b' class transaction(util.transactional):'
511 self.report("couldn't remove %s: %s\n"
511 self.report("couldn't remove %s: %s\n"
512 % (vfs.join(b), inst))
512 % (vfs.join(b), inst))
513 self._backupentries = []
513 self._backupentries = []
514 self.journal = None
514 self._journal = None
515
515
516 self.releasefn(self, True) # notify success of closing transaction
516 self.releasefn(self, True) # notify success of closing transaction
517 self.releasefn = None # Help prevent cycles.
517 self.releasefn = None # Help prevent cycles.
@@ -549,8 +549,8 b' class transaction(util.transactional):'
549 continue
549 continue
550 vfs = self._vfsmap[l]
550 vfs = self._vfsmap[l]
551 base, name = vfs.split(b)
551 base, name = vfs.split(b)
552 assert name.startswith(self.journal), name
552 assert name.startswith(self._journal), name
553 uname = name.replace(self.journal, self._undoname, 1)
553 uname = name.replace(self._journal, self._undoname, 1)
554 u = vfs.reljoin(base, uname)
554 u = vfs.reljoin(base, uname)
555 util.copyfile(vfs.join(b), vfs.join(u), hardlink=True)
555 util.copyfile(vfs.join(b), vfs.join(u), hardlink=True)
556 undobackupfile.write("%s\0%s\0%s\0%d\n" % (l, f, u, c))
556 undobackupfile.write("%s\0%s\0%s\0%d\n" % (l, f, u, c))
@@ -567,8 +567,8 b' class transaction(util.transactional):'
567 if not self.entries and not self._backupentries:
567 if not self.entries and not self._backupentries:
568 if self._backupjournal:
568 if self._backupjournal:
569 self.opener.unlink(self._backupjournal)
569 self.opener.unlink(self._backupjournal)
570 if self.journal:
570 if self._journal:
571 self.opener.unlink(self.journal)
571 self.opener.unlink(self._journal)
572 return
572 return
573
573
574 self.report(_("transaction abort!\n"))
574 self.report(_("transaction abort!\n"))
@@ -578,14 +578,14 b' class transaction(util.transactional):'
578 self._abortcallback[cat](self)
578 self._abortcallback[cat](self)
579 # Prevent double usage and help clear cycles.
579 # Prevent double usage and help clear cycles.
580 self._abortcallback = None
580 self._abortcallback = None
581 _playback(self.journal, self.report, self.opener, self._vfsmap,
581 _playback(self._journal, self.report, self.opener, self._vfsmap,
582 self.entries, self._backupentries, False,
582 self.entries, self._backupentries, False,
583 checkambigfiles=self.checkambigfiles)
583 checkambigfiles=self.checkambigfiles)
584 self.report(_("rollback completed\n"))
584 self.report(_("rollback completed\n"))
585 except BaseException:
585 except BaseException:
586 self.report(_("rollback failed - please run hg recover\n"))
586 self.report(_("rollback failed - please run hg recover\n"))
587 finally:
587 finally:
588 self.journal = None
588 self._journal = None
589 self.releasefn(self, False) # notify failure of transaction
589 self.releasefn(self, False) # notify failure of transaction
590 self.releasefn = None # Help prevent cycles.
590 self.releasefn = None # Help prevent cycles.
591
591
General Comments 0
You need to be logged in to leave comments. Login now