[PATCH 40/46] patch: Single out the commit message
Jeremy Kerr
jk at ozlabs.org
Mon Nov 10 23:55:17 AEDT 2014
Hi Damien,
> All 'Comments' are stored the same way in the db, but I believe it's
> worth making the distinction between introducing what the patch does and
> eventual review comments.
>
> Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
> ---
> apps/patchwork/models.py | 11 ++++++++++-
> templates/patchwork/patch.html | 18 +++++++++++++++++-
> 2 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
> index 4bed9b8..b9c7794 100644
> --- a/apps/patchwork/models.py
> +++ b/apps/patchwork/models.py
> @@ -188,7 +188,16 @@ class Patch(models.Model):
> return self.name
>
> def comments(self):
> - return Comment.objects.filter(patch = self)
> + comments = Comment.objects.filter(patch = self)
> + # len() will trigger a queryset evaluation. That's what we want as
> + # we need the full list of comments. That the list is then sliced into
> + # (commit message, list of followup comments) won't hit the db twice.
> + n_comments = len(comments)
> + if n_comments > 2:
> + return (comments[0], comments[1:])
> + if n_comments == 1:
> + return (comments[0], ())
> + return (None, ())
This doesn't guarantee that you'll pick the correct comment for the
commit message - you need to find the comment that has the same
message-id as the patch.
Also, could we have this as a separate function? I'd like to
Patch.comments() for the complete set as a single list. Your template
might be a bit cleaner if have separate functions for
commit-message-comments and follow-up-comments too.
Cheers,
Jeremy
More information about the Patchwork
mailing list