[PATCH 2 of 5] mq: add function to check if a header exists in a patch
Martin Geisler
mg at lazybytes.net
Mon Aug 10 21:16:06 UTC 2009
"Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr> writes:
> # HG changeset patch
> # User "Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr>
> # Date 1249850207 -7200
> # Node ID 3e9fc0157db68b42e4a38437e5b273a8052efe6b
> # Parent 2ba25ea4240e6c8916e35c4f09ba766b179efcdc
> mq: add function to check if a header exists in a patch
>
> Add the private function _hasheader to the class patchheader. This
> function works a bit like the updateheader function, but does no
> replacement. It takes a list of prefixes as argument, and returns true
> if a header in the patch starts with any of the given prefixes, false
> otherwise.
>
> diff --git a/hgext/mq.py b/hgext/mq.py
> --- a/hgext/mq.py
> +++ b/hgext/mq.py
> @@ -169,6 +169,16 @@
> break
> return res
>
> + def _hasheader(self, prefixes):
> + '''Check if a header starts with any of the given prefixes.'''
> + res = False
> + for prefix in prefixes:
> + for i in xrange(len(self.comments)):
> + if self.comments[i].startswith(prefix):
You can loop over self.comments:
for comment in self.comments:
if comments.startswith(prefix)
> + res = True
> + break
> + return res
and then simply 'return True' when you find a comment with the right
prefix, and 'return False' at the end of the function -- no need for the
res variable.
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20090810/315ed9f4/attachment.asc>
More information about the Mercurial-devel
mailing list