Commit b782d60d authored by Michael Reeves's avatar Michael Reeves

Move equality logic to MergeFileInfos

Finally got this out of DirectoryMergeWindow::updateFileVisibilities.
Set all MergeFileInfos member variables to private.
parent bdcab330
......@@ -45,6 +45,62 @@ MergeFileInfos::~MergeFileInfos()
m_children.clear();
}
void MergeFileInfos::updateParents()
{
MergeFileInfos* current = parent();
while(current != nullptr)
{
bool bChange = false;
if(!isEqualAB() && current->isEqualAB())
{
current->m_bEqualAB = false;
bChange = true;
}
if(!isEqualAC() && current->isEqualAC())
{
current->m_bEqualAC = false;
bChange = true;
}
if(!isEqualBC() && current->isEqualBC())
{
current->m_bEqualBC = false;
bChange = true;
}
if(bChange)
current->updateAge();
else
break;
current = current->parent();
}
}
/*
Check for directories or links marked as not equal and mark them equal.
*/
void MergeFileInfos::updateDirectoryOrLink()
{
bool bChange = false;
if(!isEqualAB() && isDirA() == isDirB() && isLinkA() == isLinkB())
{
m_bEqualAB = true;
bChange = true;
}
if(!isEqualBC() && isDirC() == isDirB() && isLinkC() == isLinkB())
{
m_bEqualBC = true;
bChange = true;
}
if(!isEqualAC() && isDirA() == isDirC() && isLinkA() == isLinkC())
{
m_bEqualAC = true;
bChange = true;
}
if(bChange)
updateAge();
}
QString MergeFileInfos::subPath() const
{
if(m_pFileInfoA != nullptr && m_pFileInfoA->exists())
......@@ -462,20 +518,20 @@ void MergeFileInfos::updateAge()
e_Age age = eNew;
if(existsInC())
{
setAgeC((e_Age)age);
if(m_bEqualAC) setAgeA((e_Age)age);
if(m_bEqualBC) setAgeB((e_Age)age);
setAgeC(age);
if(m_bEqualAC) setAgeA(age);
if(m_bEqualBC) setAgeB(age);
age = eMiddle;
}
if(existsInB() && getAgeB() == eNotThere)
{
setAgeB((e_Age)age);
if(m_bEqualAB) setAgeA((e_Age)age);
setAgeB(age);
if(m_bEqualAB) setAgeA(age);
age = eOld;
}
if(existsInA() && getAgeA() == eNotThere)
{
setAgeA((e_Age)age);
setAgeA(age);
}
if(getAgeA() != eOld && getAgeB() != eOld && getAgeC() != eOld)
{
......@@ -510,7 +566,7 @@ QTextStream& operator<<(QTextStream& ts, MergeFileInfos& mfi)
vm.writeEntry("AgeA", (int)mfi.getAgeA());
vm.writeEntry("AgeB", (int)mfi.getAgeB());
vm.writeEntry("AgeC", (int)mfi.getAgeC());
vm.writeEntry("ConflictingAges", mfi.m_bConflictingAges); // Equal age but files are not!
vm.writeEntry("ConflictingAges", mfi.conflictingAges()); // Equal age but files are not!
vm.save(ts);
......
......@@ -140,6 +140,9 @@ class MergeFileInfos
void updateAge();
void updateParents();
void updateDirectoryOrLink();
inline void startSimOp() { m_bSimOpComplete = false; }
inline bool isSimOpRunning() const { return !m_bOperationComplete; }
inline void endSimOp() { m_bSimOpComplete = true; }
......@@ -147,6 +150,21 @@ class MergeFileInfos
inline void startOperation() { m_bOperationComplete = false; };
inline bool isOperationRunning() const { return !m_bOperationComplete; }
inline void endOperation() { m_bOperationComplete = true; };
inline bool isThreeWay() const
{
if(getDirectoryInfo() == nullptr) return false;
return getDirectoryInfo()->dirC().isValid();
}
inline bool existsEveryWhere() const { return existsInA() && existsInB() && (existsInC() || !isThreeWay()); }
inline int existsCount() const { return (existsInA() ? 1 : 0) + (existsInB() ? 1 : 0) + (existsInC() ? 1 : 0); }
inline bool onlyInA() const {return existsInA() && !existsInB() && !existsInC();}
inline bool onlyInB() const {return !existsInA() && existsInB() && !existsInC();}
inline bool onlyInC() const { return !existsInA() && !existsInB() && existsInC(); }
bool conflictingAges() const { return m_bConflictingAges; }
private:
bool fastFileComparison(FileAccess& fi1, FileAccess& fi2, bool& bError, QString& status, QSharedPointer<Options> const pOptions);
inline void setAgeA(const e_Age inAge) { m_ageA = inAge; }
......@@ -172,7 +190,6 @@ class MergeFileInfos
bool m_bOperationComplete;
bool m_bSimOpComplete;
public:
bool m_bEqualAB;
bool m_bEqualAC;
......
......@@ -178,8 +178,8 @@ class DirectoryMergeWindow::DirectoryMergeWindowPrivate : public QAbstractItemMo
bool isThreeWay() const
{
if(rootMFI() == nullptr || rootMFI()->getDirectoryInfo() == nullptr) return false;
return rootMFI()->getDirectoryInfo()->dirC().isValid();
if(rootMFI() == nullptr) return false;
return rootMFI()->isThreeWay();
}
MergeFileInfos* rootMFI() const { return m_pRoot; }
......@@ -1431,7 +1431,7 @@ void DirectoryMergeWindow::DirectoryMergeWindowPrivate::calcSuggestedOperation(c
{
if(!bCopyNewer || pMFI->isDirA())
setMergeOperation(mi, eDefaultMergeOp);
else if(bCopyNewer && pMFI->m_bConflictingAges)
else if(bCopyNewer && pMFI->conflictingAges())
{
setMergeOperation(mi, eConflictingAges);
}
......@@ -2894,31 +2894,14 @@ void DirectoryMergeWindow::updateFileVisibilities()
MergeFileInfos* pMFI = d->getMFI(mi);
bool bDir = pMFI->hasDir();
if(loop == 0 && bDir)
{
bool bChange = false;
if(!pMFI->isEqualAB() && pMFI->isDirA() == pMFI->isDirB() && pMFI->isLinkA() == pMFI->isLinkB())
{
pMFI->m_bEqualAB = true;
bChange = true;
}
if(!pMFI->isEqualBC() && pMFI->isDirC() == pMFI->isDirB() && pMFI->isLinkC() == pMFI->isLinkB())
{
pMFI->m_bEqualBC = true;
bChange = true;
}
if(!pMFI->isEqualAC() && pMFI->isDirA() == pMFI->isDirC() && pMFI->isLinkA() == pMFI->isLinkC())
{
pMFI->m_bEqualAC = true;
bChange = true;
}
if(bChange)
pMFI->updateAge();
{ //Treat all links and directories to equal by default.
pMFI->updateDirectoryOrLink();
}
bool bExistsEverywhere = pMFI->existsInA() && pMFI->existsInB() && (pMFI->existsInC() || !bThreeDirs);
int existCount = int(pMFI->existsInA()) + int(pMFI->existsInB()) + int(pMFI->existsInC());
bool bVisible =
(bShowIdentical && bExistsEverywhere && pMFI->isEqualAB() && (pMFI->isEqualAC() || !bThreeDirs)) || ((bShowDifferent || bDir) && existCount >= 2 && (!pMFI->isEqualAB() || !(pMFI->isEqualAC() || !bThreeDirs))) || (bShowOnlyInA && pMFI->existsInA() && !pMFI->existsInB() && !pMFI->existsInC()) || (bShowOnlyInB && !pMFI->existsInA() && pMFI->existsInB() && !pMFI->existsInC()) || (bShowOnlyInC && !pMFI->existsInA() && !pMFI->existsInB() && pMFI->existsInC());
(bShowIdentical && pMFI->existsEveryWhere() && pMFI->isEqualAB() && (pMFI->isEqualAC() || !bThreeDirs)) ||
((bShowDifferent || bDir) && pMFI->existsCount() >= 2 && (!pMFI->isEqualAB() || !(pMFI->isEqualAC() || !bThreeDirs))) ||
(bShowOnlyInA && pMFI->onlyInA()) || (bShowOnlyInB && pMFI->onlyInB()) || (bShowOnlyInC && pMFI->onlyInC());
QString fileName = pMFI->fileName();
bVisible = bVisible && ((bDir && !Utils::wildcardMultiMatch(d->m_pOptions->m_DmDirAntiPattern, fileName, d->m_bCaseSensitive)) || (Utils::wildcardMultiMatch(d->m_pOptions->m_DmFilePattern, fileName, d->m_bCaseSensitive) && !Utils::wildcardMultiMatch(d->m_pOptions->m_DmFileAntiPattern, fileName, d->m_bCaseSensitive)));
......@@ -2928,33 +2911,7 @@ void DirectoryMergeWindow::updateFileVisibilities()
bool bEqual = bThreeDirs ? pMFI->isEqualAB() && pMFI->isEqualAC() : pMFI->isEqualAB();
if(!bEqual && bVisible && loop == 0) // Set all parents to "not equal"
{
MergeFileInfos* p2 = pMFI->parent();
while(p2 != nullptr)
{
bool bChange = false;
if(!pMFI->isEqualAB() && p2->isEqualAB())
{
p2->m_bEqualAB = false;
bChange = true;
}
if(!pMFI->isEqualAC() && p2->isEqualAC())
{
p2->m_bEqualAC = false;
bChange = true;
}
if(!pMFI->isEqualBC() && p2->isEqualBC())
{
p2->m_bEqualBC = false;
bChange = true;
}
if(bChange)
p2->updateAge();
else
break;
p2 = p2->parent();
}
pMFI->updateParents();
}
mi = d->treeIterator(mi, true, true);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment