9

I'd like to use Eclipse's formatter to fix some poorly styled code, but there's a huge downside to killing all the metadata in the repository about who is responsible for what. Any thoughts on ways to get around this? Perhaps it is just completely impossible...

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Jacob
  • 1,671
  • 4
  • 23
  • 26

4 Answers4

7

You can tell blame to ignore whitespace changes:

svn blame -x -w file/path

Of course that only works if your style fix doesn't change more than whitespaces.

Stefan
  • 43,293
  • 10
  • 75
  • 117
  • This looks great but it doesn't work for me. What's the magic? What client and platform are you currently using? – atikat Feb 16 '11 at 00:56
  • Tortoise svn ignores whitespace changes per default (there is a checkbox to change this). – fschmitt Jul 24 '13 at 14:05
  • If you want it to also ignore changes in newlines (CRLF vs. LF), use `svn blame -x -w -x --ignore-eol-style`. See `svn help blame` and [this question](https://stackoverflow.com/questions/7449503/how-can-i-ignore-eol-changes-and-all-white-space-in-svn). – Tor Klingberg Feb 12 '18 at 09:58
1

The history is still there, you'll just have to look at a blame prior to the cleanup revision.

This is one good reason to have a style standard. Indentation changes can cause a lot of merge conflicts, etc. "Poorly styled" to one is well written to another.

jthompson
  • 7,178
  • 2
  • 34
  • 33
  • 1
    sadly, there's a large base of poorly styled code to start. I guess one pain point is that eclipse annotations only show the most recent change. And people use them a fair amount. – Jacob Mar 27 '09 at 04:53
0

Another solution would be to add a pre-commit hook that compare the committed file with its formatted version. If there is no difference, the commit is accepted.

Otherwise, a simple message "Code not formatted : commit rejected" would inform your developers to style their modified files prior to commit.

Combined with the Stefan's answer, you still can use blame with -w option and moreover, you do not override the developer's names.

One drawback is that you won't be able to style your whole repository is one pass. Files will be styled as they are modified. Often used files will be quickly styled whereas some might never been updated.

rockeye
  • 2,765
  • 2
  • 30
  • 44
-1

When reformatting code, I usually only fix the indentation. There are just too many cases where the automatic formatter ruins a carefully hand-formatted section.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820