<div dir="ltr"><div dir="ltr">Hi Umang,<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 20 Jan 2021 at 16:52, Umang Jain <<a href="mailto:email@uajain.com">email@uajain.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
Hi Naushir<br>
<br>
Yes, I have hit this issue with pre-commit and your diagonsis is
right. <br></div></blockquote><div><br></div><div>Thanks for confirming! I'm glad it's not only me :-) I'm positive this has only recently started happening.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<br>
<div>On 1/20/21 4:29 PM, Naushir Patuck
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 20 Jan 2021 at
10:52, Naushir Patuck <<a href="mailto:naush@raspberrypi.com" target="_blank">naush@raspberrypi.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">Hi all,
<div><br>
</div>
<div>I have started noticing a problem with the
utils/checkstyle.py script when run in the provided
pre-commit hook (utils/hooks/pre-commit). Here is an
example output when I do a "git commit --amend
--fixup=xxxx" command:</div>
</div>
</blockquote>
<div><br>
</div>
<div>Sorry, my git command has a typo above, it is
"git commit -a --fixup=xxxx"</div>
<div> <br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div><br>
</div>
<div>fatal: ambiguous argument '': unknown revision or
path not in the working tree.<br>
Use '--' to separate paths from revisions, like this:<br>
'git <command> [<revision>...] --
[<file>...]'<br>
Traceback (most recent call last):<br>
File "./utils/checkstyle.py", line 875, in
<module><br>
sys.exit(main(sys.argv))<br>
File "./utils/checkstyle.py", line 850, in main<br>
commits.append(StagedChanges())<br>
File "./utils/checkstyle.py", line 237, in __init__<br>
Commit.__init__(self, '')<br>
File "./utils/checkstyle.py", line 206, in __init__<br>
self.__parse()<br>
File "./utils/checkstyle.py", line 215, in __parse<br>
self.__title = files[0]<br>
IndexError: list index out of range<br>
</div>
<div><br>
</div>
<div>This used to certainly work in the past, so I can
only assume either something in the script, or my
environment has changed. The reason behind the git
command failure seems to be related to the last argument
in the subprocess call:</div>
<div><br>
</div>
<div>ret = subprocess.run(['git', 'show',
'--pretty=oneline', '--name-status',<br>
self.commit],<br>
stdout=subprocess.PIPE).stdout.decode('utf-8')<br>
</div>
<div><br>
</div>
<div>where self.commit is an empty string.</div>
<div><br>
</div>
<div>This may have been introduced by commit 097720840
('utils: checkstyle.py: Move commit handling to a
separate section'). A fix that works for me is as
follows:</div>
<div><br>
</div>
<div>diff --git a/utils/checkstyle.py
b/utils/checkstyle.py<br>
index 0e9659e98518..cb7b2d151412 100755<br>
--- a/utils/checkstyle.py<br>
+++ b/utils/checkstyle.py<br>
@@ -207,9 +207,11 @@ class Commit:<br>
<br>
def __parse(self):<br>
# Get the commit title and list of files.<br>
- ret = subprocess.run(['git', 'show',
'--pretty=oneline', '--name-status',<br>
- self.commit],<br>
-
stdout=subprocess.PIPE).stdout.decode('utf-8')<br>
+ args = ['git', 'show', '--pretty=oneline',
'--name-status']<br>
+ if self.commit != '':<br>
+ args.append(self.commit)<br>
+<br>
+ ret = subprocess.run(args,
stdout=subprocess.PIPE).stdout.decode('utf-8')<br>
files = ret.splitlines()<br>
self.__files = [CommitFile(f) for f in
files[1:]]<br>
</div>
<div><br>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
I think this will parse the HEAD commit and not the diff/staged
changes. I haven't looked at it closely but that's my understanding.
I have seen mostly using the hook as a post-commit by other devs and
that (in my testing) works fine. <br></div></blockquote><div><br></div><div>Perhaps - my fix above worked on the (seemingly correct) assumption that an empty string appended to the end of the argument list would break the command. If there is a commit hash in the self.commit string, it will append it as before.</div><div>If the checkpatch script is not meant to be used as a pre-commit hook, perhaps we should remove the utils/hooks/pre-commit script entirely so others don't encounter this problem?</div><div><br></div><div>Regards,</div><div>Naush</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div>I was just wondering if I have something strange in
my environment that is causing these issues, or are
other folks seeing this as well?</div>
<div><br>
</div>
<div>Regards,</div>
<div>Naush</div>
<div><br>
</div>
</div>
</blockquote>
</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
libcamera-devel mailing list
<a href="mailto:libcamera-devel@lists.libcamera.org" target="_blank">libcamera-devel@lists.libcamera.org</a>
<a href="https://lists.libcamera.org/listinfo/libcamera-devel" target="_blank">https://lists.libcamera.org/listinfo/libcamera-devel</a>
</pre>
</blockquote>
<br>
</div>
</blockquote></div></div>