[PATCH 3 of 6] 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:52:33 CDT 2009


# HG changeset patch
# User "Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr>
# Date 1249939823 -7200
# Node ID d96e55ca46c55eb2588094295f76270aab51af11
# Parent  2241e777298ae3e7b9cc84096229ae75a4d6c233
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
@@ -167,6 +167,14 @@
                     return True
         return False
 
+    def _hasheader(self, prefixes):
+        '''Check if a header starts with any of the given prefixes.'''
+        for prefix in prefixes:
+            for comment in self.comments:
+                if comment.startswith(prefix):
+                    return True
+        return False
+
     def __str__(self):
         if not self.comments:
             return ''




More information about the Mercurial-devel mailing list