Patchwork D9882: revlog: change addrevision to return the new revision, not node

login
register
mail settings
Submitter phabricator
Date Jan. 27, 2021, 2:11 a.m.
Message ID <differential-rev-PHID-DREV-x5prdtbzelbvfaytymez-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48194/
State Superseded
Headers show

Comments

phabricator - Jan. 27, 2021, 2:11 a.m.
joerg.sonnenberger created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9882

AFFECTED FILES
  mercurial/changelog.py
  mercurial/filelog.py
  mercurial/interfaces/repository.py
  mercurial/manifest.py
  mercurial/revlog.py

CHANGE DETAILS




To: joerg.sonnenberger, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2111,13 +2111,14 @@ 
             )
 
         node = node or self.hash(rawtext, p1, p2)
-        if self.index.has_node(node):
-            return node
+        rev = self.index.get_rev(node)
+        if rev is not None:
+            return rev
 
         if validatehash:
             self.checkhash(rawtext, node, p1=p1, p2=p2)
 
-        rev = self.addrawrevision(
+        return self.addrawrevision(
             rawtext,
             transaction,
             link,
@@ -2128,7 +2129,6 @@ 
             cachedelta=cachedelta,
             deltacomputer=deltacomputer,
         )
-        return node
 
     def addrawrevision(
         self,
diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1704,9 +1704,10 @@ 
             arraytext, deltatext = m.fastdelta(self.fulltextcache[p1], work)
             cachedelta = self._revlog.rev(p1), deltatext
             text = util.buffer(arraytext)
-            n = self._revlog.addrevision(
+            rev = self._revlog.addrevision(
                 text, transaction, link, p1, p2, cachedelta
             )
+            n = self._revlog.node(rev)
         except FastdeltaUnavailable:
             # The first parent manifest isn't already loaded or the
             # manifest implementation doesn't support fastdelta, so
@@ -1724,7 +1725,8 @@ 
                 arraytext = None
             else:
                 text = m.text()
-                n = self._revlog.addrevision(text, transaction, link, p1, p2)
+                rev = self._revlog.addrevision(text, transaction, link, p1, p2)
+                n = self._revlog.node(rev)
                 arraytext = bytearray(text)
 
         if arraytext is not None:
@@ -1765,9 +1767,10 @@ 
                 n = m2.node()
 
         if not n:
-            n = self._revlog.addrevision(
+            rev = self._revlog.addrevision(
                 text, transaction, link, m1.node(), m2.node()
             )
+            n = self._revlog.node(rev)
 
         # Save nodeid so parent manifest can calculate its nodeid
         m.setnode(n)
diff --git a/mercurial/interfaces/repository.py b/mercurial/interfaces/repository.py
--- a/mercurial/interfaces/repository.py
+++ b/mercurial/interfaces/repository.py
@@ -734,7 +734,7 @@ 
         flags=0,
         cachedelta=None,
     ):
-        """Add a new revision to the store.
+        """Add a new revision to the store and return its number.
 
         This is similar to ``add()`` except it operates at a lower level.
 
diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -176,7 +176,8 @@ 
     def add(self, text, meta, transaction, link, p1=None, p2=None):
         if meta or text.startswith(b'\1\n'):
             text = storageutil.packmeta(meta, text)
-        return self.addrevision(text, transaction, link, p1, p2)
+        rev = self.addrevision(text, transaction, link, p1, p2)
+        return self.node(rev)
 
     def renamed(self, node):
         return storageutil.filerevisioncopied(self, node)
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -598,9 +598,10 @@ 
             parseddate = b"%s %s" % (parseddate, extra)
         l = [hex(manifest), user, parseddate] + sortedfiles + [b"", desc]
         text = b"\n".join(l)
-        return self.addrevision(
+        rev = self.addrevision(
             text, transaction, len(self), p1, p2, sidedata=sidedata, flags=flags
         )
+        return self.node(rev)
 
     def branchinfo(self, rev):
         """return the branch name and open/close state of a revision