[PATCH 2 of 6] mq: code simplification/beautification in updateheader

Martin Geisler mg at lazybytes.net
Mon Aug 10 17:05:12 CDT 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 1249940354 -7200
> # Node ID 2241e777298ae3e7b9cc84096229ae75a4d6c233
> # Parent  2ba25ea4240e6c8916e35c4f09ba766b179efcdc
> mq: code simplification/beautification in updateheader
>
> Remove the not-so-usefull temporary variable, and return as soon as we
> know the result.
>
> diff --git a/hgext/mq.py b/hgext/mq.py
> --- a/hgext/mq.py
> +++ b/hgext/mq.py
> @@ -160,14 +160,12 @@
>      def updateheader(self, prefixes, new):
>          '''Update all references to a field in the patch header.
>          Return whether the field is present.'''
> -        res = False
>          for prefix in prefixes:
>              for i in xrange(len(self.comments)):
>                  if self.comments[i].startswith(prefix):
>                      self.comments[i] = prefix + new
> -                    res = True
> -                    break
> -        return res
> +                    return True
> +        return False

I'm not an expert on the mq code, but I think the old code was
necessary: it updates *all* comments that begin with *any* of the
prefixes. So a call like

  self.updateheader(['From: ', '# User '], user)

will update both the email-like header and the patch header. Your code
will exit after updating just one of the headers.

Good thing you put this in a separate patch :-) -- now Dirkjan can just
simply skip it when he applies them.

-- 
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://selenic.com/pipermail/mercurial-devel/attachments/20090811/47c85bfd/attachment.pgp 


More information about the Mercurial-devel mailing list