瀏覽代碼

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!)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191820 91177308-0d34-0410-b5e6-96231b3b80d8
Daniel Jasper 12 年之前
父節點
當前提交
4a966d3fa2
共有 1 個文件被更改,包括 5 次插入2 次删除
  1. 5 2
      tools/clang-format/clang-format-diff.py

+ 5 - 2
tools/clang-format/clang-format-diff.py

@@ -60,9 +60,12 @@ def main():
     match = re.search('^@@.*\+(\d+)(,(\d+))?', line)
     match = re.search('^@@.*\+(\d+)(,(\d+))?', line)
     if match:
     if match:
       start_line = int(match.group(1))
       start_line = int(match.group(1))
-      end_line = start_line
+      line_count = 1
       if match.group(3):
       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_by_file.setdefault(filename, []).extend(
           ['-lines', str(start_line) + ':' + str(end_line)])
           ['-lines', str(start_line) + ':' + str(end_line)])