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

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 11, 2013, 6:17 p.m.
Message ID <dc2e69dcdb6e477b1cbc.1357928274@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/544/
State Accepted
Headers show

Comments

Pierre-Yves David - Jan. 11, 2013, 6:17 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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"))