changelog: move branchinfo to changelogrevision
authorJoerg Sonnenberger <joerg@bec.de>
Fri, 15 Jan 2021 01:30:08 +0100
changeset 46370 cad17d50736c
parent 46369 cabc5e9366c5
child 46371 0903d6b9b1df
changelog: move branchinfo to changelogrevision The function parses the extra dictionary after looking up the changelogrevision. To avoid duplicated look up, it is better to provide it as property of changelogrevision instead. Keep the function for a release cycle as at least the topic extension depends on it. Differential Revision: https://phab.mercurial-scm.org/D9779
mercurial/changelog.py
relnotes/next
--- a/mercurial/changelog.py	Fri Jan 22 11:10:39 2021 +0100
+++ b/mercurial/changelog.py	Fri Jan 15 01:30:08 2021 +0100
@@ -200,6 +200,7 @@
     p1copies = attr.ib(default=None)
     p2copies = attr.ib(default=None)
     description = attr.ib(default=b'')
+    branchinfo = attr.ib(default=(_defaultextra[b'branch'], False))
 
 
 class changelogrevision(object):
@@ -372,6 +373,11 @@
     def description(self):
         return encoding.tolocal(self._text[self._offsets[3] + 2 :])
 
+    @property
+    def branchinfo(self):
+        extra = self.extra
+        return encoding.tolocal(extra.get(b"branch")), b'close' in extra
+
 
 class changelog(revlog.revlog):
     def __init__(self, opener, trypending=False):
@@ -601,8 +607,7 @@
 
         This function exists because creating a changectx object
         just to access this is costly."""
-        extra = self.changelogrevision(rev).extra
-        return encoding.tolocal(extra.get(b"branch")), b'close' in extra
+        return self.changelogrevision(rev).branchinfo
 
     def _nodeduplicatecallback(self, transaction, node):
         # keep track of revisions that got "re-added", eg: unbunde of know rev.
--- a/relnotes/next	Fri Jan 22 11:10:39 2021 +0100
+++ b/relnotes/next	Fri Jan 15 01:30:08 2021 +0100
@@ -65,4 +65,5 @@
 
 == Internal API Changes ==
 
-
+ * `changelog.branchinfo` is deprecated and will be removed after 5.8.
+   It is superseded by `changelogrevision.branchinfo`.