# HG changeset patch
# User Joerg Sonnenberger <joerg@bec.de>
# Date 1602032401 -7200
#      Wed Oct 07 03:00:01 2020 +0200
# Node ID 88d5abec8f61a2f6e6a1adab24b2959dbca0970f
# Parent  57dc78861196740995db134e9a13c76aac242fc8
bundlerepo: don't insert index tuples with full nodes as linkrev

The index format has a documented format and latter changes will start
to enforce the field types. The bundlerepo uses full nodes for the
linkrev field when it should be using revision numbers. Use the link
mapping to resolve them, except in the special case of self-references.
Those are actually indications of a missing linkrev.

Differential Revision: https://phab.mercurial-scm.org/D9160

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -63,11 +63,14 @@
             size = len(delta)
             start = cgunpacker.tell() - size
 
-            link = linkmapper(cs)
             if self.index.has_node(node):
                 # this can happen if two branches make the same change
                 self.bundlerevs.add(self.index.rev(node))
                 continue
+            if cs == node:
+                linkrev = nullrev
+            else:
+                linkrev = linkmapper(cs)
 
             for p in (p1, p2):
                 if not self.index.has_node(p):
@@ -87,7 +90,7 @@
                 size,
                 -1,
                 baserev,
-                link,
+                linkrev,
                 self.rev(p1),
                 self.rev(p2),
                 node,