Permalink
Browse files

utils: Do not word-wrap sign-offs and special tags

Teach the word-wrapper to skip over lines that look like sign-offs,
which is basically any line that starts with a string of letters and
dashes followed by a colon.  Other popular tags are things like
"Acked-by:", "Helped-by:", etc.  We support all of these.

If we're going to have our own word-wrapping function then we
might as well do something useful with it ;-)

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information...
1 parent 1bda070 commit d0ee6d1e0b77ea03645ce6701b1ff48a93cff653 @davvid davvid committed Sep 18, 2012
Showing with 28 additions and 0 deletions.
  1. +5 −0 cola/utils.py
  2. +23 −0 test/test_cola_utils.py
View
@@ -257,7 +257,12 @@ def word_wrap(text, tabwidth, limit):
"""
lines = []
+ # Acked-by:, Signed-off-by:, Helped-by:, etc.
+ special_tag_rgx = re.compile('^[a-zA-Z-]+:')
for line in text.split('\n'):
+ if special_tag_rgx.match(line):
+ lines.append(line)
+ continue
linelen = 0
words = []
for idx, word in enumerate(line.split(' ')):
View
@@ -108,6 +108,29 @@ def test_word_wrap_spaces(self):
text = ' ' * 6
self.assertEqual(' \n \n', self.wrap(text))
+ def test_word_wrap_special_tag(self):
+ self.limit = 2
+ text = """
+This test is so meta, even this sentence
+
+With-special-tag: Avoids word-wrap
+"""
+
+ expect = """
+This
+test
+is
+so
+meta,
+even
+this
+sentence
+
+With-special-tag: Avoids word-wrap
+"""
+
+ self.assertEqual(self.wrap(text), expect)
+
if __name__ == '__main__':
unittest.main()

0 comments on commit d0ee6d1

Please sign in to comment.