[{"id":3506,"web_url":"https://patchwork.libcamera.org/comment/3506/","msgid":"<20200118175349.GB5095@pendragon.ideasonboard.com>","date":"2020-01-18T17:53:49","subject":"Re: [libcamera-devel] [PATCH v3 3/6] checkstyle: Introduce a Commit\n\tclass","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nicolas,\n\nThank you for the patch.\n\nOn Fri, Jan 17, 2020 at 10:54:45PM -0500, Nicolas Dufresne wrote:\n> From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> \n> This introduce a Commit class used in the final revlist list. All the\n\ns/introduce/introduces/\n\n> git command are moved into that class. This class will be used to\n\ns/command/commands/\n\n> introduce new type of commit (StagedChanges and Amendment) needed to implement\n\ns/type/types/\n\nHas there been a newly introduced tax on the letter S ? :-)\n\n> pre-commit hook support.\n> \n> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> ---\n>  utils/checkstyle.py | 46 +++++++++++++++++++++++++++++----------------\n>  1 file changed, 30 insertions(+), 16 deletions(-)\n> \n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index 4a14309..828605a 100755\n> --- a/utils/checkstyle.py\n> +++ b/utils/checkstyle.py\n> @@ -458,12 +458,33 @@ class StripTrailingSpaceFormatter(Formatter):\n>  # Style checking\n>  #\n>  \n> +class Commit:\n> +    def __init__(self, commit):\n> +        self.commit = commit\n> +\n> +    def get_info(self, top_level):\n\nThe top_level argument isn't used, you can drop it.\n\n> +        # Get the commit title and list of files.\n> +        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',\n> +                              self.commit],\n> +                             stdout=subprocess.PIPE).stdout.decode('utf-8')\n> +        files = ret.splitlines()\n> +        # Returning title and files list as a tuple\n> +        return files[0], files[1:]\n> +\n> +    def get_diff(self, top_level, filename):\n> +        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),\n> +                               '--', '%s/%s' % (top_level, filename)],\n> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n> +\n> +    def get_file(self, filename):\n> +        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],\n> +                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n> +\n> +\n>  def check_file(top_level, commit, filename):\n>      # Extract the line numbers touched by the commit.\n> -    diff = subprocess.run(['git', 'diff', '%s~..%s' % (commit, commit), '--',\n> -                           '%s/%s' % (top_level, filename)],\n> -                          stdout=subprocess.PIPE).stdout\n> -    diff = diff.decode('utf-8').splitlines(True)\n> +    diff = commit.get_diff(top_level, filename)\n> +    diff = diff.splitlines(True)\n>      commit_diff = parse_diff(diff)\n>  \n>      lines = []\n> @@ -476,9 +497,7 @@ def check_file(top_level, commit, filename):\n>  \n>      # Format the file after the commit with all formatters and compute the diff\n>      # between the unformatted and formatted contents.\n> -    after = subprocess.run(['git', 'show', '%s:%s' % (commit, filename)],\n> -                           stdout=subprocess.PIPE).stdout\n> -    after = after.decode('utf-8')\n> +    after = commit.get_file(filename)\n>  \n>      formatted = after\n>      for formatter in Formatter.formatters(filename):\n> @@ -522,12 +541,7 @@ def check_file(top_level, commit, filename):\n>  \n>  \n>  def check_style(top_level, commit):\n> -    # Get the commit title and list of files.\n> -    ret = subprocess.run(['git', 'show', '--pretty=oneline','--name-only', commit],\n> -                         stdout=subprocess.PIPE)\n> -    files = ret.stdout.decode('utf-8').splitlines()\n> -    title = files[0]\n> -    files = files[1:]\n> +    title, files = commit.get_info(top_level)\n>  \n>      separator = '-' * len(title)\n>      print(separator)\n> @@ -557,7 +571,7 @@ def check_style(top_level, commit):\n>      return issues\n>  \n>  \n> -def extract_revlist(revs):\n> +def extract_commits(revs):\n>      \"\"\"Extract a list of commits on which to operate from a revision or revision\n>      range.\n>      \"\"\"\n> @@ -576,7 +590,7 @@ def extract_revlist(revs):\n>          revlist = ret.stdout.decode('utf-8').splitlines()\n>          revlist.reverse()\n>  \n> -    return revlist\n> +    return [Commit(x) for x in revlist]\n>  \n>  \n>  def git_top_level():\n> @@ -632,7 +646,7 @@ def main(argv):\n>      if top_level is None:\n>              return 1\n>  \n> -    revlist = extract_revlist(args.revision_range)\n> +    revlist = extract_commits(args.revision_range)\n\ns/revlist/commits/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \n>      issues = 0\n>      for commit in revlist:","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 417A260455\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Jan 2020 18:54:04 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BB7E897A;\n\tSat, 18 Jan 2020 18:54:03 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1579370043;\n\tbh=deu40tZyfkiK+25CAeLleOMGG7X86D0phlSY3XhaINU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=An2ZnVzmS1NLlZFWgXQ1wK2lSYwwJY4V2q22keDL+5YqwkDwCC2M24h34YutVskqF\n\t2XOVYzNT6Bu8gclzs68yxmwxoCB2WeAuZZadw4T1EvAXDXiXXHjjQ8C2LSrNSy5+CH\n\tfLcRKJAL7eODhv+NzLCropq6i3ibRYzj59sQD6yA=","Date":"Sat, 18 Jan 2020 19:53:49 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"libcamera-devel@lists.libcamera.org,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Message-ID":"<20200118175349.GB5095@pendragon.ideasonboard.com>","References":"<20200118035448.230530-1-nicolas@ndufresne.ca>\n\t<20200118035448.230530-4-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200118035448.230530-4-nicolas@ndufresne.ca>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 3/6] checkstyle: Introduce a Commit\n\tclass","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 18 Jan 2020 17:54:04 -0000"}}]