r191820 - clang-format: Fix clang-format-diff.py according to diff specification.

Daniel Jasper djasper at google.com
Wed Oct 2 06:59:03 PDT 2013


Author: djasper
Date: Wed Oct  2 08:59:03 2013
New Revision: 191820

URL: http://llvm.org/viewvc/llvm-project?rev=191820&view=rev
Log:
clang-format: Fix clang-format-diff.py according to diff specification.

Patch by Alp Toker. Many thanks!

Original descriptions:
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!)

Modified:
    cfe/trunk/tools/clang-format/clang-format-diff.py

Modified: cfe/trunk/tools/clang-format/clang-format-diff.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-diff.py?rev=191820&r1=191819&r2=191820&view=diff
==============================================================================
--- 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)
     if match:
       start_line = int(match.group(1))
-      end_line = start_line
+      line_count = 1
       if match.group(3):
-        end_line = start_line + int(match.group(3))
+        line_count = int(match.group(3))
+      if line_count == 0:
+        continue
+      end_line = start_line + line_count - 1;
       lines_by_file.setdefault(filename, []).extend(
           ['-lines', str(start_line) + ':' + str(end_line)])
 





More information about the cfe-commits mailing list