clang-formatting directories you own

153 views
Skip to first unread message

Peter Kasting

unread,
Dec 23, 2024, 1:00:36 PM12/23/24
to cxx
If you are a directory OWNER, and you wish to make changes like mass formatting or clang-tidying, the holidays are a good time to do it. The tree is less busy, people are developing fewer patches (= fewer merge failures), and we all have OO+1 powers. You can make decisions like this locally where you are an OWNER, regardless of what we do for the tree as a whole; see the final paragraph of the style change policy's Consistency section.

I just landed several CLs to clang-format the directories I'm an OWNER of. In case it's useful to you, here's the script I used:

```
for DIR in $DIRS; do git new-branch format_`echo $DIR | sed s/\\\//\_/g`; find $DIR -name "*.cc" -o -name "*.h" -o -name "*.mm" | xargs clang-format -i; git commit -a -m "[cleanup] clang-format $DIR." -m "Produced with:" -m "find $DIR
 -name \"*.cc\" -o -name \"*.h\" -o -name \"*.mm\" | xargs clang-format -i" -m "Bug: none"; git cl upload --commit-description + -d -r $REVIEWER -s --bypass-hooks; done
```

Here $DIRS is a space-delimited set of directories relative to your working dir, and $REVIEWER is your chosen reviewer's email address.

Be careful not to include third-party code; for example, pbos@ noticed that I had tried to clang-format base/, and managed to include base/third_party. I believe net/, at least, would have similar concerns.

If you do do this, please make sure your CLs are titled [cleanup] and tagged with the cleanup hashtag (the above script will do this), and once they land, please collect the hashes and add them to .git-blame-ignore-revs. This will at least minimize the blame disruption such things cause.

PK
Reply all
Reply to author
Forward
0 new messages