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.
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.
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:
With this method, your file history information is kept in tact for all future revisions of the files.
This actually can be done with a single checkin. The steps are as follows:
p4 edit
on both filesThe 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With