comparison mercurial/transaction.py @ 23251:85c634ff395a

transaction: drop backupentries logic from startgroup and endgroup The `startgroup` and `endgroup` methods are used in a very specific context to wrap a very specific operation (revlog truncation). It does not make sense to perform any other operations during such a "group" (eg:file backup). There is currently no user of backupfile during a "group" so we drop the group-specific code and restrict authorized operations during "group".
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 05 Nov 2014 10:05:38 +0000
parents 8919dc7f2dbb
children 70809438c644
comparison
equal deleted inserted replaced
23250:8919dc7f2dbb 23251:85c634ff395a
119 def startgroup(self): 119 def startgroup(self):
120 """delay registration of file entry 120 """delay registration of file entry
121 121
122 This is used by strip to delay vision of strip offset. The transaction 122 This is used by strip to delay vision of strip offset. The transaction
123 sees either none or all of the strip actions to be done.""" 123 sees either none or all of the strip actions to be done."""
124 self._queue.append(([], [])) 124 self._queue.append([])
125 125
126 @active 126 @active
127 def endgroup(self): 127 def endgroup(self):
128 """apply delayed registration of file entry. 128 """apply delayed registration of file entry.
129 129
130 This is used by strip to delay vision of strip offset. The transaction 130 This is used by strip to delay vision of strip offset. The transaction
131 sees either none or all of the strip actions to be done.""" 131 sees either none or all of the strip actions to be done."""
132 q = self._queue.pop() 132 q = self._queue.pop()
133 self.entries.extend(q[0]) 133 self.entries.extend(q)
134 self._backupentries.extend(q[1])
135 134
136 offsets = [] 135 offsets = []
137 backups = [] 136 for f, o, _data in q:
138 for f, o, _data in q[0]:
139 offsets.append((f, o)) 137 offsets.append((f, o))
140
141 for f, b in q[1]:
142 backups.append((f, b))
143 138
144 d = ''.join(['%s\0%d\n' % (f, o) for f, o in offsets]) 139 d = ''.join(['%s\0%d\n' % (f, o) for f, o in offsets])
145 self.file.write(d) 140 self.file.write(d)
146 self.file.flush() 141 self.file.flush()
147
148 d = ''.join(['%s\0%s\n' % (f, b) for f, b in backups])
149 self._backupsfile.write(d)
150 self._backupsfile.flush()
151 142
152 @active 143 @active
153 def add(self, file, offset, data=None): 144 def add(self, file, offset, data=None):
154 if file in self.map or file in self._backupmap: 145 if file in self.map or file in self._backupmap:
155 return 146 return
156 if self._queue: 147 if self._queue:
157 self._queue[-1][0].append((file, offset, data)) 148 self._queue[-1].append((file, offset, data))
158 return 149 return
159 150
160 self.entries.append((file, offset, data)) 151 self.entries.append((file, offset, data))
161 self.map[file] = len(self.entries) - 1 152 self.map[file] = len(self.entries) - 1
162 # add enough data to the journal to do the truncate 153 # add enough data to the journal to do the truncate
172 aborting. 163 aborting.
173 164
174 * `file`: the file path, relative to .hg/store 165 * `file`: the file path, relative to .hg/store
175 * `hardlink`: use a hardlink to quickly create the backup 166 * `hardlink`: use a hardlink to quickly create the backup
176 """ 167 """
168 if self._queue:
169 msg = 'cannot use transaction.addbackup inside "group"'
170 raise RuntimeError(msg)
177 171
178 if file in self.map or file in self._backupmap: 172 if file in self.map or file in self._backupmap:
179 return 173 return
180 backupfile = "%s.backup.%s" % (self.journal, file) 174 backupfile = "%s.backup.%s" % (self.journal, file)
181 if vfs is None: 175 if vfs is None:
184 filepath = vfs.join(file) 178 filepath = vfs.join(file)
185 backuppath = self.opener.join(backupfile) 179 backuppath = self.opener.join(backupfile)
186 util.copyfiles(filepath, backuppath, hardlink=hardlink) 180 util.copyfiles(filepath, backuppath, hardlink=hardlink)
187 else: 181 else:
188 self.add(file, 0) 182 self.add(file, 0)
189 return
190
191 if self._queue:
192 self._queue[-1][1].append((file, backupfile))
193 return 183 return
194 184
195 self._backupentries.append((file, backupfile)) 185 self._backupentries.append((file, backupfile))
196 self._backupmap[file] = len(self._backupentries) - 1 186 self._backupmap[file] = len(self._backupentries) - 1
197 self._backupsfile.write("%s\0%s\n" % (file, backupfile)) 187 self._backupsfile.write("%s\0%s\n" % (file, backupfile))