[PATCH 2 of 4] revlog: addgroup adds punched revisions for missing parents

Vishakh H vsh426 at gmail.com
Tue Aug 10 08:08:54 CDT 2010


# HG changeset patch
# User Vishakh H <vsh426 at gmail.com>
# Date 1281445635 -19800
# Node ID 24bc8a82d4f7b4cff194b96c0e0c1601563b6eee
# Parent  85bb4e5aa6292f74714b613ba17a0dde3d825253
revlog: addgroup 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.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1121,7 +1121,8 @@
 
     def _addrevision(self, text, transaction, link, p1, p2, d, ifh, dfh):
         node = hash(text, p1, p2)
-        if node in self.nodemap:
+        if (node in self.nodemap and
+            (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)):
             return node
 
         curr = len(self)
@@ -1250,7 +1251,8 @@
             for chunk in revs:
                 node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80])
                 link = linkmapper(cs)
-                if node in self.nodemap:
+                if (node in self.nodemap and
+                    (not self.flags(self.rev(node)) & REVIDX_PUNCHED_FLAG)):
                     # this can happen if two branches make the same change
                     chain = node
                     continue
@@ -1259,7 +1261,21 @@
 
                 for p in (p1, p2):
                     if not p in self.nodemap:
-                        raise LookupError(p, self.indexfile, _('unknown parent'))
+                        if self._shallow:
+                            # add null entries for missing parents
+                            if base == -1:
+                                base = len(self)
+                            e = (offset_type(end, REVIDX_PUNCHED_FLAG),
+                                 0, 0, base, nullrev, nullrev, nullrev, p)
+                            self.index.insert(-1, e)
+                            self.nodemap[p] = r
+                            entry = self._io.packentry(e, self.node,
+                                                       self.version, r)
+                            ifh.write(entry)
+                            t, r = r, r + 1
+                        else:
+                            raise LookupError(p, self.indexfile,
+                                              _('unknown parent'))
 
                 if not chain:
                     # retrieve the parent revision of the delta chain


More information about the Mercurial-devel mailing list