1

I have a requirement to style only the part of the C/C++ file which is getting committed (so the blame for the other lines are intact). Is there any tool to just do that? I know we can style the whole file and get the blame to ignore styling changes (but my team doesn't want that).

Here are a few things I tried with astyle:

  1. I write the diff to a new file and style it and replace the diff part in the original file - Why it doesn't work? It doesn't really get styled as it doesn't have the context, like the if statement to indent the rest of the lines on etc.

  2. I style the whole file and replace only the section that changed. - Why it doesn't work? If I try to change max code length and the lines get broken up then the diff lines are different.

  3. How about a 3 way merge between the original file and the file where the styled diff is included? Yet to try this.

May be there is an easier way and I am missing it :S

LizzeBennet
  • 197
  • 1
  • 1
  • 13

1 Answers1

1

You can do that with a git hook and clang-format.

For example this: https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/git-clang-format

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • I for one won't be following that link (since my browser flags its cert). Via google I did find clang-format docs which *claim* to be able to format a unified diff; but I'm more than a little skeptical that this would address the issues OP raised regarding things already tried, since the example usage in the docs shows no means of conveying the context to clang-format – Mark Adelsberger Jun 12 '17 at 15:42