comparison mercurial/revlog.py @ 12000:3361075816f8

revlog: addgroup re-adds punched revisions for missing parents While reading changegroup if a node with missing parents is encountered, we add a punched entry in the index with null parents for the missing parent node.
author Vishakh H <vsh426@gmail.com>
date Fri, 13 Aug 2010 19:42:28 +0530
parents 62e2bbf523f2
children f38b0a3308b6
comparison
equal deleted inserted replaced
11999:62e2bbf523f2 12000:3361075816f8
1152 ifh.close() 1152 ifh.close()
1153 1153
1154 def _addrevision(self, text, transaction, link, p1, p2, 1154 def _addrevision(self, text, transaction, link, p1, p2,
1155 cachedelta, ifh, dfh): 1155 cachedelta, ifh, dfh):
1156 node = hash(text, p1, p2) 1156 node = hash(text, p1, p2)
1157 if node in self.nodemap: 1157 if (node in self.nodemap and
1158 (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)):
1158 return node 1159 return node
1159 1160
1160 curr = len(self) 1161 curr = len(self)
1161 prev = curr - 1 1162 prev = curr - 1
1162 base = curr 1163 base = curr
1303 # loop through our set of deltas 1304 # loop through our set of deltas
1304 chain = None 1305 chain = None
1305 for chunk in revs: 1306 for chunk in revs:
1306 node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) 1307 node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80])
1307 link = linkmapper(cs) 1308 link = linkmapper(cs)
1308 if node in self.nodemap: 1309 if (node in self.nodemap and
1310 (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)):
1309 # this can happen if two branches make the same change 1311 # this can happen if two branches make the same change
1310 chain = node 1312 chain = node
1311 continue 1313 continue
1312 delta = buffer(chunk, 80) 1314 delta = buffer(chunk, 80)
1313 del chunk 1315 del chunk
1314 1316
1315 for p in (p1, p2): 1317 for p in (p1, p2):
1316 if not p in self.nodemap: 1318 if not p in self.nodemap:
1317 raise LookupError(p, self.indexfile, _('unknown parent')) 1319 if self._shallow:
1320 # add null entries for missing parents
1321 if base == nullrev:
1322 base = len(self)
1323 e = (offset_type(end, REVIDX_PUNCHED_FLAG),
1324 0, 0, base, nullrev, nullrev, nullrev, p)
1325 self.index.insert(-1, e)
1326 self.nodemap[p] = r
1327 entry = self._io.packentry(e, self.node,
1328 self.version, r)
1329 ifh.write(entry)
1330 t, r = r, r + 1
1331 else:
1332 raise LookupError(p, self.indexfile,
1333 _('unknown parent'))
1318 1334
1319 if not chain: 1335 if not chain:
1320 # retrieve the parent revision of the delta chain 1336 # retrieve the parent revision of the delta chain
1321 chain = p1 1337 chain = p1
1322 if not chain in self.nodemap: 1338 if not chain in self.nodemap:
1339 dfh.flush() 1355 dfh.flush()
1340 ifh.flush() 1356 ifh.flush()
1341 text = self.revision(chain) 1357 text = self.revision(chain)
1342 if len(text) == 0: 1358 if len(text) == 0:
1343 # skip over trivial delta header 1359 # skip over trivial delta header
1360 # text == '' in the case of nullrev or punched revision
1344 text = buffer(delta, 12) 1361 text = buffer(delta, 12)
1345 else: 1362 else:
1346 text = mdiff.patches(text, [delta]) 1363 text = mdiff.patches(text, [delta])
1347 del delta 1364 del delta
1348 chk = self._addrevision(text, transaction, link, p1, p2, None, 1365 chk = self._addrevision(text, transaction, link, p1, p2, None,