clang-format: Set Bitcoin Core IncludeCategories #33917

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2511-format-includes changing 2 files +11 −8
  1. maflcko commented at 3:57 pm on November 20, 2025: member

    Replace the default llvm include categories with the ones specific to Bitcoin Core.

    Ref: https://releases.llvm.org/17.0.1/tools/clang/docs/ClangFormatStyleOptions.html#includecategories

    Also, format a file as example. To test this, the diff in src/test needs to be reverted. Also IncludeBlocks: Regroup needs to be set. Then clang-format -i src/test/blockchain_tests.cpp should recreate the diff.

    0diff --git a/src/.clang-format b/src/.clang-format
    1index 15335fe9ae..579079095f 100644
    2--- a/src/.clang-format
    3+++ b/src/.clang-format
    4@@ -99,3 +99,3 @@ IfMacros:
    5   - KJ_IF_MAYBE
    6-IncludeBlocks:   Preserve
    7+IncludeBlocks:   Regroup
    8 IncludeCategories:
    
  2. DrahtBot commented at 3:57 pm on November 20, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33917.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK l0rinc

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #33637 (refactor: optimize block index comparisons (1.4-6.8x faster) by l0rinc)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. in src/.clang-format:101 in fa54461940 outdated
     98@@ -99,18 +99,21 @@ IfMacros:
     99   - KJ_IF_MAYBE
    100 IncludeBlocks:   Preserve
    101 IncludeCategories:
    


    l0rinc commented at 6:14 pm on November 20, 2025:

    nice!

    How did you come up with the categories? Have you reformatted the whole codebase - or it’s just experience? :)


    maflcko commented at 6:57 pm on November 20, 2025:

    I think this is just the common approach to go from local to global, and also used in this codebase historically. This means:

    • Priority -1 for the build-config (not sure why this is special). Changing it can be done in a different pull. Here I just want to document the existing order.
    • Priority 1 for Bitcoin Core stuff
    • Priority 2 for third-party libs (boost, QT)
    • Priority 3 for the c++ stdlib (includes without a dot in them)
  4. in src/.clang-format:116 in fa54461940
    119+    CaseSensitive:   true
    120   - Regex:           '.*'
    121     Priority:        1
    122-    SortPriority:    0
    123-    CaseSensitive:   false
    124+    CaseSensitive:   true
    


    l0rinc commented at 6:14 pm on November 20, 2025:
    this might as well stay false, lol
  5. in src/.clang-format:113 in fa54461940
    114+    CaseSensitive:   true
    115+  - Regex:           '^<[^>.]*>'
    116     Priority:        3
    117-    SortPriority:    0
    118-    CaseSensitive:   false
    119+    CaseSensitive:   true
    


    l0rinc commented at 6:15 pm on November 20, 2025:
    for simplicity, this can also stay false
  6. l0rinc approved
  7. clang-format: Set Bitcoin Core IncludeCategories
    Replace the default llvm include categories with the ones specific to
    Bitcoin Core.
    fa7e222a23
  8. maflcko force-pushed on Nov 20, 2025
  9. l0rinc commented at 7:49 pm on November 20, 2025: contributor

    ACK fa7e222a23266e258d82e085f62cbf89d20dc8f3

    Thanks for adjusting these. After this PR we can remove the deprecated ones and add the new options in 17 by regenerating the config.

  10. DrahtBot added the label CI failed on Nov 20, 2025
  11. DrahtBot removed the label CI failed on Nov 20, 2025
  12. fanquake merged this on Nov 25, 2025
  13. fanquake closed this on Nov 25, 2025

  14. maflcko deleted the branch on Nov 25, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-01 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me