changeset 46561:7a93b7b3dc2d

revlog: change addgroup callbacks to take revision numbers Differential Revision: https://phab.mercurial-scm.org/D9883
author Joerg Sonnenberger <joerg@bec.de>
date Wed, 27 Jan 2021 02:34:51 +0100
parents f7b61ad3c64a
children fa7ae7aa0efd
files hgext/sqlitestore.py mercurial/changegroup.py mercurial/changelog.py mercurial/exchangev2.py mercurial/interfaces/repository.py mercurial/revlog.py mercurial/testing/storage.py tests/simplestorerepo.py
diffstat 8 files changed, 37 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/sqlitestore.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/hgext/sqlitestore.py	Wed Jan 27 02:34:51 2021 +0100
@@ -743,7 +743,7 @@
                     )
 
                 if duplicaterevisioncb:
-                    duplicaterevisioncb(self, node)
+                    duplicaterevisioncb(self, self.rev(node))
                 empty = False
                 continue
 
@@ -754,7 +754,7 @@
                 text = None
                 storedelta = (deltabase, delta)
 
-            self._addrawrevision(
+            rev = self._addrawrevision(
                 node,
                 text,
                 transaction,
@@ -766,7 +766,7 @@
             )
 
             if addrevisioncb:
-                addrevisioncb(self, node)
+                addrevisioncb(self, rev)
             empty = False
 
         return not empty
--- a/mercurial/changegroup.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/mercurial/changegroup.py	Wed Jan 27 02:34:51 2021 +0100
@@ -318,12 +318,11 @@
             efilesset = set()
             cgnodes = []
 
-            def ondupchangelog(cl, node):
-                if cl.rev(node) < clstart:
-                    cgnodes.append(node)
+            def ondupchangelog(cl, rev):
+                if rev < clstart:
+                    cgnodes.append(cl.node(rev))
 
-            def onchangelog(cl, node):
-                rev = cl.rev(node)
+            def onchangelog(cl, rev):
                 ctx = cl.changelogrevision(rev)
                 efilesset.update(ctx.files)
                 repo.register_changeset(rev, ctx)
--- a/mercurial/changelog.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/mercurial/changelog.py	Wed Jan 27 02:34:51 2021 +0100
@@ -610,9 +610,9 @@
         just to access this is costly."""
         return self.changelogrevision(rev).branchinfo
 
-    def _nodeduplicatecallback(self, transaction, node):
+    def _nodeduplicatecallback(self, transaction, rev):
         # keep track of revisions that got "re-added", eg: unbunde of know rev.
         #
         # We track them in a list to preserve their order from the source bundle
         duplicates = transaction.changes.setdefault(b'revduplicates', [])
-        duplicates.append(self.rev(node))
+        duplicates.append(rev)
--- a/mercurial/exchangev2.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/mercurial/exchangev2.py	Wed Jan 27 02:34:51 2021 +0100
@@ -358,15 +358,14 @@
         # Linkrev for changelog is always self.
         return len(cl)
 
-    def ondupchangeset(cl, node):
-        added.append(node)
+    def ondupchangeset(cl, rev):
+        added.append(cl.node(rev))
 
-    def onchangeset(cl, node):
+    def onchangeset(cl, rev):
         progress.increment()
 
-        rev = cl.rev(node)
         revision = cl.changelogrevision(rev)
-        added.append(node)
+        added.append(cl.node(rev))
 
         # We need to preserve the mapping of changelog revision to node
         # so we can set the linkrev accordingly when manifests are added.
@@ -537,8 +536,8 @@
             # Chomp off header object.
             next(objs)
 
-            def onchangeset(cl, node):
-                added.append(node)
+            def onchangeset(cl, rev):
+                added.append(cl.node(rev))
 
             rootmanifest.addgroup(
                 iterrevisions(objs, progress),
--- a/mercurial/interfaces/repository.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/mercurial/interfaces/repository.py	Wed Jan 27 02:34:51 2021 +0100
@@ -774,8 +774,9 @@
         This used to be the default when ``addrevisioncb`` was provided up to
         Mercurial 5.8.
 
-        ``addrevisioncb`` should be called for each node as it is committed.
-        ``duplicaterevisioncb`` should be called for each pre-existing node.
+        ``addrevisioncb`` should be called for each new rev as it is committed.
+        ``duplicaterevisioncb`` should be called for all revs with a
+        pre-existing node.
 
         ``maybemissingparents`` is a bool indicating whether the incoming
         data may reference parents/ancestor revisions that aren't present.
--- a/mercurial/revlog.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/mercurial/revlog.py	Wed Jan 27 02:34:51 2021 +0100
@@ -2419,11 +2419,12 @@
                 link = linkmapper(linknode)
                 flags = flags or REVIDX_DEFAULT_FLAGS
 
-                if self.index.has_node(node):
+                rev = self.index.get_rev(node)
+                if rev is not None:
                     # this can happen if two branches make the same change
-                    self._nodeduplicatecallback(transaction, node)
+                    self._nodeduplicatecallback(transaction, rev)
                     if duplicaterevisioncb:
-                        duplicaterevisioncb(self, node)
+                        duplicaterevisioncb(self, rev)
                     empty = False
                     continue
 
@@ -2461,7 +2462,7 @@
                 # We're only using addgroup() in the context of changegroup
                 # generation so the revision data can always be handled as raw
                 # by the flagprocessor.
-                self._addrevision(
+                rev = self._addrevision(
                     node,
                     None,
                     transaction,
@@ -2477,7 +2478,7 @@
                 )
 
                 if addrevisioncb:
-                    addrevisioncb(self, node)
+                    addrevisioncb(self, rev)
                 empty = False
 
                 if not dfh and not self._inline:
--- a/mercurial/testing/storage.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/mercurial/testing/storage.py	Wed Jan 27 02:34:51 2021 +0100
@@ -1129,12 +1129,13 @@
         with self._maketransactionfn() as tr:
             nodes = []
 
-            def onchangeset(cl, node):
+            def onchangeset(cl, rev):
+                node = cl.node(rev)
                 nodes.append(node)
                 cb(cl, node)
 
-            def ondupchangeset(cl, node):
-                nodes.append(node)
+            def ondupchangeset(cl, rev):
+                nodes.append(cl.node(rev))
 
             f.addgroup(
                 [],
@@ -1163,12 +1164,13 @@
         with self._maketransactionfn() as tr:
             nodes = []
 
-            def onchangeset(cl, node):
+            def onchangeset(cl, rev):
+                node = cl.node(rev)
                 nodes.append(node)
                 cb(cl, node)
 
-            def ondupchangeset(cl, node):
-                nodes.append(node)
+            def ondupchangeset(cl, rev):
+                nodes.append(cl.node(rev))
 
             f.addgroup(
                 deltas,
@@ -1217,8 +1219,8 @@
         with self._maketransactionfn() as tr:
             newnodes = []
 
-            def onchangeset(cl, node):
-                newnodes.append(node)
+            def onchangeset(cl, rev):
+                newnodes.append(cl.node(rev))
 
             f.addgroup(
                 deltas,
--- a/tests/simplestorerepo.py	Wed Jan 27 01:43:17 2021 +0100
+++ b/tests/simplestorerepo.py	Wed Jan 27 02:34:51 2021 +0100
@@ -550,7 +550,7 @@
 
             if node in self._indexbynode:
                 if duplicaterevisioncb:
-                    duplicaterevisioncb(self, node)
+                    duplicaterevisioncb(self, self.rev(node))
                 empty = False
                 continue
 
@@ -560,12 +560,12 @@
             else:
                 text = mdiff.patch(self.revision(deltabase), delta)
 
-            self._addrawrevision(
+            rev = self._addrawrevision(
                 node, text, transaction, linkrev, p1, p2, flags
             )
 
             if addrevisioncb:
-                addrevisioncb(self, node)
+                addrevisioncb(self, rev)
             empty = False
         return not empty