[PATCH 3 of 3 hglib] client: implement __iter__ (issue4511)
Yuya Nishihara
yuya at tcha.org
Fri Jul 8 08:42:17 EDT 2016
On Wed, 06 Jul 2016 14:40:14 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1467840878 25200
> # Wed Jul 06 14:34:38 2016 -0700
> # Node ID 36e8e8f994eb6783de296c23f4ea0f1d058af37f
> # Parent 04badaecb6343ca09230b9a8e80ee9e3388e748d
> client: implement __iter__ (issue4511)
>
> The client is a container-like class for changesets. It makes sense
> to implement __iter__ as a way of iterating over every changeset in
> the repo.
>
> The implementation in this patch isn't ideal in terms of performance.
> But it gets the job done.
>
> diff --git a/hglib/client.py b/hglib/client.py
> --- a/hglib/client.py
> +++ b/hglib/client.py
> @@ -1641,8 +1641,19 @@ class hgclient(object):
> check if changeid, which can be either a local revision number or a
> changeset id, matches a changeset in the client.
> """
> try:
> context.changectx(self, changeid)
> return True
> except ValueError:
> return False
> +
> + def __iter__(self):
> + # We query all available nodes up front then obtain a context
> + # for each. This isn't optimal because we have to run a command
> + # for every context.
> + # FUTURE: turn self.log() directly into context instances.
> + args = cmdbuilder(b('log'), template='{node}\\0', r='0:tip')
Needs hidden=self.hidden ?
Other than that, the series LGTM.
More information about the Mercurial-devel
mailing list