[PATCH V2] localrepo: avoid unnecessary conversion from node to rev
Jun Wu
quark at fb.com
Tue Feb 7 16:11:23 EST 2017
V1 was accepted and in hg-committed [1] already. I don't know the official
recommended workflows but I used to just push follow-up fixes.
In general, it's a good practice to use hg-committed instead of the hg repo
for development, to avoid potential conflicts with other changes.
[1]: https://www.mercurial-scm.org/repo/hg-committed/rev/1791be8a95c5
Excerpts from Stanislau Hlebik's message of 2017-02-07 00:52:13 -0800:
> # HG changeset patch
> # User Stanislau Hlebik <stash at fb.com>
> # Date 1486457478 28800
> # Tue Feb 07 00:51:18 2017 -0800
> # Node ID 8614d5d15d6fe47c3bcfdf79823f68f18c7741ae
> # Parent 1f51b4658f21bbb797e922d155c1046eddccf91d
> 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 = reversed(self.changelog.headrevs())
> + 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