[PATCH] localrepo: avoid unnecessary conversion from node to rev

Stanislau Hlebik stash at fb.com
Thu Feb 2 10:57:24 UTC 2017


# HG changeset patch
# User Stanislau Hlebik <stash at fb.com>
# Date 1486032998 28800
#      Thu Feb 02 02:56:38 2017 -0800
# Node ID 13a528b72173b1228f6eeb0ffc2346e7b78d1d78
# Parent  abf029200e198878a4576a87e095bd8d77d9cea9
localrepo: avoid unnecessary conversion from node to rev

changelog.heads() first calls headrevs then converts them to nodes.
localrepo.heads() then sorts them using self.changelog.rev function and makes
useless conversion back to revs. Instead let's call changelog.headrevs() from
localrepo.heads(), sort the output and then convert to nodes. Because headrevs
does not support start parameter this optimization only works if start is None.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1852,6 +1852,10 @@
                                   listsubrepos)
 
     def heads(self, start=None):
+        if start is None:
+            headrevs = sorted(self.changelog.headrevs(), reverse=True)
+            return [self.changelog.node(rev) for rev in headrevs]
+
         heads = self.changelog.heads(start)
         # sort the output in rev descending order
         return sorted(heads, key=self.changelog.rev, reverse=True)


More information about the Mercurial-devel mailing list