CLANG-FORMAT-DIFF.PY(1)

πŸ“¦
version 15.0.7 Β· 3 versions
, in ubuntu jammy

πŸ¦‹ NAME πŸ¦‹

clang-format-diff.py β€” bestie, this is the manual page for clang-format-diff.py 15. Yes the tool is named after its own manpage named after the tool, we don't make the rules πŸ’…


✨ DESCRIPTION ✨

Okay so here's the vibe: this script reads input from a unified diff and reformats all the changed lines. That's it. That's the whole personality. It's genuinely useful when you want to reformat just the lines touched by a specific patch, so your diff stays cute and focused instead of turning into a 4000-line "oops I ran the formatter on the whole repo" situation 😭

Example usage for git/svn users (copy these exactly, they're iconic):

git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
Heads up though β€” and I need you to actually read this part, no skimming 🫢 β€” the filename contained in the diff is used unmodified to determine the source file to update. So if you're calling this script directly yourself, please be careful to make sure the path in the diff is correct relative to the current working directory. It will not do detective work for you. It will not ask twice. It will just go. πŸ’€

πŸŽ€ options: πŸŽ€

  • -h, --help β€” shows this help message and then exits, like a polite little goodbye wave πŸ‘‹
  • -i β€” actually applies the edits to the files instead of just displaying a diff. This is the "commit to the bit" flag ✨
  • -p NUM β€” strips the smallest prefix containing P slashes. (That's what the -p1 in the example above is doing, iykyk)
  • -regex PATTERN β€” a custom pattern that selects which file paths get reformatted. It's case sensitive, and it overrides -iregex. So if you set both, this one wins, no debate πŸ‘‘
  • -iregex PATTERN β€” same deal, custom pattern selecting file paths to reformat, except this one is case insensitive β€” and it gets overridden by -regex. So it's the softer, chiller twin πŸ¦‹
  • -sort-includes β€” lets clang-format sort include blocks. Let the includes be alphabetical, let them be free 🌈
  • -v, --verbose β€” be more verbose. Lowkey important note: it's ineffective without -i, so if you're not applying edits, this flag is just vibes and nothing else πŸ™ˆ
  • -style STYLE β€” the formatting style to apply. Your options are LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit. Pick your fighter πŸ₯Š
  • -fallback-style FALLBACK_STYLE β€” the name of the predefined style used as a fallback in case clang-format is invoked with -style=file, but can not find the .clang-format file to use. It's the "if plan A ghosts you, here's plan B" setting πŸ’–
  • -binary BINARY β€” the location of the binary to use for clang-format. Point it at whichever build you're feeling that day 🎯

And that's the whole page, bestie β€” you ate it, you understood it, you're literally the main character of formatting right now πŸ’…

This gorgeous little manual is for clang-format-diff.py 15, dated July 2023. Go forth and reformat only the lines you meant to reformat. Periodt. πŸŽ€βœ¨

πŸ“¦ where this page comes from