##// END OF EJS Templates
transaction: mark backup-related attributes private...
Pierre-Yves David -
r23249:84720eab default
parent child Browse files
Show More
@@ -83,22 +83,22 b' class transaction(object):'
83 self.onclose = onclose
83 self.onclose = onclose
84 self.onabort = onabort
84 self.onabort = onabort
85 self.entries = []
85 self.entries = []
86 self.map = {}
86 # a list of ('path', 'backuppath') entries.
87 # a list of ('path', 'backuppath') entries.
87 self.backupentries = []
88 self._backupentries = []
88 self.map = {}
89 self._backupmap = {}
89 self.backupmap = {}
90 self.journal = journal
90 self.journal = journal
91 self._queue = []
91 self._queue = []
92 # a dict of arguments to be passed to hooks
92 # a dict of arguments to be passed to hooks
93 self.hookargs = {}
93 self.hookargs = {}
94
94
95 self.backupjournal = "%s.backupfiles" % journal
95 self._backupjournal = "%s.backupfiles" % journal
96 self.file = opener.open(self.journal, "w")
96 self.file = opener.open(self.journal, "w")
97 self.backupsfile = opener.open(self.backupjournal, 'w')
97 self._backupsfile = opener.open(self._backupjournal, 'w')
98 self.backupsfile.write('%d\n' % version)
98 self._backupsfile.write('%d\n' % version)
99 if createmode is not None:
99 if createmode is not None:
100 opener.chmod(self.journal, createmode & 0666)
100 opener.chmod(self.journal, createmode & 0666)
101 opener.chmod(self.backupjournal, createmode & 0666)
101 opener.chmod(self._backupjournal, createmode & 0666)
102
102
103 # hold file generations to be performed on commit
103 # hold file generations to be performed on commit
104 self._filegenerators = {}
104 self._filegenerators = {}
@@ -123,7 +123,7 b' class transaction(object):'
123 def endgroup(self):
123 def endgroup(self):
124 q = self._queue.pop()
124 q = self._queue.pop()
125 self.entries.extend(q[0])
125 self.entries.extend(q[0])
126 self.backupentries.extend(q[1])
126 self._backupentries.extend(q[1])
127
127
128 offsets = []
128 offsets = []
129 backups = []
129 backups = []
@@ -138,12 +138,12 b' class transaction(object):'
138 self.file.flush()
138 self.file.flush()
139
139
140 d = ''.join(['%s\0%s\n' % (f, b) for f, b in backups])
140 d = ''.join(['%s\0%s\n' % (f, b) for f, b in backups])
141 self.backupsfile.write(d)
141 self._backupsfile.write(d)
142 self.backupsfile.flush()
142 self._backupsfile.flush()
143
143
144 @active
144 @active
145 def add(self, file, offset, data=None):
145 def add(self, file, offset, data=None):
146 if file in self.map or file in self.backupmap:
146 if file in self.map or file in self._backupmap:
147 return
147 return
148 if self._queue:
148 if self._queue:
149 self._queue[-1][0].append((file, offset, data))
149 self._queue[-1][0].append((file, offset, data))
@@ -167,7 +167,7 b' class transaction(object):'
167 * `hardlink`: use a hardlink to quickly create the backup
167 * `hardlink`: use a hardlink to quickly create the backup
168 """
168 """
169
169
170 if file in self.map or file in self.backupmap:
170 if file in self.map or file in self._backupmap:
171 return
171 return
172 backupfile = "%s.backup.%s" % (self.journal, file)
172 backupfile = "%s.backup.%s" % (self.journal, file)
173 if vfs is None:
173 if vfs is None:
@@ -184,10 +184,10 b' class transaction(object):'
184 self._queue[-1][1].append((file, backupfile))
184 self._queue[-1][1].append((file, backupfile))
185 return
185 return
186
186
187 self.backupentries.append((file, backupfile))
187 self._backupentries.append((file, backupfile))
188 self.backupmap[file] = len(self.backupentries) - 1
188 self._backupmap[file] = len(self._backupentries) - 1
189 self.backupsfile.write("%s\0%s\n" % (file, backupfile))
189 self._backupsfile.write("%s\0%s\n" % (file, backupfile))
190 self.backupsfile.flush()
190 self._backupsfile.flush()
191
191
192 @active
192 @active
193 def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None):
193 def addfilegenerator(self, genid, filenames, genfunc, order=0, vfs=None):
@@ -238,8 +238,8 b' class transaction(object):'
238 def find(self, file):
238 def find(self, file):
239 if file in self.map:
239 if file in self.map:
240 return self.entries[self.map[file]]
240 return self.entries[self.map[file]]
241 if file in self.backupmap:
241 if file in self._backupmap:
242 return self.backupentries[self.backupmap[file]]
242 return self._backupentries[self._backupmap[file]]
243 return None
243 return None
244
244
245 @active
245 @active
@@ -324,17 +324,17 b' class transaction(object):'
324 if self.count != 0:
324 if self.count != 0:
325 return
325 return
326 self.file.close()
326 self.file.close()
327 self.backupsfile.close()
327 self._backupsfile.close()
328 self.entries = []
328 self.entries = []
329 if self.after:
329 if self.after:
330 self.after()
330 self.after()
331 if self.opener.isfile(self.journal):
331 if self.opener.isfile(self.journal):
332 self.opener.unlink(self.journal)
332 self.opener.unlink(self.journal)
333 if self.opener.isfile(self.backupjournal):
333 if self.opener.isfile(self._backupjournal):
334 self.opener.unlink(self.backupjournal)
334 self.opener.unlink(self._backupjournal)
335 for _f, b in self.backupentries:
335 for _f, b in self._backupentries:
336 self.opener.unlink(b)
336 self.opener.unlink(b)
337 self.backupentries = []
337 self._backupentries = []
338 self.journal = None
338 self.journal = None
339 # run post close action
339 # run post close action
340 categories = sorted(self._postclosecallback)
340 categories = sorted(self._postclosecallback)
@@ -352,24 +352,24 b' class transaction(object):'
352 self.count = 0
352 self.count = 0
353 self.usages = 0
353 self.usages = 0
354 self.file.close()
354 self.file.close()
355 self.backupsfile.close()
355 self._backupsfile.close()
356
356
357 if self.onabort is not None:
357 if self.onabort is not None:
358 self.onabort()
358 self.onabort()
359
359
360 try:
360 try:
361 if not self.entries and not self.backupentries:
361 if not self.entries and not self._backupentries:
362 if self.journal:
362 if self.journal:
363 self.opener.unlink(self.journal)
363 self.opener.unlink(self.journal)
364 if self.backupjournal:
364 if self._backupjournal:
365 self.opener.unlink(self.backupjournal)
365 self.opener.unlink(self._backupjournal)
366 return
366 return
367
367
368 self.report(_("transaction abort!\n"))
368 self.report(_("transaction abort!\n"))
369
369
370 try:
370 try:
371 _playback(self.journal, self.report, self.opener,
371 _playback(self.journal, self.report, self.opener,
372 self.entries, self.backupentries, False)
372 self.entries, self._backupentries, False)
373 self.report(_("rollback completed\n"))
373 self.report(_("rollback completed\n"))
374 except Exception:
374 except Exception:
375 self.report(_("rollback failed - please run hg recover\n"))
375 self.report(_("rollback failed - please run hg recover\n"))
General Comments 0
You need to be logged in to leave comments. Login now