[PATCH 3 of 4] changelog: add a `branch` method for direct access to the branch value

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Fri Jan 11 12:17:54 CST 2013


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1357774900 -3600
# Node ID dc2e69dcdb6e477b1cbc15b08a51990de8737b0b
# Parent  0ea0b0c68cbee6d9a257a942eba773f00f696d3a
changelog: add a `branch` method for direct access to the branch value

The only way to access the branch of a changeset is currently to create a
changectx object and access it's `branch()` method. Creating a new python object
is costly and have a huge impact on code doing massive access to `branch()`
(like branchmap).

This changesets introduce a new method on changelog that allows direct access to
the branch of a revision. See the next changeset for impact.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -335,5 +335,12 @@ class changelog(revlog.revlog):
             extra = encodeextra(extra)
             parseddate = "%s %s" % (parseddate, extra)
         l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
         text = "\n".join(l)
         return self.addrevision(text, transaction, len(self), p1, p2)
+
+    def branch(self, rev):
+        """return the branch of a revision
+
+        This function exist because creating a changectx object just to access
+        this is costly."""
+        return encoding.tolocal(self.read(rev)[5].get("branch"))


More information about the Mercurial-devel mailing list