Tuesday, 8 March 2011

How to automatically run checkpatch.pl when developing QEMU

The checkpatch.pl script was recently added to qemu.git as a way to scan patches for coding standard violations. You can automatically run checkpatch.pl when committing changes to git and abort if there are violations:

$ cd qemu
$ cat >.git/hooks/pre-commit
#!/bin/bash
exec git diff --cached | scripts/checkpatch.pl --no-signoff -q -
^D
$ chmod 755 .git/hooks/pre-commit

Any commit that violates the coding standard as checked by checkpatch.pl will be aborted. I am running with this git hook now and will post any tweaks I make to it.

Update: If you encounter a false positive because checkpatch.pl is complaining about code you didn't touch, use git commit --no-verify to override the pre-commit hook. Use this trick sparingly :-).

13 comments:

  1. How did you manage to force commit if messages are false positive?

    ReplyDelete
    Replies
    1. I have updated the post to mention the git commit --no-verify option which lets you override the pre-commit hook. This is the solution you are looking for.

      Delete
  2. I did a post on my site based on your article.

    I tried to keep the source material and mention that I based on his work, the purpose of my post is to record the steps needed for those who are beginning to study the QEMU to become a developer.

    The post is being built according to demand that I have knowledge.
    http://carlosdelfino.eti.br/logicadeprogramacao/Preparando_o_Ambiente_Para_Estudar_o_QEMU/

    ReplyDelete
  3. Thanks Stefan, let's also recommend running pycodestyle, for ex:

    #!/bin/bash

    set -e

    git diff --cached | pycodestyle --diff

    git diff --cached | scripts/checkpatch.pl --no-signoff -q -

    ReplyDelete
  4. I tried to keep the source material and mention that I based on his work, the purpose of my post is to record the steps needed for those who are beginning to study the QEMU to become a developer.Daniel Ballerini

    ReplyDelete
  5. I'm really impressed about the info you provide in your articles. If you want to invest in suits and be stress-free, then you should shake hands with us. We are providing great clothing in the most reasonable price range that you wouldn’t find anywhere else. Put your trust in us as your supplier since we are the prominent custom stickers printing You can rely on us for the clothing problems we assure you we will never let our customers down.

    ReplyDelete
  6. Wow i can say that this is another great article as expected of this blog.Bookmarked this site.. cd duplication services

    ReplyDelete
  7. Great post mate, thank you for the valuable and useful information. Keep up the good work! FYI, please check these depression, stress and anxiety related articles:

    20 Ways to calm your mind – How to calm your mind


    22 Ways To Become More Positive – How To Become Positive


    25 Ways To Forget Unwanted Memories – How to Forget a Bad Memory


    Top 25 Ways To Reduce Stress – How To Reduce Stress


    21 Ways To Get Rid Of Anger – How To Get Rid Of Anger


    How to Know When Depression Is Serious


    21 Ways To Get Rid Of Anger – Alcohol and Depression


    you can also contact me at depressioncure.net@gmail.com for link exchange, article exchange or for advertisement.

    Thanks

    ReplyDelete
  8. Wow, excellent post. I'd like to draft like this too - taking time and real hard work to make a great article. This post has encouraged me to write some posts that I am going to write soon
    Custom Packaging Boxes
    Custom Printed Boxes Uk
    Logo Stickers
    Custom Box Printing
    custom stickers uk

    ReplyDelete
  9. Great article! I enjoyed this movie and I thought the fight scenes are some of the best I’ve saw. I never thought this would be as good but I was wrong. I just watched it using my DISH online feature where I get thousands of movies I can watch and thought I would give this third movie a try
    Die Cut Bookmarks

    ReplyDelete
  10. Hello, I want to subscribe for this web site to take most up-to-date updates, thus where can i do it please help out.
    Reflective Stickers
    custom hair extension boxes

    ReplyDelete
  11. m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article
    custom wig pillow boxes
    custom burger boxes

    ReplyDelete