git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] clang-format: outline the git project's coding style

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
Aug 13, 2017, 16:14 UTC
Message-ID
<26bebb5b-857f-1501-5139-a5513d9875ec@ramsayjones.plus.com>
In-Reply-To
<20170813044145.xz4o47oog3z5eycg@sigill.intra.peff.net>
On 13/08/17 05:41, Jeff King wrote:
Show 24 quoted lines
> On Fri, Aug 11, 2017 at 09:39:11PM -0700, Junio C Hamano wrote:
> 
>>> Yeah, I just dug in the archive. The script I ran way back when was
>>> actually clang-format-diff.
>>
>> I am confident with the competence of people around here that we can
>> come up with a reasonable checker for obvious style violations. In
>> the worst case, we could customize and/or tweak checkpatch.pl and
>> start from there.
> 
> I am confident we _can_, too. My question is whether we will. :)
> 
>> Assuming that we can have such a checker, I am more interested in
>> the way how people envision such a checker fits in our workflow to
>> help people.  Earlier Dscho floated an idea to integrate with the
>> GitHub pull requests in a way similar to how Travis and SubmitGit
>> are triggered, and I can sort of see how it may help, but I haven't
>> seen ideas from others.
> 
> Yeah, I agree. I assume most people already run "make test" locally. I'd
> be happy enough if we started with a "make style" that offers style
> suggestions for you to accept. From there we can grow into
> "automatically apply suggestions" and integrating with things like
> submitGit.
As a start, how about something like this:

-- >8 -- $ git diff

diff --git a/Makefile b/Makefile
index 461c845d3..7555def45 100644
--- a/Makefile
+++ b/Makefile
@@ -2440,6 +2440,18 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
 .PHONY: sparse $(SP_OBJ)
 sparse: $(SP_OBJ)
 
+ST_C = $(patsubst %.o,%.stc,$(C_OBJ))
+ST_H = $(patsubst %.h,%.sth,$(LIB_H))
+
+$(ST_C): %.stc: %.c FORCE
+       checkpatch.pl --no-tree --show-types --ignore=NEW_TYPEDEFS,INLINE -f $<
+
+$(ST_H): %.sth: %.h FORCE
+       checkpatch.pl --no-tree --show-types --ignore=NEW_TYPEDEFS,INLINE -f $<
+
+.PHONY: style $(ST_C) $(ST_H)
+style: $(ST_C) $(ST_H)
+
 check: common-cmds.h
        @if sparse; \
        then \
$ 
-- >8 --

To give it a try:

    $ make git.stc    # just run checkpatch over git.c
    $ make cache.sth  # just run checkpatch over cache.h
    $ make -k style >style.out 2>&1  # yep, large output!

A bit crude, but workable. ;-)

Just FYI, for me:

$ wc -l style.out
144076 style.out
$ 
$ grep '^WARNING' style.out | cut -d: -f1,2 | sort | uniq -c
      2 WARNING:AVOID_EXTERNS
    495 WARNING:BLOCK_COMMENT_STYLE
    127 WARNING:BRACES
    213 WARNING:CONSTANT_COMPARISON
  12584 WARNING:CONST_STRUCT
      5 WARNING:CVS_KEYWORD
     26 WARNING:DEEP_INDENTATION
      2 WARNING:DEFAULT_NO_BREAK
     77 WARNING:EMBEDDED_FUNCTION_NAME
      5 WARNING:ENOSYS
    773 WARNING:FUNCTION_ARGUMENTS
     39 WARNING:INDENTED_LABEL
   2610 WARNING:LEADING_SPACE
      1 WARNING:LINE_CONTINUATIONS
   2680 WARNING:LINE_SPACING
   3975 WARNING:LONG_LINE
    330 WARNING:LONG_LINE_COMMENT
    380 WARNING:LONG_LINE_STRING
      2 WARNING:MACRO_WITH_FLOW_CONTROL
      1 WARNING:MISORDERED_TYPE
     17 WARNING:MISSING_SPACE
      1 WARNING:ONE_SEMICOLON
     77 WARNING:PREFER_PRINTF
      7 WARNING:QUOTED_WHITESPACE_BEFORE_NEWLINE
     10 WARNING:RETURN_VOID
      5 WARNING:SINGLE_STATEMENT_DO_WHILE_MACRO
      6 WARNING:SIZEOF_PARENTHESIS
     61 WARNING:SPACE_BEFORE_TAB
    347 WARNING:SPACING
    322 WARNING:SPLIT_STRING
     87 WARNING:STATIC_CONST_CHAR_ARRAY
      2 WARNING:STORAGE_CLASS
    538 WARNING:SUSPECT_CODE_INDENT
     29 WARNING:SYMBOLIC_PERMS
    279 WARNING:TABSTOP
      9 WARNING:TRAILING_SEMICOLON
      3 WARNING:TYPECAST_INT_CONSTANT
      2 WARNING:UNNECESSARY_BREAK
     56 WARNING:UNNECESSARY_ELSE
    568 WARNING:UNSPECIFIED_INT
      4 WARNING:USE_NEGATIVE_ERRNO
     26 WARNING:VOLATILE
$ 

Hmm, on reflection, it may be a bit too crude! :-D

ATB,
Ramsay Jones
Previous: Jeff KingNext: Ramsay Jones
Message 33 of 64 in “[RFC] clang-format: outline the git project's coding style”
  1. Brandon WilliamsAug 8, 2017
  2. Johannes SchindelinAug 8, 2017
  3. Stefan BellerAug 8, 2017
  4. Brandon WilliamsAug 8, 2017
  5. Johannes SchindelinAug 9, 2017
  6. Stefan BellerAug 9, 2017
  7. Johannes SchindelinAug 10, 2017
  8. Junio C HamanoAug 10, 2017
  9. Brandon WilliamsAug 10, 2017
  10. Junio C HamanoAug 10, 2017
  11. Brandon WilliamsAug 10, 2017
  12. Ben PeartAug 11, 2017
  13. Johannes SchindelinAug 14, 2017
  14. Johannes SchindelinSep 28, 2017
  15. Brandon WilliamsSep 28, 2017
  16. Junio C HamanoAug 8, 2017
  17. Brandon WilliamsAug 8, 2017
  18. Junio C HamanoAug 8, 2017
  19. Junio C HamanoAug 9, 2017
  20. Brandon WilliamsAug 11, 2017
  21. Junio C HamanoAug 11, 2017
  22. Jeff KingAug 9, 2017
  23. Ævar Arnfjörð BjarmasonAug 9, 2017
  24. Stefan BellerAug 9, 2017
  25. Stefan BellerAug 9, 2017
  26. Jeff KingAug 9, 2017
  27. brian m. carlsonAug 15, 2017
  28. Jonathan NiederAug 15, 2017
  29. Brandon WilliamsAug 11, 2017
  30. Jeff KingAug 11, 2017
  31. Junio C HamanoAug 12, 2017
  32. Jeff KingAug 13, 2017
  33. Ramsay JonesAug 13, 2017
  34. Ramsay JonesAug 13, 2017
  35. Junio C HamanoAug 13, 2017
  36. Ramsay JonesAug 13, 2017
  37. 0/2 clang-formatBrandon Williams, Aug 14, 2017
  38. 2/2 Makefile: add style build ruleBrandon Williams, Aug 14, 2017
  39. Stefan BellerAug 14, 2017
  40. Junio C HamanoAug 14, 2017
  41. Stefan BellerAug 14, 2017
  42. Jeff KingAug 14, 2017
  43. Junio C HamanoAug 14, 2017
  44. Junio C HamanoAug 14, 2017
  45. Brandon WilliamsAug 15, 2017
  46. Jeff KingAug 15, 2017
  47. 1/2 clang-format: outline the git project's coding styleBrandon Williams, Aug 14, 2017
  48. Stefan BellerAug 14, 2017
  49. Ben PeartAug 15, 2017
  50. Brandon WilliamsAug 15, 2017
  51. Jeff KingAug 14, 2017
  52. Jeff KingAug 14, 2017
  53. Brandon WilliamsAug 14, 2017
  54. Jeff KingAug 14, 2017
  55. Johannes SchindelinAug 16, 2017
  56. Ben PeartAug 15, 2017
  57. Brandon WilliamsAug 15, 2017
  58. Stefan BellerAug 15, 2017
  59. Brandon WilliamsAug 14, 2017
  60. Jeff KingAug 14, 2017
  61. Stefan BellerAug 14, 2017
  62. Jeff KingAug 15, 2017
  63. Junio C HamanoAug 15, 2017
  64. Jeff KingAug 15, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.