From: Daniel Jasper Date: Tue, 2 Jul 2013 13:20:35 +0000 (+0000) Subject: Fix ranges computed by git clang-format. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aad1422fa167ff8508c7e56772b0ba1974e4aa00;p=clang Fix ranges computed by git clang-format. Before, the computed byte range would include the trailing newline. clang-format on the other hand counts whitespace as belonging to the following token, so that git-clang-format inadvertendly reformats the first unmodified line as well. It is not entirely clear whether clang-format's behavior itself should be modified, but for now this seems to be a safe change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185423 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-format/git-clang-format b/tools/clang-format/git-clang-format index 62fe67c19e..763fc35aae 100755 --- a/tools/clang-format/git-clang-format +++ b/tools/clang-format/git-clang-format @@ -329,13 +329,13 @@ def lines_to_bytes_single_file(file, line_ranges): if linenum == r.start: byte_start = byte_idx if linenum == r.start + r.count: - byte_ranges.append(Range(byte_start, byte_idx - byte_start)) + byte_ranges.append(Range(byte_start, byte_idx - byte_start - 1)) r = next(line_ranges_iter) linenum += 1 byte_idx += len(line) if r is not None: # FIXME: Detect and warn if line ranges go past the end of file? - byte_ranges.append(Range(byte_start, byte_idx - byte_start)) + byte_ranges.append(Range(byte_start, byte_idx - byte_start - 1)) return byte_ranges