r191820 - clang-format: Fix clang-format-diff.py according to diff specification.
djasper at google.com
Wed Oct 2 06:59:03 PDT 2013
Date: Wed Oct 2 08:59:03 2013
New Revision: 191820
clang-format: Fix clang-format-diff.py according to diff specification.
Patch by Alp Toker. Many thanks!
clang-format-diff incorrectly modifies unchanged lines due to an error
in diff parsing.
The unified diff format has a default line change count of 1, and 0 may
be specified to indicate that no lines have been added. This patch
updates the parser to accurately reflect the diff specification.
This also has the benefit of stabilising the operation so it will
produce the same output when run multiple times on the same changeset,
which was previously not the case.
No tests added because this script is not currently tested (though we
should look into that!)
--- cfe/trunk/tools/clang-format/clang-format-diff.py (original)
+++ cfe/trunk/tools/clang-format/clang-format-diff.py Wed Oct 2 08:59:03 2013
@@ -60,9 +60,12 @@ def main():
match = re.search('^@@.*\+(\d+)(,(\d+))?', line)
start_line = int(match.group(1))
- end_line = start_line
+ line_count = 1
- end_line = start_line + int(match.group(3))
+ line_count = int(match.group(3))
+ if line_count == 0:
+ end_line = start_line + line_count - 1;
['-lines', str(start_line) + ':' + str(end_line)])
More information about the cfe-commits