[3/3] utils: checkstyle.py: Add __repr__ method to Commit class
diff mbox series

Message ID 20240810005840.20841-3-laurent.pinchart@ideasonboard.com
State Accepted
Commit 2d5cea862dbc369d848fb1b745e61a34658c3a0f
Headers show
Series
  • [1/3] utils: checkstyle.py: Rework commit message parsing
Related show

Commit Message

Laurent Pinchart Aug. 10, 2024, 12:58 a.m. UTC
When debugging issues with the Commit class, a __repr__ method proved to
be useful to quickly print all the parsed information about a commit. To
avoid reimplementing the method over and over again in the future, add
it to the class, even if it is not actually used.

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

Comments

Milan Zamazal Aug. 12, 2024, 6:45 a.m. UTC | #1
Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:

> When debugging issues with the Commit class, a __repr__ method proved to
> be useful to quickly print all the parsed information about a commit. To
> avoid reimplementing the method over and over again in the future, add
> it to the class, even if it is not actually used.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Milan Zamazal <mzamazal@redhat.com>

> ---
>  utils/checkstyle.py | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 2b1e1f6c1b9e..c9e41d4149f7 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -248,6 +248,17 @@ class Commit:
>                               stdout=subprocess.PIPE).stdout.decode('utf-8')
>          self._files = [CommitFile(f) for f in ret.splitlines()]
>  
> +    def __repr__(self):
> +        return '\n'.join([
> +            f'commit {self.commit}',
> +            f'Author: {self.author}',
> +            f'',
> +            f'    {self.title}',
> +            '',
> +            '\n'.join([line and f'    {line}' or '' for line in self._body]),
> +            'Trailers:',
> +        ] + self.trailers)
> +
>      def files(self, filter='AMR'):
>          return [f.filename for f in self._files if f.status in filter]
Dan Scally Aug. 12, 2024, 10:47 a.m. UTC | #2
Hi Laurent

On 10/08/2024 01:58, Laurent Pinchart wrote:
> When debugging issues with the Commit class, a __repr__ method proved to
> be useful to quickly print all the parsed information about a commit. To
> avoid reimplementing the method over and over again in the future, add
> it to the class, even if it is not actually used.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---


Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

>   utils/checkstyle.py | 11 +++++++++++
>   1 file changed, 11 insertions(+)
>
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 2b1e1f6c1b9e..c9e41d4149f7 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -248,6 +248,17 @@ class Commit:
>                                stdout=subprocess.PIPE).stdout.decode('utf-8')
>           self._files = [CommitFile(f) for f in ret.splitlines()]
>   
> +    def __repr__(self):
> +        return '\n'.join([
> +            f'commit {self.commit}',
> +            f'Author: {self.author}',
> +            f'',
> +            f'    {self.title}',
> +            '',
> +            '\n'.join([line and f'    {line}' or '' for line in self._body]),
> +            'Trailers:',
> +        ] + self.trailers)
> +
>       def files(self, filter='AMR'):
>           return [f.filename for f in self._files if f.status in filter]
>

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 2b1e1f6c1b9e..c9e41d4149f7 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -248,6 +248,17 @@  class Commit:
                              stdout=subprocess.PIPE).stdout.decode('utf-8')
         self._files = [CommitFile(f) for f in ret.splitlines()]
 
+    def __repr__(self):
+        return '\n'.join([
+            f'commit {self.commit}',
+            f'Author: {self.author}',
+            f'',
+            f'    {self.title}',
+            '',
+            '\n'.join([line and f'    {line}' or '' for line in self._body]),
+            'Trailers:',
+        ] + self.trailers)
+
     def files(self, filter='AMR'):
         return [f.filename for f in self._files if f.status in filter]