diff options
author | Tamir Duberstein <tamird@google.com> | 2023-02-27 20:02:51 +0000 |
---|---|---|
committer | Leonard Chan <leonardchan@google.com> | 2023-02-27 20:02:51 +0000 |
commit | 50563944ab962b58a1e00763ce16d8c712965c6d (patch) | |
tree | 850322c19e15fa85c89d326484655bae93622e81 /clang/tools/clang-format/clang-format-diff.py | |
parent | 666731660c733896b83de5eec49e2cd469aef02c (diff) | |
download | llvm-50563944ab962b58a1e00763ce16d8c712965c6d.zip llvm-50563944ab962b58a1e00763ce16d8c712965c6d.tar.gz llvm-50563944ab962b58a1e00763ce16d8c712965c6d.tar.bz2 |
[clang-format-diff] Correctly parse start-of-file diffs
Handle the case where the diff is a pure removal of lines. Before this
change start_line would end up as 0 which is rejected by clang-format.
Submitting on behalf of @tamird.
Differential Revision: https://reviews.llvm.org/D144291
Diffstat (limited to 'clang/tools/clang-format/clang-format-diff.py')
-rwxr-xr-x | clang/tools/clang-format/clang-format-diff.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/tools/clang-format/clang-format-diff.py b/clang/tools/clang-format/clang-format-diff.py index 1f6ff0f..1dcc868 100755 --- a/clang/tools/clang-format/clang-format-diff.py +++ b/clang/tools/clang-format/clang-format-diff.py @@ -84,12 +84,19 @@ def main(): if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): continue - match = re.search(r'^@@.*\+(\d+)(,(\d+))?', line) + match = re.search(r'^@@.*\+(\d+)(?:,(\d+))?', line) if match: start_line = int(match.group(1)) line_count = 1 - if match.group(3): - line_count = int(match.group(3)) + if match.group(2): + line_count = int(match.group(2)) + # The input is something like + # + # @@ -1, +0,0 @@ + # + # which means no lines were added. + if line_count == 0: + continue # Also format lines range if line_count is 0 in case of deleting # surrounding statements. end_line = start_line |