Wug
Wug

Reputation: 13196

How do I combine two files in Perforce such that the history of both files is preserved?

I have a perforce repository containing, among other things, this:

depot
 |-- wug.h
 |-- wug1.cpp
 |-- wug2.cpp
 |-- wug3.cpp

wug.h contains a class declaration, and the definitions for that class are spread through the other three files. I'd like to combine all of the files into a single file without losing their perforce history. I've reviewed the documentation for most perforce commands and have no idea how I'd do it. Can anyone suggest anything?

Upvotes: 4

Views: 1404

Answers (1)

Samwise
Samwise

Reputation: 71454

If you want to create a new file called "wug.cpp" that contains all of the others, leave a record of this in the metadata, and do it all in one changelist, you could do:

p4 merge wug1.cpp wug.cpp
p4 resolve (choose 'at', to branch the file)
p4 merge wug2.cpp wug.cpp
p4 resolve (choose 'm' to invoke perforce's merge tool, then 'ae' to accept)
p4 merge wug3.cpp wug.cpp
p4 resolve (choose 'm' to invoke perforce's merge tool, then 'ae' to accept)
p4 delete wug1.cpp wug2.cpp wug3.cpp
p4 submit

During the "p4 resolve" you'll need to do baseless merges to edit all the files together, since there isn't a common base to use as a reference point to actually merge them. Perforce's merge tool will behave this way by default for files with no common ancestor, and should (more or less) provide a merged output consisting of the content of one file, followed by the content of the other, which is more-or-less suitable as-is.

After the final resolve, you can make edits (first using p4 edit wug.cpp to open the file for editing) such as moving include directives to the top of the file, removing duplicate or extraneous code or comments, and other such janitorial changes.

This has the desired effect of preserving the history of the file's contents such that the command
p4 annotate -I wug.cpp properly shows the most recent change to affect each line.

Upvotes: 4

Related Questions