revlog: fix revlogio.packentry corner case
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Wed, 26 Sep 2007 01:58:45 -0300
changeset 5338 f87685355c9c
parent 5337 8c5ef3b87cb1
child 5339 058e93c3d07d
child 5351 c8d6f8510bf4
revlog: fix revlogio.packentry corner case We want to store version information about the revlog in the first entry of its index. The code in packentry was using some heuristics to detect whether this was the first entry, but these heuristics could fail in some cases (e.g. rev 0 was empty; rev 1 descends directly from the nullid and is stored as a delta). We now give the revision number to packentry to avoid heuristics.
mercurial/revlog.py
tests/test-revlog-packentry
tests/test-revlog-packentry.out
--- a/mercurial/revlog.py	Tue Sep 25 19:05:34 2007 +0200
+++ b/mercurial/revlog.py	Wed Sep 26 01:58:45 2007 -0300
@@ -314,7 +314,7 @@
 
         return index, nodemap, None
 
-    def packentry(self, entry, node, version):
+    def packentry(self, entry, node, version, rev):
         e2 = (getoffset(entry[0]), entry[1], entry[3], entry[4],
               node(entry[5]), node(entry[6]), entry[7])
         return _pack(indexformatv0, *e2)
@@ -388,9 +388,9 @@
 
         return index, nodemap, cache
 
-    def packentry(self, entry, node, version):
+    def packentry(self, entry, node, version, rev):
         p = _pack(indexformatng, *entry)
-        if not entry[3] and not getoffset(entry[0]) and entry[5] == nullrev:
+        if rev == 0:
             p = _pack(versionformat, version) + p[4:]
         return p
 
@@ -972,7 +972,7 @@
         self.version &= ~(REVLOGNGINLINEDATA)
         self._inline = False
         for i in xrange(self.count()):
-            e = self._io.packentry(self.index[i], self.node, self.version)
+            e = self._io.packentry(self.index[i], self.node, self.version, i)
             fp.write(e)
 
         # if we don't call rename, the temp file will never replace the
@@ -1027,7 +1027,7 @@
         self.index.insert(-1, e)
         self.nodemap[node] = curr
 
-        entry = self._io.packentry(e, self.node, self.version)
+        entry = self._io.packentry(e, self.node, self.version, curr)
         if not self._inline:
             transaction.add(self.datafile, offset)
             transaction.add(self.indexfile, curr * len(entry))
@@ -1179,7 +1179,7 @@
                      link, self.rev(p1), self.rev(p2), node)
                 self.index.insert(-1, e)
                 self.nodemap[node] = r
-                entry = self._io.packentry(e, self.node, self.version)
+                entry = self._io.packentry(e, self.node, self.version, r)
                 if self._inline:
                     ifh.write(entry)
                     ifh.write(cdelta)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-revlog-packentry	Wed Sep 26 01:58:45 2007 -0300
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+hg init repo
+cd repo
+
+touch foo
+hg ci -Am 'add foo'
+
+hg up -C null
+# this should be stored as a delta against rev 0
+echo foo bar baz > foo
+hg ci -Am 'add foo again'
+
+hg debugindex .hg/store/data/foo.i
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-revlog-packentry.out	Wed Sep 26 01:58:45 2007 -0300
@@ -0,0 +1,6 @@
+adding foo
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+adding foo
+   rev    offset  length   base linkrev nodeid       p1           p2
+     0         0       0      0       0 b80de5d13875 000000000000 000000000000
+     1         0      24      0       1 0376abec49b8 000000000000 000000000000