[PATCH 2 of 5] mq: add function to check if a header exists in a patch

Yann E. MORIN yann.morin.1998 at anciens.enib.fr
Mon Aug 10 16:07:03 CDT 2009


# 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):
+                    res = True
+                    break
+        return res
+
     def __str__(self):
         if not self.comments:
             return ''




More information about the Mercurial-devel mailing list