Patchwork _addset: add a __len__ method

login
register
mail settings
Submitter Pierre-Yves David
Date March 21, 2014, 6:34 p.m.
Message ID <a9cd7e13fd9d5e1a9d5b.1395426846@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4023/
State Accepted
Commit bc95143446e88341be2943253a2ceef76f813a77
Headers show

Comments

Pierre-Yves David - March 21, 2014, 6:34 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1395366928 25200
#      Thu Mar 20 18:55:28 2014 -0700
# Node ID a9cd7e13fd9d5e1a9d5b03f39788a701551a2b29
# Parent  6ca61d24858992759652e869e1b7437402f6f512
_addset: add a __len__ method

Back in the time where repo.revs(...) returned a list, calling `len(...)` on the
result was quite common. We reinstall this on _addset.

There is absolutely no easy way to test this from the command line. The commands
using this in the evolve extension will eventually land into core.
Matt Mackall - March 27, 2014, 1:58 a.m.
On Fri, 2014-03-21 at 11:34 -0700, pierre-yves.david@ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1395366928 25200
> #      Thu Mar 20 18:55:28 2014 -0700
> # Node ID a9cd7e13fd9d5e1a9d5b03f39788a701551a2b29
> # Parent  6ca61d24858992759652e869e1b7437402f6f512
> _addset: add a __len__ method

Queued for default, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2464,10 +2464,13 @@  class _addset(_orderedsetmixin):
         self._r2 = revs2
         self._iter = None
         self._ascending = ascending
         self._genlist = None
 
+    def __len__(self):
+        return len(self._list)
+
     @util.propertycache
     def _list(self):
         if not self._genlist:
             self._genlist = baseset(self._iterator())
         return self._genlist