[PATCH] D144291: [clang-format-diff] Correctly parse start-of-file diffs

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 27 12:04:00 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG50563944ab96: [clang-format-diff] Correctly parse start-of-file diffs (authored by tamird, committed by leonardchan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144291/new/

https://reviews.llvm.org/D144291

Files:
  clang/tools/clang-format/clang-format-diff.py


Index: clang/tools/clang-format/clang-format-diff.py
===================================================================
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -84,12 +84,19 @@
       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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144291.500867.patch
Type: text/x-patch
Size: 971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230227/bdffbfc9/attachment.bin>


More information about the cfe-commits mailing list