[PATCH 1 of 2 hglib] util: introduce skiplines

Idan Kamara idankk86 at gmail.com
Thu Aug 11 07:43:11 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1313066578 -10800
# Node ID b7889fc948d3b8bd6c169abf98cbbe56e2e9cef4
# Parent  a38fae6122cde6b75cf7159b512eb43d3141c4d8
util: introduce skiplines

diff -r a38fae6122cd -r b7889fc948d3 hglib/util.py
--- a/hglib/util.py	Thu Aug 11 15:20:49 2011 +0300
+++ b/hglib/util.py	Thu Aug 11 15:42:58 2011 +0300
@@ -24,6 +24,27 @@
             return cs.read()
     return ''
 
+def skiplines(s, prefix):
+    """
+    Skip lines starting with prefix in s
+
+    >>> skiplines('a\\nb\\na\\n', 'a')
+    'b\\na\\n'
+    >>> skiplines('a\\na\\n', 'a')
+    ''
+    >>> skiplines('', 'a')
+    ''
+    >>> skiplines('a\\nb', 'b')
+    'a\\nb'
+    """
+    cs = cStringIO.StringIO(s)
+
+    for line in cs:
+        if not line.startswith(prefix):
+            return line + cs.read()
+
+    return ''
+
 def cmdbuilder(name, *args, **kwargs):
     """
     A helper for building the command arguments


More information about the Mercurial-devel mailing list