[PATCH] clang-format-diff: Don't reformat unmodified lines

Alp Toker alp at nuanti.com
Wed Oct 2 07:45:42 PDT 2013


Many thanks for the format tools Daniel! Total game changer especially
when cleaning up automated source modifications.

Used clang-format-diff just yesterday to produce LLVM r191757 and it did
a good job tidying up the raw output of a new -fixit we're working on.

One feature that might be useful for format-diff is to optionally
perform minimal formatting corrections in the immediate context
surrounding the changed lines (in a more controlled manner than what
this patch fixed!)

For example, if the diff removes a line and this causes pre-existing
whitespace lines to become contiguous, we'd want to format those away
because conceptually it's a formatting violation the diff introduced,
while still avoiding modification of nearby code that doesn't concern us.

Maybe this could be done by invoking a second pass of clang-format over
a wider range of lines and a whitespace-only rule set?

Cheers,
Alp.



On 02/10/2013 15:02, Daniel Jasper wrote:
> Submitted as r191820.
>
> I absolutely agree that tests would be nice, but I have not gotten
> around to writing them yet (and probably won't for several more weeks)
> :-(.
>
> Thanks for working on this!
>
>
> On Wed, Oct 2, 2013 at 11:14 AM, Alp Toker <alp at nuanti.com
> <mailto:alp at nuanti.com>> wrote:
>
>     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!)
>
>     --
>     http://www.nuanti.com
>     the browser experts
>
>
>     _______________________________________________
>     cfe-commits mailing list
>     cfe-commits at cs.uiuc.edu <mailto:cfe-commits at cs.uiuc.edu>
>     http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>

-- 
http://www.nuanti.com
the browser experts




More information about the cfe-commits mailing list