Patchwork [2,of,2] obsstore: add a __len__ method

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 27, 2014, 3:28 a.m.
Message ID <493182544d3d1f5699c5.1393471703@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3784/
State Accepted
Commit f3c8db3d6d66550b050e02b592c84e3705b9f899
Headers show

Comments

Pierre-Yves David - Feb. 27, 2014, 3:28 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1393353174 28800
#      Tue Feb 25 10:32:54 2014 -0800
# Node ID 493182544d3d1f5699c5e3e5e74c7e3b3001fc9d
# Parent  2553363489703ae22fbdb3b979be0bd34d9370c5
obsstore: add a __len__ method

We can already use "for mark in store:" it make sense to allow
"len(store)" too.

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -245,10 +245,13 @@  class obsstore(object):
             self._load(_readmarkers(data))
 
     def __iter__(self):
         return iter(self._all)
 
+    def __len__(self):
+        return len(self._all)
+
     def __nonzero__(self):
         return bool(self._all)
 
     def create(self, transaction, prec, succs=(), flag=0, metadata=None):
         """obsolete: add a new obsolete marker