From: Stephen Finucane Date: Wed, 28 Jun 2017 19:53:58 +0000 (+0100) Subject: parser: Support single-patch "series" X-Git-Tag: v2.0.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=736426930ba4252b23375a8c60fba20c39187393;p=thirdparty%2Fpatchwork.git parser: Support single-patch "series" There are merits to supporting single-patch series, not least the ability to provide two consistent interfaces that show _all_ patches in the '/patches' endpoint and the '/series' endpoint. Signed-off-by: Stephen Finucane Reviewed-by: Sean Farley --- diff --git a/patchwork/parser.py b/patchwork/parser.py index aa5ac589..b6c8047d 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -903,15 +903,20 @@ def parse_mail(mail, list_id=None): filenames = find_filenames(diff) delegate = find_delegate_by_filename(project, filenames) - series = find_series(project, mail) + # if we don't have a series marker, we will never have an existing + # series to match against. + series = None + if n: + series = find_series(project, mail) + else: + x = n = 1 + # We will create a new series if: - # - we have a patch number (x of n), and - # - either: - # * there is no series, or - # * we have a patch with this number already - if n and ((not series) or - (SeriesPatch.objects.filter(series=series, number=x).count() - )): + # - there is no existing series to assign this patch to, or + # - there is an existing series, but it already has a patch with this + # number in it + if not series or ( + SeriesPatch.objects.filter(series=series, number=x).count()): series = Series(project=project, date=date, submitter=author, diff --git a/patchwork/tests/series/base-single-patch.mbox b/patchwork/tests/series/base-single-patch.mbox new file mode 100644 index 00000000..a47c3cf8 --- /dev/null +++ b/patchwork/tests/series/base-single-patch.mbox @@ -0,0 +1,34 @@ +From stephenfinucane@gmail.com Sun Sep 11 23:22:13 2016 +Return-Path: +From: Stephen Finucane +To: stephenfinucane@hotmail.com +Subject: [PATCH] test: Add some lorem ipsum +Date: Sun, 11 Sep 2016 23:22:03 +0100 +Message-ID: <1473632524-8585-2-git-send-email-stephenfinucane@gmail.com> +X-Mailer: git-send-email 2.7.4 +MIME-Version: 1.0 +Content-Type: text/plain +Content-Length: 670 +Lines: 22 + +From: Stephen Finucane + +--- + test.txt | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/test.txt b/test.txt +index f75ba05..a6c61c0 100644 +--- a/test.txt ++++ b/test.txt +@@ -1 +1,8 @@ + Hello, world. ++ ++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend ++augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris. ++Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus ++id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus ++eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet ++tellus commodo bibendum ut vel dolor. +-- +2.7.4 diff --git a/patchwork/tests/series/revision-threaded-to-single-patch.mbox b/patchwork/tests/series/revision-threaded-to-single-patch.mbox new file mode 100644 index 00000000..1e7b952a --- /dev/null +++ b/patchwork/tests/series/revision-threaded-to-single-patch.mbox @@ -0,0 +1,85 @@ +From stephenfinucane@gmail.com Sun Sep 11 23:22:13 2016 +Return-Path: +From: Stephen Finucane +To: stephenfinucane@hotmail.com +Subject: [PATCH] test: Add some lorem ipsum +Date: Sun, 11 Sep 2016 23:22:03 +0100 +Message-ID: <1473632524-8585-2-git-send-email-stephenfinucane@gmail.com> +X-Mailer: git-send-email 2.7.4 +MIME-Version: 1.0 +Content-Type: text/plain +Content-Length: 670 +Lines: 22 + +From: Stephen Finucane + +--- + test.txt | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/test.txt b/test.txt +index f75ba05..a6c61c0 100644 +--- a/test.txt ++++ b/test.txt +@@ -1 +1,8 @@ + Hello, world. ++ ++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend ++augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris. ++Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus ++id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus ++eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet ++tellus commodo bibendum ut vel dolor. +-- +2.7.4 + + +From stephenfinucane@gmail.com Sun Sep 11 23:31:04 2016 +Return-Path: +From: Stephen Finucane +To: stephenfinucane@hotmail.com +Subject: [PATCH v2] test: Add some lorem ipsum +Date: Sun, 11 Sep 2016 23:30:54 +0100 +Message-ID: <1473633055-10316-2-git-send-email-stephenfinucane@gmail.com> +X-Mailer: git-send-email 2.7.4 +In-Reply-To: <1473632524-8585-2-git-send-email-stephenfinucane@gmail.com> +References: <1473632524-8585-2-git-send-email-stephenfinucane@gmail.com> +MIME-Version: 1.0 +Content-Type: text/plain +Content-Length: 1363 +Lines: 35 + +From: Stephen Finucane + +This is a better commit message. +--- +v2: +- Add some additional content +--- + test.txt | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/test.txt b/test.txt +index f75ba05..4478ac2 100644 +--- a/test.txt ++++ b/test.txt +@@ -1 +1,17 @@ + Hello, world. ++ ++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eleifend ++augue. Nullam at metus venenatis, laoreet neque nec, convallis mauris. ++Pellentesque aliquam at nisi et laoreet. Duis non nisl venenatis, rhoncus risus ++id, elementum felis. In hac habitasse platea dictumst. Nam sit amet maximus ++eros. Nam quis ligula ut tortor egestas bibendum. Nunc sed purus sit amet ++tellus commodo bibendum ut vel dolor. ++ ++Curabitur scelerisque tempus efficitur. Maecenas aliquet elementum quam, ac ++pharetra nisi gravida a. Nam vitae malesuada leo. Nam accumsan facilisis metus ++sed vulputate. Ut libero odio, tempor ac posuere vel, malesuada quis ex. Donec ++interdum ipsum et nibh molestie auctor eget in neque. Sed nec hendrerit enim. ++Etiam scelerisque non magna eu molestie. Maecenas dui quam, tempor quis ipsum ++eu, dapibus congue dui. Integer tincidunt accumsan tortor sed maximus. Praesent ++eu magna accumsan, consequat turpis quis, fringilla ante. Vestibulum nec ++maximus nulla. Donec vehicula nisl at pharetra eleifend. +-- +2.7.4 diff --git a/patchwork/tests/test_series.py b/patchwork/tests/test_series.py index 390ee519..c1ede069 100644 --- a/patchwork/tests/test_series.py +++ b/patchwork/tests/test_series.py @@ -94,6 +94,20 @@ class _BaseTestCase(TestCase): class BaseSeriesTest(_BaseTestCase): """Tests for a series without any revisions.""" + def test_single_patch(self): + """Series with only a single patch. + + Parse a "series" with only a single patch and no subject prefixes. + + Input: + + - [PATCH] test: Add some lorem ipsum + """ + _, patches, _ = self._parse_mbox( + 'base-single-patch.mbox', [0, 1, 0]) + + self.assertSerialized(patches, [1]) + def test_cover_letter(self): """Series with a cover letter. @@ -291,6 +305,21 @@ class RevisedSeriesTest(_BaseTestCase): self.assertSerialized(patches, [2, 2]) self.assertSerialized(covers, [1, 1]) + def test_threaded_to_single_patch(self): + """Series with a revision sent in-reply-to a single-patch series. + + Parse a series with a single patch, followed by a second revision of + the same. The second revision is correctly labeled but is sent in reply + to the original patch. + + - [PATCH] test: Add some lorem ipsum + - [PATCH v2] test: Add some lorem ipsum + """ + _, patches, _ = self._parse_mbox( + 'revision-threaded-to-single-patch.mbox', [0, 2, 0]) + + self.assertSerialized(patches, [1, 1]) + def test_threaded_to_cover(self): """Series with a revision sent in-reply-to a cover. @@ -427,8 +456,8 @@ class RevisedSeriesTest(_BaseTestCase): """Series with a reply with a diff but no number. The random message with the diff should not belong to the - series, as it lacks a n/N label. We expect 1 series and the - random message to be orphaned. + series, as it lacks a n/N label. We expect two series and the + random message to be assigned its own series. Input: @@ -439,9 +468,8 @@ class RevisedSeriesTest(_BaseTestCase): covers, patches, _ = self._parse_mbox( 'bugs-unnumbered.mbox', [1, 2, 0]) - self.assertEqual(len([p for p in patches if p.latest_series]), 1) - self.assertEqual(len([p for p in patches if not p.latest_series]), 1) - self.assertSerialized(covers, [1]) + self.assertSerialized(patches, [1, 1]) + self.assertSerialized(covers, [1, 0]) def test_reply_nocover_noversion(self): """Series with a revision sent without a version label or cover