Submitter | Durham Goode |
---|---|
Date | Nov. 4, 2016, 12:31 a.m. |
Message ID | <7688f9dc22eef566e15a.1478219485@dev111.prn1.facebook.com> |
Download | mbox | patch |
Permalink | /patch/17333/ |
State | Accepted |
Headers | show |
Comments
On Thu, Nov 03, 2016 at 05:31:25PM -0700, Durham Goode wrote: > # HG changeset patch > # User Durham Goode <durham@fb.com> > # Date 1478219474 25200 > # Thu Nov 03 17:31:14 2016 -0700 > # Branch stable > # Node ID 7688f9dc22eef566e15ae0cc57e320d87984b351 > # Parent b9f7b0c10027764cee77f9c6d61877fcffea837f > manifest: add __nonzero__ method Sure, queued, thanks. > > This adds a __nonzero__ method to manifestdict. This isn't strictly necessary in > the vanilla Mercurial implementation, since Python will handle nonzero checks by > using __len__, but having it implemented here makes it easier for alternative > implementations to implement __nonzero__ and have them be plug-n-play with the > normal implementation. > > diff --git a/mercurial/manifest.py b/mercurial/manifest.py > --- a/mercurial/manifest.py > +++ b/mercurial/manifest.py > @@ -422,6 +422,11 @@ class manifestdict(object): > def __len__(self): > return len(self._lm) > > + def __nonzero__(self): > + # nonzero is covered by the __len__ function, but implementing it here > + # makes it easier for extensions to override. > + return len(self._lm) != 0 > + > def __setitem__(self, key, node): > self._lm[key] = node, self.flags(key, '') > > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Patch
diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -422,6 +422,11 @@ class manifestdict(object): def __len__(self): return len(self._lm) + def __nonzero__(self): + # nonzero is covered by the __len__ function, but implementing it here + # makes it easier for extensions to override. + return len(self._lm) != 0 + def __setitem__(self, key, node): self._lm[key] = node, self.flags(key, '')