clang-format: use AngleBracket for main includes #34345

pull stickies-v wants to merge 1 commits into bitcoin:master from stickies-v:2026-01/clang-format-main-include changing 1 files +1 −0
  1. stickies-v commented at 5:13 pm on January 19, 2026: contributor

    This project uses angle brackets instead of quotes for project-specific headers. Setting MainIncludeChar enables clang-format to automatically detect the main header, so it can be kept as the top group of includes.

    For example, without this change, clang-format would demote <signet.h> from being the main header in src/signet.cpp. With this change, the order is preserved.

    On 5e49f5d63c74512c8f46fe7de7deb0341f13244a:

     0% clang-format src/signet.cpp | head -n 15
     1// Copyright (c) 2019-present The Bitcoin Core developers
     2// Distributed under the MIT software license, see the accompanying
     3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
     4
     5#include <consensus/merkle.h>
     6#include <consensus/params.h>
     7#include <consensus/validation.h>
     8#include <logging.h>
     9#include <primitives/block.h>
    10#include <primitives/transaction.h>
    11#include <script/interpreter.h>
    12#include <script/script.h>
    13#include <signet.h>
    14#include <streams.h>
    15#include <uint256.h>
    

    With this PR:

     0% clang-format src/signet.cpp | head -n 10
     1// Copyright (c) 2019-present The Bitcoin Core developers
     2// Distributed under the MIT software license, see the accompanying
     3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
     4
     5#include <signet.h>
     6
     7#include <consensus/merkle.h>
     8#include <consensus/params.h>
     9#include <consensus/validation.h>
    10#include <logging.h>
    

    Note: AngleBracket requires clang-format 19, and will cause older versions (including our current minimum llvm version 17) to fail

  2. clang-format: use AngleBracket for main includes
    This project uses angle brackets instead of quotes for project-specific
    headers. Setting MainIncludeChar enables clang-format to automatically
    detect the main header, so it can be kept as the top group of includes.
    
    For example, without this change, the below command would demote
    <signet.h> from being the main header. With this change, the order is
    preserved.
    
    `clang-format -i src/signet.cpp`
    0dafc0d83c
  3. DrahtBot commented at 5:13 pm on January 19, 2026: 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/34345.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK sedited, maflcko, hebasto

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  4. hebasto commented at 5:14 pm on January 19, 2026: member
    Concept ACK.
  5. maflcko commented at 5:24 pm on January 19, 2026: member
    I guess this was only added in clang-format 19. It may be fine to bump to that (https://github.com/bitcoin/bitcoin/pull/33555). However, it could make sense to sanity check what clang-format-17 does here and possibly just accept that outcome?
  6. sedited approved
  7. sedited commented at 5:25 pm on January 19, 2026: contributor
    Nice, ACK 0dafc0d83c3e4c48c0ab2efad4b160d1b8c6d252
  8. DrahtBot requested review from hebasto on Jan 19, 2026
  9. hebasto commented at 5:27 pm on January 19, 2026: member
    cc @l0rinc
  10. sedited commented at 5:31 pm on January 19, 2026: contributor

    However, it could make sense to sanity check what clang-format-17 does here and possibly just accept that outcome?

    This is indeed broken on clang-17, but do we typically require the same lowest version for all our linter and formatting tools?

  11. stickies-v commented at 6:12 pm on January 19, 2026: contributor

    Yeah, this breaks clang-format on llvm@{17,18}:

    0$(brew --prefix llvm@17)/bin/clang-format -i src/signet.cpp
    1/Users/stickies-v/code/bitcoin/review/src/.clang-format:145:1: error: unknown key 'MainIncludeChar'
    2MainIncludeChar: AngleBracket
    3^~~~~~~~~~~~~~~
    4Error reading /Users/stickies-v/code/bitcoin/review/src/.clang-format: Invalid argument
    

    I think we’ll either have to revert the IncludeBlocks: Regroup change, bump clang-format to v19, or accept that main headers will no longer be grouped at the top.

    I personally think it is acceptable to de facto bump clang-format to 19, given that it is opt-in only (i.e. not required by build system or any automated tooling), so it shouldn’t really affect casual/drive-by contributors too much?

  12. maflcko commented at 6:17 pm on January 19, 2026: member

    I personally think it is acceptable to de facto bump clang-format to 19, given that it is opt-in only (i.e. not required by build system or any automated tooling), so it shouldn’t really affect casual/drive-by contributors too much?

    I agree. Thanks for testing clang-17 and providing the error message.

  13. maflcko commented at 6:17 pm on January 19, 2026: member
    review ACK 0dafc0d83c3e4c48c0ab2efad4b160d1b8c6d252
  14. hebasto approved
  15. hebasto commented at 9:20 pm on January 19, 2026: member

    ACK 0dafc0d83c3e4c48c0ab2efad4b160d1b8c6d252, tested on Ubuntu 25.10.

    nit: Maybe document the minimum required clang-format version somewhere?

  16. maflcko commented at 9:29 pm on January 19, 2026: member

    nit: Maybe document the minimum required clang-format version somewhere?

    I think this will just be temporary, so no need to document further, beyond the existence of this pull request.

  17. fanquake merged this on Jan 20, 2026
  18. fanquake closed this on Jan 20, 2026

  19. stickies-v deleted the branch on Jan 20, 2026

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: 2026-01-27 06:13 UTC

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