[PATCH 03/51] parsemail: Return the list of prefixes when cleaning up the subject

Damien Lespiau damien.lespiau at intel.com
Sat Sep 12 01:54:36 AEST 2015


The patch is a preparation step towards understanding series. It will be
handy to parse those prefixes, looking for 'x/n' to retrieve the order
of a patch in a series.

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
 patchwork/bin/parsemail.py          |  6 +++---
 patchwork/tests/test_patchparser.py | 34 +++++++++++++++++++---------------
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index f2b10bd..fda2960 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -215,7 +215,8 @@ def find_content(project, mail):
     comment = None
 
     if pullurl or patchbuf:
-        name = clean_subject(mail.get('Subject'), [project.linkname])
+        (name, prefixes) = clean_subject(mail.get('Subject'),
+                                         [project.linkname])
         patch = Patch(name = name, pull_url = pullurl, content = patchbuf,
                     date = mail_date(mail), headers = mail_headers(mail))
 
@@ -289,7 +290,6 @@ def clean_subject(subject, drop_prefixes = None):
     in the subject. If drop_prefixes is provided, remove those too,
     comparing case-insensitively."""
 
-
     subject = clean_header(subject)
 
     if drop_prefixes is None:
@@ -322,7 +322,7 @@ def clean_subject(subject, drop_prefixes = None):
     if prefixes:
         subject = '[%s] %s' % (','.join(prefixes), subject)
 
-    return subject
+    return (subject, prefixes)
 
 sig_re = re.compile('^(-- |_+)\n.*', re.S | re.M)
 def clean_content(str):
diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py
index 58689bb..c3d3f9a 100644
--- a/patchwork/tests/test_patchparser.py
+++ b/patchwork/tests/test_patchparser.py
@@ -598,26 +598,30 @@ class PrefixTest(TestCase):
 class SubjectTest(TestCase):
 
     def testCleanSubject(self):
-        self.assertEquals(clean_subject('meep'), 'meep')
-        self.assertEquals(clean_subject('Re: meep'), 'meep')
-        self.assertEquals(clean_subject('[PATCH] meep'), 'meep')
-        self.assertEquals(clean_subject('[PATCH] meep \n meep'), 'meep meep')
-        self.assertEquals(clean_subject('[PATCH RFC] meep'), '[RFC] meep')
-        self.assertEquals(clean_subject('[PATCH,RFC] meep'), '[RFC] meep')
-        self.assertEquals(clean_subject('[PATCH,1/2] meep'), '[1/2] meep')
+        self.assertEquals(clean_subject('meep'), ('meep', []))
+        self.assertEquals(clean_subject('Re: meep'), ('meep', []))
+        self.assertEquals(clean_subject('[PATCH] meep'), ('meep', []))
+        self.assertEquals(clean_subject("[PATCH] meep \n meep"),
+                                        ('meep meep', []))
+        self.assertEquals(clean_subject('[PATCH RFC] meep'),
+                                        ('[RFC] meep', ['RFC']))
+        self.assertEquals(clean_subject('[PATCH,RFC] meep'),
+                                        ('[RFC] meep', ['RFC']))
+        self.assertEquals(clean_subject('[PATCH,1/2] meep'),
+                                        ('[1/2] meep', ['1/2']))
         self.assertEquals(clean_subject('[PATCH RFC 1/2] meep'),
-                                            '[RFC,1/2] meep')
+                                        ('[RFC,1/2] meep', ['RFC', '1/2']))
         self.assertEquals(clean_subject('[PATCH] [RFC] meep'),
-                                            '[RFC] meep')
+                                        ('[RFC] meep', ['RFC']))
         self.assertEquals(clean_subject('[PATCH] [RFC,1/2] meep'),
-                                            '[RFC,1/2] meep')
+                                        ('[RFC,1/2] meep', ['RFC', '1/2']))
         self.assertEquals(clean_subject('[PATCH] [RFC] [1/2] meep'),
-                                            '[RFC,1/2] meep')
+                                        ('[RFC,1/2] meep', ['RFC', '1/2']))
         self.assertEquals(clean_subject('[PATCH] rewrite [a-z] regexes'),
-                                            'rewrite [a-z] regexes')
+                                        ('rewrite [a-z] regexes', []))
         self.assertEquals(clean_subject('[PATCH] [RFC] rewrite [a-z] regexes'),
-                                            '[RFC] rewrite [a-z] regexes')
+                                        ('[RFC] rewrite [a-z] regexes', ['RFC']))
         self.assertEquals(clean_subject('[foo] [bar] meep', ['foo']),
-                                            '[bar] meep')
+                                        ('[bar] meep', ['bar']))
         self.assertEquals(clean_subject('[FOO] [bar] meep', ['foo']),
-                                            '[bar] meep')
+                                        ('[bar] meep', ['bar']))
-- 
2.1.0



More information about the Patchwork mailing list