Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 12624:557988c691d1
revlog.addgroup(): always use _addrevision() to add new revlog entries
This makes parentdelta clone support pulling.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Fri, 08 Oct 2010 18:00:19 -0500 |
parents | 8f97b50a8d10 |
children | c25945a148c1 |
comparison
equal
deleted
inserted
replaced
12623:8f97b50a8d10 | 12624:557988c691d1 |
---|---|
1298 given a set of deltas, add them to the revision log. the | 1298 given a set of deltas, add them to the revision log. the |
1299 first delta is against its parent, which should be in our | 1299 first delta is against its parent, which should be in our |
1300 log, the rest are against the previous delta. | 1300 log, the rest are against the previous delta. |
1301 """ | 1301 """ |
1302 | 1302 |
1303 #track the base of the current delta log | 1303 # track the base of the current delta log |
1304 node = None | |
1305 | |
1304 r = len(self) | 1306 r = len(self) |
1305 t = r - 1 | 1307 end = 0 |
1306 node = None | |
1307 | |
1308 base = prev = nullrev | |
1309 start = end = textlen = 0 | |
1310 if r: | 1308 if r: |
1311 end = self.end(t) | 1309 end = self.end(r - 1) |
1312 | |
1313 ifh = self.opener(self.indexfile, "a+") | 1310 ifh = self.opener(self.indexfile, "a+") |
1314 isize = r * self._io.size | 1311 isize = r * self._io.size |
1315 if self._inline: | 1312 if self._inline: |
1316 transaction.add(self.indexfile, end + isize, r) | 1313 transaction.add(self.indexfile, end + isize, r) |
1317 dfh = None | 1314 dfh = None |
1342 | 1339 |
1343 for p in (p1, p2): | 1340 for p in (p1, p2): |
1344 if not p in self.nodemap: | 1341 if not p in self.nodemap: |
1345 if self._shallow: | 1342 if self._shallow: |
1346 # add null entries for missing parents | 1343 # add null entries for missing parents |
1347 if base == nullrev: | 1344 # XXX FIXME |
1348 base = len(self) | 1345 #if base == nullrev: |
1349 e = (offset_type(end, REVIDX_PUNCHED_FLAG), | 1346 # base = len(self) |
1350 0, 0, base, nullrev, nullrev, nullrev, p) | 1347 #e = (offset_type(end, REVIDX_PUNCHED_FLAG), |
1351 self.index.insert(-1, e) | 1348 # 0, 0, base, nullrev, nullrev, nullrev, p) |
1352 self.nodemap[p] = r | 1349 #self.index.insert(-1, e) |
1353 entry = self._io.packentry(e, self.node, | 1350 #self.nodemap[p] = r |
1354 self.version, r) | 1351 #entry = self._io.packentry(e, self.node, |
1355 ifh.write(entry) | 1352 # self.version, r) |
1356 t, r = r, r + 1 | 1353 #ifh.write(entry) |
1354 #t, r = r, r + 1 | |
1355 raise LookupError(p, self.indexfile, | |
1356 _('unknown parent')) | |
1357 else: | 1357 else: |
1358 raise LookupError(p, self.indexfile, | 1358 raise LookupError(p, self.indexfile, |
1359 _('unknown parent')) | 1359 _('unknown parent')) |
1360 | 1360 |
1361 if not chain: | 1361 if not chain: |
1362 # retrieve the parent revision of the delta chain | 1362 # retrieve the parent revision of the delta chain |
1363 chain = p1 | 1363 chain = p1 |
1364 if not chain in self.nodemap: | 1364 if not chain in self.nodemap: |
1365 raise LookupError(chain, self.indexfile, _('unknown base')) | 1365 raise LookupError(chain, self.indexfile, _('unknown base')) |
1366 | 1366 |
1367 # full versions are inserted when the needed deltas become | 1367 chainrev = self.rev(chain) |
1368 # comparable to the uncompressed text or when the previous | 1368 chain = self._addrevision(node, None, transaction, link, |
1369 # version is not the one we have a delta against. We use | 1369 p1, p2, (chainrev, delta), ifh, dfh) |
1370 # the size of the previous full rev as a proxy for the | 1370 if not dfh and not self._inline: |
1371 # current size. | 1371 # addrevision switched from inline to conventional |
1372 | 1372 # reopen the index |
1373 if chain == prev: | 1373 dfh = self.opener(self.datafile, "a") |
1374 cdelta = compress(delta) | 1374 ifh = self.opener(self.indexfile, "a") |
1375 cdeltalen = len(cdelta[0]) + len(cdelta[1]) | |
1376 textlen = mdiff.patchedsize(textlen, delta) | |
1377 | |
1378 if chain != prev or (end - start + cdeltalen) > textlen * 2: | |
1379 # flush our writes here so we can read it in revision | |
1380 if dfh: | |
1381 dfh.flush() | |
1382 ifh.flush() | |
1383 text = self.revision(chain) | |
1384 text = mdiff.patch(text, delta) | |
1385 del delta | |
1386 chk = self._addrevision(node, text, transaction, link, | |
1387 p1, p2, None, ifh, dfh) | |
1388 if not dfh and not self._inline: | |
1389 # addrevision switched from inline to conventional | |
1390 # reopen the index | |
1391 dfh = self.opener(self.datafile, "a") | |
1392 ifh = self.opener(self.indexfile, "a") | |
1393 if chk != node: | |
1394 raise RevlogError(_("consistency error adding group")) | |
1395 textlen = len(text) | |
1396 else: | |
1397 e = (offset_type(end, 0), cdeltalen, textlen, base, | |
1398 link, self.rev(p1), self.rev(p2), node) | |
1399 self.index.insert(-1, e) | |
1400 self.nodemap[node] = r | |
1401 entry = self._io.packentry(e, self.node, self.version, r) | |
1402 if self._inline: | |
1403 ifh.write(entry) | |
1404 ifh.write(cdelta[0]) | |
1405 ifh.write(cdelta[1]) | |
1406 self.checkinlinesize(transaction, ifh) | |
1407 if not self._inline: | |
1408 dfh = self.opener(self.datafile, "a") | |
1409 ifh = self.opener(self.indexfile, "a") | |
1410 else: | |
1411 dfh.write(cdelta[0]) | |
1412 dfh.write(cdelta[1]) | |
1413 ifh.write(entry) | |
1414 | |
1415 t, r, chain, prev = r, r + 1, node, node | |
1416 base = self.base(t) | |
1417 start = self.start(base) | |
1418 end = self.end(t) | |
1419 finally: | 1375 finally: |
1420 if dfh: | 1376 if dfh: |
1421 dfh.close() | 1377 dfh.close() |
1422 ifh.close() | 1378 ifh.close() |
1423 | 1379 |