I am doing a refactoring of my C++ project containing many source files.
The current refactoring step includes joining two files (say, x.cpp
and y.cpp
) into a bigger one (say, xy.cpp
) with some code being thrown out, and some more code added to it.
I would like to tell my version control system (Perforce, in my case) that the resulting file is based on two previous files, so in future, when i look at the revision history of xy.cpp
, i also see all the changes ever done to x.cpp
and y.cpp
.
Perforce supports renaming files, so if y.cpp
didn't exist i would know exactly what to do. Perforce also supports merging, so if i had 2 different versions of xy.cpp
it could create one version from it. From this, i figure out that joining two different files is possible (not sure about it); however, i searched through some documentation on Perforce and other source control systems and didn't find anything useful.
Is what i am trying to do possible at all?
Does it have a conventional name (searching the documentation on "merging" or "joining" was unsuccessful)?
In version control, merging (also called integration) is a fundamental operation that reconciles multiple changes made to a version-controlled collection of files. Most often, it is necessary when a file is modified on two independent branches and subsequently merged.
Generated files can bloat the version control history (the size of the database that is stored in the repository). A small change to a source file may result in a rather different generated file.
A diff is a compact summary of the differences (hence the name “diff”) between two items. For example, given two files, the Unix and Linux diff command compares the files line by line and summarizes the deviations in a diff, as shown in the following code.
You could try integrating with baseless merges (-i on the command line). If I understand the documentation correctly (and I've never used it myself), this will force the integration of two files. You would then need to resolve the integration however you choose, resulting in something close to the file you are envisioning.
After doing this, I assume the Perforce history would show the integration from the unrelated file in it's integration history, allowing you to track back to that file when desired.
I don't think it can be done in a classic VCS.
Those versioning systems come in two flavors (slide 50+ of Getting git by Scott Chacon):
delta-based history: you take one file, and record its delta. In this case, the unit being the file, you cannot associate its history with another file.
DAG-based history: you take one content and record its patches. In this case, the file itself can vary (it can be renamed/moved at will), and it can be the result of two other contents (so it is close of what you want)... but still within the history of one file (the contents coming from different branches of its DAG).
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