##// END OF EJS Templates
transaction: refactor transaction.abort and rollback to use the same code...
Henrik Stuart -
r8294:48a382c2 default
parent child Browse files
Show More
@@ -624,7 +624,7 class localrepository(repo.repository):
624 624 try:
625 625 if os.path.exists(self.sjoin("journal")):
626 626 self.ui.status(_("rolling back interrupted transaction\n"))
627 transaction.rollback(self.sopener, self.sjoin("journal"))
627 transaction.rollback(self.sopener, self.sjoin("journal"), self.ui.warn)
628 628 self.invalidate()
629 629 return True
630 630 else:
@@ -640,7 +640,7 class localrepository(repo.repository):
640 640 lock = self.lock()
641 641 if os.path.exists(self.sjoin("undo")):
642 642 self.ui.status(_("rolling back last transaction\n"))
643 transaction.rollback(self.sopener, self.sjoin("undo"))
643 transaction.rollback(self.sopener, self.sjoin("undo"), self.ui.warn)
644 644 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
645 645 try:
646 646 branch = self.opener("undo.branch").read()
@@ -23,6 +23,23 def active(func):
23 23 return func(self, *args, **kwds)
24 24 return _active
25 25
26 def _playback(journal, report, opener, entries, unlink=True):
27 for f, o, ignore in entries:
28 if o or not unlink:
29 try:
30 opener(f, 'a').truncate(o)
31 except:
32 report(_("failed to truncate %s\n") % f)
33 raise
34 else:
35 try:
36 fn = opener(f).name
37 os.unlink(fn)
38 except OSError, inst:
39 if inst.errno != errno.ENOENT:
40 raise
41 os.unlink(journal)
42
26 43 class transaction(object):
27 44 def __init__(self, report, opener, journal, after=None, createmode=None):
28 45 self.journal = None
@@ -101,40 +118,21 class transaction(object):
101 118
102 119 self.report(_("transaction abort!\n"))
103 120
104 failed = False
105 for f, o, ignore in self.entries:
121 try:
106 122 try:
107 self.opener(f, "a").truncate(o)
123 _playback(self.journal, self.report, self.opener, self.entries, False)
124 self.report(_("rollback completed\n"))
108 125 except:
109 failed = True
110 self.report(_("failed to truncate %s\n") % f)
111
112 self.entries = []
113
114 if not failed:
115 os.unlink(self.journal)
116 self.report(_("rollback completed\n"))
117 else:
118 126 self.report(_("rollback failed - please run hg recover\n"))
119
127 finally:
120 128 self.journal = None
121 129
122 130
123 def rollback(opener, file):
124 files = {}
131 def rollback(opener, file, report):
132 entries = []
133
125 134 for l in open(file).readlines():
126 135 f, o = l.split('\0')
127 files[f] = int(o)
128 for f in files:
129 o = files[f]
130 if o:
131 opener(f, "a").truncate(int(o))
132 else:
133 try:
134 fn = opener(f).name
135 os.unlink(fn)
136 except OSError, inst:
137 if inst.errno != errno.ENOENT:
138 raise
139 os.unlink(file)
136 entries.append((f, int(o), None))
140 137
138 _playback(file, report, opener, entries)
@@ -17,8 +17,9 checking files
17 17 b@?: rev 1 points to nonexistent changeset 2
18 18 (expected 1)
19 19 b@?: 736c29771fba not in manifests
20 warning: orphan revlog 'data/c.i'
20 21 2 files, 2 changesets, 3 total revisions
21 1 warnings encountered!
22 2 warnings encountered!
22 23 2 integrity errors encountered!
23 24 % journal contents
24 25 00changelog.i
@@ -63,15 +64,15 checking manifests
63 64 manifest@?: rev 2 points to nonexistent changeset 2
64 65 manifest@?: rev 3 points to nonexistent changeset 3
65 66 crosschecking files in changesets and manifests
66 c@?: in manifest but not in changeset
67 c@3: in manifest but not in changeset
67 68 checking files
68 b@2: 736c29771fba in manifests not found
69 data/c.i@?: missing revlog!
70 ?: empty or missing c
71 c@3: 149da44f2a4e in manifests not found
72 3 files, 2 changesets, 2 total revisions
73 7 integrity errors encountered!
74 (first damaged changeset appears to be 2)
69 b@?: rev 1 points to nonexistent changeset 2
70 (expected 1)
71 c@?: rev 0 points to nonexistent changeset 3
72 3 files, 2 changesets, 4 total revisions
73 1 warnings encountered!
74 5 integrity errors encountered!
75 (first damaged changeset appears to be 3)
75 76 % journal contents
76 77 00changelog.i
77 78 00manifest.i
General Comments 0
You need to be logged in to leave comments. Login now