user3419794
user3419794

Reputation: 31

SVN tracking changes across files

I am working on a legacy C++ project where there are many classes in a single file and some files end up being 8k+ lines. I am planning on moving some of these classes to separate files. The project uses SVN. I am wondering if SVN can track the history of such change because I may not do the refactoring if it can't.

As an example, I have old.cpp with 3 classes A B C. I want to refactor this into A.cpp B.cpp C.cpp. If I select history of C.cpp, I want to see the class used to be in old.cpp and all the changes to C in old.cpp.

Upvotes: 1

Views: 135

Answers (2)

Dialecticus
Dialecticus

Reputation: 16769

I have never tried it with single files (only with complete folders, which is essentially branching), but in TortoiseSVN you can drag-n-drop the file using right mouse button. When you drop the file (within the same working folder) in displayed context menu select "SVN copy and rename versioned item here". After that (and other changes) commit the working copy.

Another option is to do the same thing, but from repository browser. The difference from previous option is that here each operation is automatically a new revision. I prefer the first option.

After the file is copied edit it to remove the extraneous content. Using the first option you can do it in the same revision as the copying.

Upvotes: 2

vmax33
vmax33

Reputation: 683

Since your project in SVN - you always will be able to return to the original version. I strongly recommend writing unit tests before the change, so you can track the sanity of the program after each change.

I have an experience in the past with such a change, here how I did it:

  1. Create a separate branch in SVN
  2. Checkout the source from this branch

For each class do the next steps:

  1. Move the class to separate (new) file without changing it. Since the creation you will be able to control each change in SVN
  2. Commit the change to SVN - this way you know that nothing changed in the contents of the file.
  3. Make the necessary changes to the newly created file.
  4. Run unit tests
  5. Commit the change

Upvotes: 1

Related Questions