Skip to content

Commit

Permalink
Improve clang-format-diff help output (#73491)
Browse files Browse the repository at this point in the history
It is quite common to symlink clang-format-diff.py to clang-format-diff,
and in that case the help output still refers to the .py version.
Compute it instead to work in both setup.
  • Loading branch information
serge-sans-paille committed Nov 28, 2023
1 parent 2c729d2 commit ced0f28
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions clang/tools/clang-format/clang-format-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
lines. This is useful to reformat all the lines touched by a specific patch.
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
git diff -U0 --no-color --relative HEAD^ | {clang_format_diff} -p1 -i
svn diff --diff-cmd=diff -x-U0 | {clang_format_diff} -i
It should be noted that the filename contained in the diff is used unmodified
to determine the source file to update. Users calling this script directly
Expand All @@ -25,6 +25,7 @@

import argparse
import difflib
import os
import re
import subprocess
import sys
Expand All @@ -36,8 +37,10 @@


def main():
basename = os.path.basename(sys.argv[0])
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
description=__doc__.format(clang_format_diff=basename),
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"-i",
Expand Down

0 comments on commit ced0f28

Please sign in to comment.