[PATCH V2] parser: fix wrong parsing of diff comments

WEN Pingbo wengpingbo at gmail.com
Mon Sep 26 12:50:23 AEST 2016


Hi, Stephen

I think you missed this patch. But I saw you have already merged
it, maybe it can give you some reference:)

2016-09-05 22:31 GMT+08:00 Pingbo Wen <wengpingbo at gmail.com>:
> From: WEN Pingbo <wengpingbo at gmail.com>
>
> If the subject of a submission is prefixed by 'Re:', then it can't be a
> patch or cover letter.
>
> Signed-off-by: WEN Pingbo <wengpingbo at gmail.com>
> ---
>  patchwork/parser.py | 34 ++++++++++++++++++++++------------
>  1 file changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/patchwork/parser.py b/patchwork/parser.py
> index 1805df8..a4b20a8 100644
> --- a/patchwork/parser.py
> +++ b/patchwork/parser.py
> @@ -303,6 +303,10 @@ def split_prefixes(prefix):
>
>      return [s for s in matches if s != '']
>
> +def subject_check(subject):
> +    comment_re = re.compile(r'^(re)[:\s]\s*', re.I)
> +
> +    return comment_re.match(subject)
>
>  def clean_subject(subject, drop_prefixes=None):
>      """Clean a Subject: header from an incoming patch.
> @@ -620,7 +624,9 @@ def parse_mail(mail, list_id=None):
>
>      msgid = mail.get('Message-Id').strip()
>      author = find_author(mail)
> -    name, prefixes = clean_subject(mail.get('Subject'), [project.linkname])
> +    subject = mail.get('Subject')
> +    name, prefixes = clean_subject(subject, [project.linkname])
> +    is_comment = subject_check(subject)
>      x, n = parse_series_marker(prefixes)
>      refs = find_references(mail)
>      date = find_date(mail)
> @@ -629,7 +635,7 @@ def parse_mail(mail, list_id=None):
>
>      # build objects
>
> -    if diff or pull_url:  # patches or pull requests
> +    if not is_comment and (diff or pull_url):  # patches or pull requests
>          # we delay the saving until we know we have a patch.
>          author.save()
>
> @@ -659,17 +665,18 @@ def parse_mail(mail, list_id=None):
>          # however, we need to see if a match already exists and, if
>          # not, assume that it is indeed a new cover letter
>          is_cover_letter = False
> -        if not refs == []:
> -            try:
> -                CoverLetter.objects.all().get(name=name)
> -            except CoverLetter.DoesNotExist:
> -                # if no match, this is a new cover letter
> +        if not is_comment:
> +            if not refs == []:
> +                try:
> +                    CoverLetter.objects.all().get(name=name)
> +                except CoverLetter.DoesNotExist:
> +                    # if no match, this is a new cover letter
> +                    is_cover_letter = True
> +                except CoverLetter.MultipleObjectsReturned:
> +                    # if multiple cover letters are found, just ignore
> +                    pass
> +            else:
>                  is_cover_letter = True
> -            except CoverLetter.MultipleObjectsReturned:
> -                # if multiple cover letters are found, just ignore
> -                pass
> -        else:
> -            is_cover_letter = True
>
>          if is_cover_letter:
>              author.save()
> @@ -694,6 +701,9 @@ def parse_mail(mail, list_id=None):
>      if not submission:
>          return
>
> +    if is_comment and diff:
> +        message += diff
> +
>      author.save()
>
>      comment = Comment(
> --
> 1.9.1
>


More information about the Patchwork mailing list