Question

I'll start off by saying that it's entirely possible that this isn't possible - if it's not, that's fine (well, it sucks, but I'll live). I know there are potentially some "well, how would that work anyway?" walls in doing what I want to do, but hey.

What I'd like to do is to reformat a large number of files in a Subversion repository without changing any of the ownership data, either turning this:

username   | commit number
------------------------------------------------
john_smith | 1 | <?php
john_smith | 1 | echo 'Hello world';
joe_bloggs | 2 | if (isset($user)) {
john_doe   | 3 |   echo ', and hello ' . $user;
joe_bloggs | 2 | }

into this (where the new lines are unowned):

username   | commit number
------------------------------------------------
john_smith | 1 | <?php
           |   |
john_smith | 1 | echo 'Hello world';
joe_bloggs | 2 | if (isset($user))
           |   | {
john_doe   | 3 |   echo ', and hello ' . $user;
joe_bloggs | 2 | }

or this (where new lines are owned by me but changed lines aren't):

username   | commit number
------------------------------------------------
john_smith | 1 | <?php
mr_man     | 4 |
john_smith | 1 | echo 'Hello world';
joe_bloggs | 2 | if (isset($user))
mr_man     | 4 | {
john_doe   | 3 |   echo ', and hello ' . $user;
joe_bloggs | 2 | }

or any other permutation.

I'm wanting to do this as there's a lot of badly formatted code in the repository, and I'd like to get it cleaned up without taking ownership of (pretty much) the entire thing, as it's handy to be able to hit Blame down the side of a file and see the last changes for each line, and the reasons for those changes. Re-formatting with a commit message and ownership would remove that for a large chunk of the repository, and force us to look in the log for the actual person, then diff it just to make sure.

If anyone can think of an alternative way to get the code reformatted without ruining the Blame, I'm open to suggestions on that too.

Était-ce utile?

La solution

Can you do that? No. Any change in the file creates another revision. Thus, you'll get a new revision number in svn blame for each line. After all, even innocuous changes might cause problems. What if your reformatting operation changed data that broke the application. The developer who carefully formatted that data wouldn't want to find themselves getting blamed for that. That's why even formatting changes will change the revision.

There is something you can possibly do if so desired: The owner of a revision is a revision property of svn:author. If you change that revision property, you can change the name of the user who did the commit.

A bit of a limit:

  • Each commit has only a single author, so you'd have to arrange your commits to do all the files by a particular author.
  • By default, Subversion does not allow you to change revision properties. You have to create a pre revision change hook to allow you to change that property.
  • All of the lines will show up as that author in the blame and the revision shown will be the revision of when you did the change.

My recommendation: Don't do it. You could break something if it isn't thoroughly tested. What I would recommend is to use something like Jenkins. I realize that PHP files don't need to be compiled like Java or C code, but you could run a syntax checker on the files and display the results in Jenkins.

You might be able to use the phpcheckstyle application along with the Jenkins Checkstyle plugin. Then use the cigame plugin to challenge developers to fix the formatting of the code itself.

Each checkstyle violation that's fixed will give developers points in the cigame plugin. This will encourage the developers to fix the format issues themselves. If you're not a developer, you should not be touching code. Otherwise, the Finger o' Blame could point from a developer who created buggy code to you because you changed it -- even though it was only formatting.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top