CLANG-FORMAT-DIFF.PY(1)

πŸ“¦ version 12.0.1, in ubuntu jammy

πŸ’… NAME πŸ’…

okay bestie, welcome to the manual for clang-format-diff.py β€” yes, the whole thing, section 1 of the manual, the CLANG-FORMAT-DIFF.PY(1) page. it's the script that reads a diff and reformats the changed lines. that's the vibe. that's the whole vibe. πŸ¦‹


🌸 DESCRIPTION 🌸

so, usage, exactly as it is:

usage: clang-format-diff.py [-h] [-i] [-p NUM] [-regex PATTERN]
       [-iregex PATTERN] [-sort-includes] [-v]
              [-style STYLE] [-binary BINARY]

okay so what this script does: it reads input from a unified diff and reformats all the changed lines. that's it. that's the assignment. πŸ’– it is useful to reformat all the lines touched by a specific patch β€” like, only the lines your patch actually touched, no stray edits anywhere else. periodt.

Example usage for git/svn users:

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
⚠️ okay real talk, important caveat, no cap: the filename contained in the diff is used unmodified to determine the source file to update. so if you're calling this script directly, be careful and make sure the path in the diff is correct relative to the current working directory. it does not do that for you. it trusts you. do not betray its trust. 😭

✨ options: ✨

  • -h, --help β€” show this help message and exit. the classic. the icon. 🫢
  • -i β€” apply edits to files instead of displaying a diff. this is the "actually do the thing" button, bestie. πŸ’…
  • -p NUM β€” strip the smallest prefix containing P slashes. that's NUM slashes, mmkay? 🌈
  • -regex PATTERN β€” custom pattern selecting file paths to reformat (case sensitive, and it overrides -iregex). the main character of the two. πŸ‘‘
  • -iregex PATTERN β€” custom pattern selecting file paths to reformat (case insensitive, and it gets overridden by -regex). the soft launch version. πŸŽ€
  • -sort-includes β€” let clang-format sort include blocks. yes queen, alphabetize those includes. ✨
  • -v, --verbose β€” be more verbose. lowkey ineffective without -i though, so don't expect it to do anything if you're just printing a diff. πŸ™ˆ
  • -style STYLE β€” formatting style to apply. the options are LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit. pick your fighter. πŸ₯Š
  • -binary BINARY β€” location of binary to use for clang-format. in case your clang-format is somewhere weird. we don't judge. πŸ¦‹

and that's the whole page, bestie, you ate it. πŸ’– this was clang-format-diff.py version 12, from February 2022 β€” go forth and reformat only the lines you actually touched. slay. πŸ’…βœ¨πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from