Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Apr 16, 2020

When writing tests, often includes need to be added or removed. Currently the list of includes is not sorted, so developers that write tests and have clang-format installed will either have an unrelated change (sorting) included in their commit or they will have to manually undo the sort.

This pull preempts both issues by just sorting all includes in one commit.

Please be aware that this is NOT a change to policy to enforce clang-format or any other developer guideline or process. Developers are free to use whatever tool they want, see also #18651.

Edit: Also includes a commit to bump the copyright headers, so that the touched files don't need to be touched again for that.

MarcoFalke added 2 commits April 16, 2020 13:32
-BEGIN VERIFY SCRIPT-
 # Mark all lines with #includes
 sed -i --regexp-extended -e 's/(#include <.*>)/\1 /g' $(git grep -l '#include' ./src/bench/ ./src/test ./src/wallet/test/)
 # Sort all marked lines
 git diff -U0 | ./contrib/devtools/clang-format-diff.py -p1 -i -v
-END VERIFY SCRIPT-
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
@maflcko maflcko force-pushed the 2004-testSortIncludes branch from fa3a43c to fa488f1 Compare April 16, 2020 17:33
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 16, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@promag
Copy link
Contributor

promag commented Apr 16, 2020

ACK just for the scripted-diff 👏

will either have an unrelated change (sorting) included in their commit or they will have to manually undo the sort

or not stage in the first place?

@jnewbery
Copy link
Contributor

I think generally accepted good practice is to go from local to global for includes (ie file's header, then local project imports, then library imports, then std imports). See https://stackoverflow.com/questions/2762568/c-c-include-header-file-order. That seems to be the de facto standard across much of this repo.

Is there any way you can modify your scripted diff to preserve this ordering?

@maflcko
Copy link
Member Author

maflcko commented Apr 17, 2020

@jnewbery I went ahead and manually fixed up the 7 files where the boost/stdlib includes were not last. Those files had this issue as a pre-existing condition and this is not something that can be solved by clang-format. The original author of the test should have take care of it. I am not going to touch files that are not already touched by this pull request and if you think this is a worthy task, it can be done as a follow-up cleanup for the other files. I am happy to review and ACK, but I think the goal of this pull should not be extended further than solving a workflow issue of devs writing tests and using clang-format.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa4632c, light review and sanity checks with gcc build and clang fuzz build

#include <clientversion.h>
#include <hash.h> // For Hash()
#include <key.h> // For CKey
#include <key.h> // For CKey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this changed manually?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is part of the scripted-diff, which you can verify by running ./test/lint/commit-script-check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks -- I need to upgrade my scripted-diff-fu

@practicalswift
Copy link
Contributor

ACK fa4632c

A scripted-diff tour de force - I'm impressed. Very clever! :)

@jnewbery
Copy link
Contributor

Very rough code review ACK. Thanks Marco!

@maflcko maflcko merged commit 54f812d into bitcoin:master Apr 17, 2020
@maflcko maflcko deleted the 2004-testSortIncludes branch April 17, 2020 14:14
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants