Tracking a fragment of a file in two places with git
- by mabraham
Hi,
I have code such as
void myfunc()
{
introduction();
while(condition())
{
complex();
loop();
interior();
code();
}
cleanup();
}
which I wish to duplicate into two versions, viz:
void myfuncA()
{
introduction();
minorchangeA();
while(condition())
{
complex();
loop();
interior();
code();
}
cleanup();
}
void myfuncB()
{
introduction();
minorchangeB();
while(condition())
{
complex();
modifiedB();
loop();
interior();
code();
}
cleanup();
extracleanupB();
}
git claims to track content rather than files, so do I need to tell it that there are chunks here that are common to both myfuncA and myfuncB so that when merging with upstream changes to myfunc that those changes should propagate to both myfuncA and myfuncB? If so, how?
The code could be written so that myfuncAB did the correct thing at each point by testing for condition A or B, but that could seriously hinder readability or performance.