git gcc-commit-mklog doesn't extract PR number to ChangeLog

Jakub Jelinek jakub@redhat.com
Thu Jun 10 10:08:51 GMT 2021


On Thu, Jun 10, 2021 at 11:01:49AM +0100, Jonathan Wakely via Gcc wrote:
> On 10/06/21 10:44 +0100, Jonathan Wakely wrote:
> > > Quite interesting idea! Are you willing to prepare a patch for it?
> > 
> > This works.
> 
> And this works better, because it checks the PR in the title matches
> one in the changelog.
> 
> I'll get something added to the tests and prep this for commit.

Note, some commits fix more than one PR.  Sometimes the subject lists
just one of them and the ChangeLog several, at other times people mention
[PRnnnnnn, PRnnnnnn] etc. in the subject.
I think checking that at least one changeLog PR line matches at least one PR
in the subject would be good enough.

Your regex will not match [PR123456, PR123457] in subject, perhaps ok
initially, and if I read it will will be happy if at least one line matches
it.

> diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
> index bd8c1ff7af2..15b602595c4 100755
> --- a/contrib/gcc-changelog/git_commit.py
> +++ b/contrib/gcc-changelog/git_commit.py
> @@ -157,6 +157,7 @@ author_line_regex = \
>  additional_author_regex = re.compile(r'^\t(?P<spaces>\ *)?(?P<name>.*  <.*>)')
>  changelog_regex = re.compile(r'^(?:[fF]or +)?([a-z0-9+-/]*)ChangeLog:?')
>  pr_regex = re.compile(r'\tPR (?P<component>[a-z+-]+\/)?([0-9]+)$')
> +title_pr_regex = re.compile(r' \[PR ?([0-9]+)]$')
>  dr_regex = re.compile(r'\tDR ([0-9]+)$')
>  star_prefix_regex = re.compile(r'\t\*(?P<spaces>\ *)(?P<content>.*)')
>  end_of_location_regex = re.compile(r'[\[<(:]')
> @@ -343,6 +344,7 @@ class GitCommit:
>              self.check_for_broken_parentheses()
>              self.deduce_changelog_locations()
>              self.check_file_patterns()
> +            self.check_pr_consistent()
>              if not self.errors:
>                  self.check_mentioned_files()
>                  self.check_for_correct_changelog()
> @@ -568,6 +570,18 @@ class GitCommit:
>                      msg = 'unsupported wildcard prefix'
>                      self.errors.append(Error(msg, name))
>  
> +    def check_pr_consistent(self):
> +        """Check that a 'PR component/nnn' line is present if the first
> +           line ends with a bug number like [PRnnn] or [PR nnn]."""
> +        title_pr = title_pr_regex.search(self.info.lines[0])
> +        if title_pr:
> +            for line in self.changes:
> +                body_pr = pr_regex.match(line)
> +                if body_pr and body_pr.group(2) == title_pr.group(1):
> +                    return
> +            msg = 'changelog does not contain the PR in the summary:%s'
> +            self.errors.append(Error(msg % title_pr.group()))
> +
>      def check_for_empty_description(self):
>          for entry in self.changelog_entries:
>              for i, line in enumerate(entry.lines):


	Jakub



More information about the Gcc mailing list