[libcamera-devel,3/8] utils: checkstyle.py: Move commit handling to a separate section
diff mbox series

Message ID 20201224122855.22200-4-laurent.pinchart@ideasonboard.com
State Accepted
Delegated to: Laurent Pinchart
Headers show
Series
  • checkstyle.py: Ensure meson.build is updated when adding header
Related show

Commit Message

Laurent Pinchart Dec. 24, 2020, 12:28 p.m. UTC
To prepare for checkers that operate directly on commits, move the
related classes to a separate section. No functional change is included.

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

Comments

Niklas Söderlund Dec. 27, 2020, 10:31 a.m. UTC | #1
Hi Laurent,

Thanks for your patch.

On 2020-12-24 14:28:50 +0200, Laurent Pinchart wrote:
> To prepare for checkers that operate directly on commits, move the
> related classes to a separate section. No functional change is included.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I trust you that none of the code moved is modified ;-)

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  utils/checkstyle.py | 120 +++++++++++++++++++++++---------------------
>  1 file changed, 62 insertions(+), 58 deletions(-)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 76267d5ea764..4ba65e5a4ff1 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -190,6 +190,68 @@ def parse_diff(diff):
>      return hunks
>  
>  
> +# ------------------------------------------------------------------------------
> +# Commit, Staged Changes & Amendments
> +#
> +
> +class Commit:
> +    def __init__(self, commit):
> +        self.commit = commit
> +
> +    def get_info(self):
> +        # Get the commit title and list of files.
> +        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',
> +                              self.commit],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        files = ret.splitlines()
> +        # Returning title and files list as a tuple
> +        return files[0], files[1:]
> +
> +    def get_diff(self, top_level, filename):
> +        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
> +                               '--', '%s/%s' % (top_level, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +    def get_file(self, filename):
> +        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +
> +class StagedChanges(Commit):
> +    def __init__(self):
> +        Commit.__init__(self, '')
> +
> +    def get_info(self):
> +        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        return "Staged changes", ret.splitlines()
> +
> +    def get_diff(self, top_level, filename):
> +        return subprocess.run(['git', 'diff', '--staged', '--',
> +                               '%s/%s' % (top_level, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +
> +class Amendment(StagedChanges):
> +    def __init__(self):
> +        StagedChanges.__init__(self)
> +
> +    def get_info(self):
> +        # Create a title using HEAD commit
> +        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        title = 'Amendment of ' + ret.strip()
> +        # Extract the list of modified files
> +        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        return title, ret.splitlines()
> +
> +    def get_diff(self, top_level, filename):
> +        return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
> +                               '%s/%s' % (top_level, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +
>  # ------------------------------------------------------------------------------
>  # Helpers
>  #
> @@ -564,64 +626,6 @@ class StripTrailingSpaceFormatter(Formatter):
>  # Style checking
>  #
>  
> -class Commit:
> -    def __init__(self, commit):
> -        self.commit = commit
> -
> -    def get_info(self):
> -        # Get the commit title and list of files.
> -        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',
> -                              self.commit],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        files = ret.splitlines()
> -        # Returning title and files list as a tuple
> -        return files[0], files[1:]
> -
> -    def get_diff(self, top_level, filename):
> -        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
> -                               '--', '%s/%s' % (top_level, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -    def get_file(self, filename):
> -        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -
> -class StagedChanges(Commit):
> -    def __init__(self):
> -        Commit.__init__(self, '')
> -
> -    def get_info(self):
> -        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        return "Staged changes", ret.splitlines()
> -
> -    def get_diff(self, top_level, filename):
> -        return subprocess.run(['git', 'diff', '--staged', '--',
> -                               '%s/%s' % (top_level, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -
> -class Amendment(StagedChanges):
> -    def __init__(self):
> -        StagedChanges.__init__(self)
> -
> -    def get_info(self):
> -        # Create a title using HEAD commit
> -        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        title = 'Amendment of ' + ret.strip()
> -        # Extract the list of modified files
> -        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        return title, ret.splitlines()
> -
> -    def get_diff(self, top_level, filename):
> -        return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
> -                               '%s/%s' % (top_level, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -
>  def check_file(top_level, commit, filename):
>      # Extract the line numbers touched by the commit.
>      diff = commit.get_diff(top_level, filename)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Paul Elder Dec. 28, 2020, 5:15 a.m. UTC | #2
Hi Laurent,

On Thu, Dec 24, 2020 at 02:28:50PM +0200, Laurent Pinchart wrote:
> To prepare for checkers that operate directly on commits, move the
> related classes to a separate section. No functional change is included.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  utils/checkstyle.py | 120 +++++++++++++++++++++++---------------------
>  1 file changed, 62 insertions(+), 58 deletions(-)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 76267d5ea764..4ba65e5a4ff1 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -190,6 +190,68 @@ def parse_diff(diff):
>      return hunks
>  
>  
> +# ------------------------------------------------------------------------------
> +# Commit, Staged Changes & Amendments
> +#
> +
> +class Commit:
> +    def __init__(self, commit):
> +        self.commit = commit
> +
> +    def get_info(self):
> +        # Get the commit title and list of files.
> +        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',
> +                              self.commit],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        files = ret.splitlines()
> +        # Returning title and files list as a tuple
> +        return files[0], files[1:]
> +
> +    def get_diff(self, top_level, filename):
> +        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
> +                               '--', '%s/%s' % (top_level, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +    def get_file(self, filename):
> +        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +
> +class StagedChanges(Commit):
> +    def __init__(self):
> +        Commit.__init__(self, '')
> +
> +    def get_info(self):
> +        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        return "Staged changes", ret.splitlines()
> +
> +    def get_diff(self, top_level, filename):
> +        return subprocess.run(['git', 'diff', '--staged', '--',
> +                               '%s/%s' % (top_level, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +
> +class Amendment(StagedChanges):
> +    def __init__(self):
> +        StagedChanges.__init__(self)
> +
> +    def get_info(self):
> +        # Create a title using HEAD commit
> +        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        title = 'Amendment of ' + ret.strip()
> +        # Extract the list of modified files
> +        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],
> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> +        return title, ret.splitlines()
> +
> +    def get_diff(self, top_level, filename):
> +        return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
> +                               '%s/%s' % (top_level, filename)],
> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> +
> +
>  # ------------------------------------------------------------------------------
>  # Helpers
>  #
> @@ -564,64 +626,6 @@ class StripTrailingSpaceFormatter(Formatter):
>  # Style checking
>  #
>  
> -class Commit:
> -    def __init__(self, commit):
> -        self.commit = commit
> -
> -    def get_info(self):
> -        # Get the commit title and list of files.
> -        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',
> -                              self.commit],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        files = ret.splitlines()
> -        # Returning title and files list as a tuple
> -        return files[0], files[1:]
> -
> -    def get_diff(self, top_level, filename):
> -        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
> -                               '--', '%s/%s' % (top_level, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -    def get_file(self, filename):
> -        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -
> -class StagedChanges(Commit):
> -    def __init__(self):
> -        Commit.__init__(self, '')
> -
> -    def get_info(self):
> -        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        return "Staged changes", ret.splitlines()
> -
> -    def get_diff(self, top_level, filename):
> -        return subprocess.run(['git', 'diff', '--staged', '--',
> -                               '%s/%s' % (top_level, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -
> -class Amendment(StagedChanges):
> -    def __init__(self):
> -        StagedChanges.__init__(self)
> -
> -    def get_info(self):
> -        # Create a title using HEAD commit
> -        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        title = 'Amendment of ' + ret.strip()
> -        # Extract the list of modified files
> -        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],
> -                             stdout=subprocess.PIPE).stdout.decode('utf-8')
> -        return title, ret.splitlines()
> -
> -    def get_diff(self, top_level, filename):
> -        return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
> -                               '%s/%s' % (top_level, filename)],
> -                              stdout=subprocess.PIPE).stdout.decode('utf-8')
> -
> -
>  def check_file(top_level, commit, filename):
>      # Extract the line numbers touched by the commit.
>      diff = commit.get_diff(top_level, filename)
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 76267d5ea764..4ba65e5a4ff1 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -190,6 +190,68 @@  def parse_diff(diff):
     return hunks
 
 
+# ------------------------------------------------------------------------------
+# Commit, Staged Changes & Amendments
+#
+
+class Commit:
+    def __init__(self, commit):
+        self.commit = commit
+
+    def get_info(self):
+        # Get the commit title and list of files.
+        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',
+                              self.commit],
+                             stdout=subprocess.PIPE).stdout.decode('utf-8')
+        files = ret.splitlines()
+        # Returning title and files list as a tuple
+        return files[0], files[1:]
+
+    def get_diff(self, top_level, filename):
+        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
+                               '--', '%s/%s' % (top_level, filename)],
+                              stdout=subprocess.PIPE).stdout.decode('utf-8')
+
+    def get_file(self, filename):
+        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
+                              stdout=subprocess.PIPE).stdout.decode('utf-8')
+
+
+class StagedChanges(Commit):
+    def __init__(self):
+        Commit.__init__(self, '')
+
+    def get_info(self):
+        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],
+                             stdout=subprocess.PIPE).stdout.decode('utf-8')
+        return "Staged changes", ret.splitlines()
+
+    def get_diff(self, top_level, filename):
+        return subprocess.run(['git', 'diff', '--staged', '--',
+                               '%s/%s' % (top_level, filename)],
+                              stdout=subprocess.PIPE).stdout.decode('utf-8')
+
+
+class Amendment(StagedChanges):
+    def __init__(self):
+        StagedChanges.__init__(self)
+
+    def get_info(self):
+        # Create a title using HEAD commit
+        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'],
+                             stdout=subprocess.PIPE).stdout.decode('utf-8')
+        title = 'Amendment of ' + ret.strip()
+        # Extract the list of modified files
+        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],
+                             stdout=subprocess.PIPE).stdout.decode('utf-8')
+        return title, ret.splitlines()
+
+    def get_diff(self, top_level, filename):
+        return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
+                               '%s/%s' % (top_level, filename)],
+                              stdout=subprocess.PIPE).stdout.decode('utf-8')
+
+
 # ------------------------------------------------------------------------------
 # Helpers
 #
@@ -564,64 +626,6 @@  class StripTrailingSpaceFormatter(Formatter):
 # Style checking
 #
 
-class Commit:
-    def __init__(self, commit):
-        self.commit = commit
-
-    def get_info(self):
-        # Get the commit title and list of files.
-        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',
-                              self.commit],
-                             stdout=subprocess.PIPE).stdout.decode('utf-8')
-        files = ret.splitlines()
-        # Returning title and files list as a tuple
-        return files[0], files[1:]
-
-    def get_diff(self, top_level, filename):
-        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
-                               '--', '%s/%s' % (top_level, filename)],
-                              stdout=subprocess.PIPE).stdout.decode('utf-8')
-
-    def get_file(self, filename):
-        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
-                              stdout=subprocess.PIPE).stdout.decode('utf-8')
-
-
-class StagedChanges(Commit):
-    def __init__(self):
-        Commit.__init__(self, '')
-
-    def get_info(self):
-        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],
-                             stdout=subprocess.PIPE).stdout.decode('utf-8')
-        return "Staged changes", ret.splitlines()
-
-    def get_diff(self, top_level, filename):
-        return subprocess.run(['git', 'diff', '--staged', '--',
-                               '%s/%s' % (top_level, filename)],
-                              stdout=subprocess.PIPE).stdout.decode('utf-8')
-
-
-class Amendment(StagedChanges):
-    def __init__(self):
-        StagedChanges.__init__(self)
-
-    def get_info(self):
-        # Create a title using HEAD commit
-        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'],
-                             stdout=subprocess.PIPE).stdout.decode('utf-8')
-        title = 'Amendment of ' + ret.strip()
-        # Extract the list of modified files
-        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],
-                             stdout=subprocess.PIPE).stdout.decode('utf-8')
-        return title, ret.splitlines()
-
-    def get_diff(self, top_level, filename):
-        return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
-                               '%s/%s' % (top_level, filename)],
-                              stdout=subprocess.PIPE).stdout.decode('utf-8')
-
-
 def check_file(top_level, commit, filename):
     # Extract the line numbers touched by the commit.
     diff = commit.get_diff(top_level, filename)