[PATCH 1 of 4] revlog: optionally return the text from _addrevision

Gregory Szorc gregory.szorc at gmail.com
Fri Jul 10 00:08:58 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1436484530 25200
#      Thu Jul 09 16:28:50 2015 -0700
# Node ID 9403f12629d5c83ddc9d68dc5f8c2f48c6a895e1
# Parent  648323f41a89619d9eeeb7287213378c340866c8
revlog: optionally return the text from _addrevision

Callers of _addrevision may not pass in the full text. And, since this
method may already calculate it, it makes sense to perform the
computation once instead of having the caller recompute it.

The use case for this will become apparent in a subsequent patch.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1235,15 +1235,20 @@ class revlog(object):
             return ('u', text)
         return ("", bin)
 
     def _addrevision(self, node, text, transaction, link, p1, p2, flags,
-                     cachedelta, ifh, dfh):
+                     cachedelta, ifh, dfh, returntext=False):
         """internal function to add revisions to the log
 
         see addrevision for argument descriptions.
         invariants:
         - text is optional (can be None); if not set, cachedelta must be set.
           if both are set, they must correspond to each other.
+
+        Returns the node of the added revision by default. If ``returntext``
+        is True, returns a tuple of the node and full text of the added
+        revision. This gives callers which passed in cachedelta and not text
+        the ability to access the text without recomputing it.
         """
         btext = [text]
         def buildtext():
             if btext[0] is not None:
@@ -1358,9 +1363,13 @@ class revlog(object):
 
         if type(text) == str: # only accept immutable objects
             self._cache = (node, curr, text)
         self._basecache = (curr, chainbase)
-        return node
+
+        if returntext:
+            return node, buildtext()
+        else:
+            return node
 
     def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset):
         curr = len(self) - 1
         if not self._inline:


More information about the Mercurial-devel mailing list