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.
Do not duplicate code. That’s the DRY principle.
Neither git nor anyone will help you for that.
Besides, you misunderstood the role of git: git tracks file contents, not chunks. There is no way to tell git that such and such chunks in one file are the same.