# HG changeset patch # User Idan Kamara # Date 1313066578 -10800 # Node ID 19d2c55c3928a51e782e0e92b2625ed3ddf385a9 # Parent 518149e328889a5cada37293f8d399540bb6a766 util: introduce skiplines diff -r 518149e32888 -r 19d2c55c3928 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