Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the proper way to refactor a single file into multiple files and maintain version history in Perforce?

Tags:

perforce

I have a file which has gotten too large, and should be refactored into two smaller files. What's the best way to do this in Perforce such that the relationship to the original file is maintained?

I'm adding two new files, and deleting the original in this case, but I would expect there to be some general solution to this problem.

I think the simplest case would be to add one new file which contains a subset of the content of the original, and delete that content from the original file, but leave it in place (it's trivial to delete it later anyway).

It would be nicest if the operation could be done in a single changelist to avoid any checkins which would break the build.

like image 675
Dave Andersen Avatar asked Feb 16 '11 22:02

Dave Andersen


3 Answers

This can't be done in a single checking, but it can certainly be done without "breaking the build". Let's say you want to split bigFile.cs into smallFile1.cs and smallFile2.cs. First integrate the big file into the two little files and submit them.

p4 integrate bigFile.cs smallFile1.cs
p4 integrate bigFile.cs smallFile2.cs
p4 submit

You now have two extra files in your project directory, but they're doing no harm. Now check out smallFile1.cs and smallFile2.cs, and your project file(s). Add references to the smaller files, remove the reference to the big, edit the small files accordingly, etc. Finally, mark bigFile.cs for delete and submit your changes.

You have now split your big file into two smaller files and the smaller files' history will show you their big file origins.

like image 117
raven Avatar answered Nov 24 '22 06:11

raven


You can use the integrate command.

When you've made changes to a file that need to be propagated to another file, start the process with p4 integrate.

The simplist form of the command would be

p4 integrate fromFile toFile

I would therefore perform the following tasks:

  1. run p4 integrate with toFile being the new file and fromFile being the large, original file
  2. p4 submit
  3. p4 edit both fromFile and toFile to be the smaller versions of the original.
  4. p4 submit

With this method, your file history information is kept in tact for all future revisions of the files.

like image 24
Scott Saad Avatar answered Nov 24 '22 04:11

Scott Saad


This actually can be done with a single checkin. The steps are as follows:

  1. integrate from the source file to both destination files as both raven and Scott Saad suggest
  2. before submitting the new files, do a p4 edit on both files
  3. make changes
  4. p4 submit

The complete file history shows up in the revision graph and time-lapse views. The only disadvantage that I can see to skipping the intermediate submit is that the action type changes from 'integrate' to 'add'. Because of that, other people might not realize there is more to the file history.

I think I slightly prefer the two-checkin process.

like image 22
Dave Andersen Avatar answered Nov 24 '22 04:11

Dave Andersen