[libcamera-devel,v1,3/4] utils: checkstyle: Don't include commit ID in commit title
diff mbox series

Message ID 20230612224751.4437-4-laurent.pinchart@ideasonboard.com
State Accepted
Commit 925ee0ac8ecfd43aa219f6bad04b3b7e90d0b76d
Headers show
Series
  • utils: checkstyle: Add a commit message trailers checker
Related show

Commit Message

Laurent Pinchart June 12, 2023, 10:47 p.m. UTC
The commit title and commit ID are two different pieces of information.
Don't include the latter in the former, to simplify code that only needs
the commit title. Constructing a string from the ID and title is easier
than splitting the combined string back into its elements.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/checkstyle.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Kieran Bingham July 5, 2023, 12:13 a.m. UTC | #1
Quoting Laurent Pinchart via libcamera-devel (2023-06-12 23:47:50)
> The commit title and commit ID are two different pieces of information.
> Don't include the latter in the former, to simplify code that only needs
> the commit title. Constructing a string from the ID and title is easier
> than splitting the combined string back into its elements.

Seems to make sense.

I can see why you wanted to run a single checker to work through this.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  utils/checkstyle.py | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 3104acfa2065..e68c874609bc 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -210,12 +210,12 @@ class Commit:
>  
>      def _parse(self):
>          # Get the commit title and list of files.
> -        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-status',
> +        ret = subprocess.run(['git', 'show', '--format=%s', '--name-status',
>                                self.commit],
>                               stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        files = ret.splitlines()
> -        self._files = [CommitFile(f) for f in files[1:]]
> -        self._title = files[0]
> +        lines = ret.splitlines()
> +        self._files = [CommitFile(f) for f in lines[1:] if f]
> +        self._title = lines[0]
>  
>      def files(self, filter='AMR'):
>          return [f.filename for f in self._files if f.status in filter]
> @@ -358,7 +358,7 @@ class HeaderAddChecker(CommitChecker):
>  
>  
>  class TitleChecker(CommitChecker):
> -    prefix_regex = re.compile(r'[0-9a-f]+ (([a-zA-Z0-9_.-]+: )+)')
> +    prefix_regex = re.compile(r'^([a-zA-Z0-9_.-]+: )+')
>      release_regex = re.compile(r'libcamera v[0-9]+\.[0-9]+\.[0-9]+')
>  
>      @classmethod
> @@ -388,7 +388,7 @@ class TitleChecker(CommitChecker):
>              if not prefix:
>                  continue
>  
> -            prefix = prefix.group(1)
> +            prefix = prefix.group(0)
>              if prefix in prefixes:
>                  prefixes[prefix] += 1
>              else:
> @@ -846,9 +846,10 @@ def check_file(top_level, commit, filename, checkers):
>  
>  
>  def check_style(top_level, commit, checkers):
> -    separator = '-' * len(commit.title)
> +    title = commit.commit + ' ' + commit.title
> +    separator = '-' * len(title)
>      print(separator)
> -    print(commit.title)
> +    print(title)
>      print(separator)
>  
>      issues = 0
> -- 
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 3104acfa2065..e68c874609bc 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -210,12 +210,12 @@  class Commit:
 
     def _parse(self):
         # Get the commit title and list of files.
-        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-status',
+        ret = subprocess.run(['git', 'show', '--format=%s', '--name-status',
                               self.commit],
                              stdout=subprocess.PIPE).stdout.decode('utf-8')
-        files = ret.splitlines()
-        self._files = [CommitFile(f) for f in files[1:]]
-        self._title = files[0]
+        lines = ret.splitlines()
+        self._files = [CommitFile(f) for f in lines[1:] if f]
+        self._title = lines[0]
 
     def files(self, filter='AMR'):
         return [f.filename for f in self._files if f.status in filter]
@@ -358,7 +358,7 @@  class HeaderAddChecker(CommitChecker):
 
 
 class TitleChecker(CommitChecker):
-    prefix_regex = re.compile(r'[0-9a-f]+ (([a-zA-Z0-9_.-]+: )+)')
+    prefix_regex = re.compile(r'^([a-zA-Z0-9_.-]+: )+')
     release_regex = re.compile(r'libcamera v[0-9]+\.[0-9]+\.[0-9]+')
 
     @classmethod
@@ -388,7 +388,7 @@  class TitleChecker(CommitChecker):
             if not prefix:
                 continue
 
-            prefix = prefix.group(1)
+            prefix = prefix.group(0)
             if prefix in prefixes:
                 prefixes[prefix] += 1
             else:
@@ -846,9 +846,10 @@  def check_file(top_level, commit, filename, checkers):
 
 
 def check_style(top_level, commit, checkers):
-    separator = '-' * len(commit.title)
+    title = commit.commit + ' ' + commit.title
+    separator = '-' * len(title)
     print(separator)
-    print(commit.title)
+    print(title)
     print(separator)
 
     issues = 0