mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-12-04 15:52:46 -08:00
refactor: remove unused merge methods
This commit is contained in:
1 parent
cc0530ba46
commit
f7fd3881e3
6 files changed
+3
-219
No files matched your search
+3
-99
@@ -257,76 +257,6 @@ void Merger::eraseGroup(Group* group)
|
||||
database->setDeletedObjects(deletions);
|
||||
}
|
||||
|
||||
Merger::ChangeList
|
||||
Merger::resolveEntryConflict_Duplicate(const MergeContext& context, const Entry* sourceEntry, Entry* targetEntry)
|
||||
{
|
||||
ChangeList changes;
|
||||
const int comparison = compare(targetEntry->timeInfo().lastModificationTime(),
|
||||
sourceEntry->timeInfo().lastModificationTime(),
|
||||
CompareItemIgnoreMilliseconds);
|
||||
// if one entry is newer, create a clone and add it to the group
|
||||
if (comparison < 0) {
|
||||
Entry* clonedEntry = sourceEntry->clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory);
|
||||
moveEntry(clonedEntry, context.m_targetGroup);
|
||||
markOlderEntry(targetEntry);
|
||||
changes << tr("Adding backup for older target %1 [%2]").arg(targetEntry->title(), targetEntry->uuidToHex());
|
||||
} else if (comparison > 0) {
|
||||
Entry* clonedEntry = sourceEntry->clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory);
|
||||
moveEntry(clonedEntry, context.m_targetGroup);
|
||||
markOlderEntry(clonedEntry);
|
||||
changes << tr("Adding backup for older source %1 [%2]").arg(sourceEntry->title(), sourceEntry->uuidToHex());
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
Merger::ChangeList
|
||||
Merger::resolveEntryConflict_KeepLocal(const MergeContext& context, const Entry* sourceEntry, Entry* targetEntry)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
ChangeList changes;
|
||||
const int comparison = compare(targetEntry->timeInfo().lastModificationTime(),
|
||||
sourceEntry->timeInfo().lastModificationTime(),
|
||||
CompareItemIgnoreMilliseconds);
|
||||
if (comparison < 0) {
|
||||
// we need to make our older entry "newer" than the new entry - therefore
|
||||
// we just create a new history entry without any changes - this preserves
|
||||
// the old state before merging the new state and updates the timestamp
|
||||
// the merge takes care, that the newer entry is sorted inbetween both entries
|
||||
// this type of merge changes the database timestamp since reapplying the
|
||||
// old entry is an active change of the database!
|
||||
changes << tr("Reapplying older target entry on top of newer source %1 [%2]")
|
||||
.arg(targetEntry->title(), targetEntry->uuidToHex());
|
||||
Entry* agedTargetEntry = targetEntry->clone(Entry::CloneNoFlags);
|
||||
targetEntry->addHistoryItem(agedTargetEntry);
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
Merger::ChangeList
|
||||
Merger::resolveEntryConflict_KeepRemote(const MergeContext& context, const Entry* sourceEntry, Entry* targetEntry)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
ChangeList changes;
|
||||
const int comparison = compare(targetEntry->timeInfo().lastModificationTime(),
|
||||
sourceEntry->timeInfo().lastModificationTime(),
|
||||
CompareItemIgnoreMilliseconds);
|
||||
if (comparison > 0) {
|
||||
// we need to make our older entry "newer" than the new entry - therefore
|
||||
// we just create a new history entry without any changes - this preserves
|
||||
// the old state before merging the new state and updates the timestamp
|
||||
// the merge takes care, that the newer entry is sorted inbetween both entries
|
||||
// this type of merge changes the database timestamp since reapplying the
|
||||
// old entry is an active change of the database!
|
||||
changes << tr("Reapplying older source entry on top of newer target %1 [%2]")
|
||||
.arg(targetEntry->title(), targetEntry->uuidToHex());
|
||||
targetEntry->beginUpdate();
|
||||
targetEntry->copyDataFrom(sourceEntry);
|
||||
targetEntry->endUpdate();
|
||||
// History item is created by endUpdate since we should have changes
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
Merger::ChangeList Merger::resolveEntryConflict_MergeHistories(const MergeContext& context,
|
||||
const Entry* sourceEntry,
|
||||
Entry* targetEntry,
|
||||
@@ -366,38 +296,12 @@ Merger::ChangeList Merger::resolveEntryConflict_MergeHistories(const MergeContex
|
||||
Merger::ChangeList
|
||||
Merger::resolveEntryConflict(const MergeContext& context, const Entry* sourceEntry, Entry* targetEntry)
|
||||
{
|
||||
ChangeList changes;
|
||||
// We need to cut off the milliseconds since the persistent format only supports times down to seconds
|
||||
// so when we import data from a remote source, it may represent the (or even some msec newer) data
|
||||
// which may be discarded due to higher runtime precision
|
||||
|
||||
Group::MergeMode mergeMode = m_mode == Group::Default ? context.m_targetGroup->mergeMode() : m_mode;
|
||||
switch (mergeMode) {
|
||||
case Group::Duplicate:
|
||||
changes << resolveEntryConflict_Duplicate(context, sourceEntry, targetEntry);
|
||||
break;
|
||||
|
||||
case Group::KeepLocal:
|
||||
changes << resolveEntryConflict_KeepLocal(context, sourceEntry, targetEntry);
|
||||
changes << resolveEntryConflict_MergeHistories(context, sourceEntry, targetEntry, mergeMode);
|
||||
break;
|
||||
|
||||
case Group::KeepRemote:
|
||||
changes << resolveEntryConflict_KeepRemote(context, sourceEntry, targetEntry);
|
||||
changes << resolveEntryConflict_MergeHistories(context, sourceEntry, targetEntry, mergeMode);
|
||||
break;
|
||||
|
||||
case Group::Synchronize:
|
||||
case Group::KeepNewer:
|
||||
// nothing special to do since resolveEntryConflictMergeHistories takes care to use the newest entry
|
||||
changes << resolveEntryConflict_MergeHistories(context, sourceEntry, targetEntry, mergeMode);
|
||||
break;
|
||||
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
return changes;
|
||||
return resolveEntryConflict_MergeHistories(context, sourceEntry, targetEntry, mergeMode);
|
||||
}
|
||||
|
||||
bool Merger::mergeHistory(const Entry* sourceEntry, Entry* targetEntry, Group::MergeMode mergeMethod)
|
||||
@@ -408,8 +312,8 @@ bool Merger::mergeHistory(const Entry* sourceEntry, Entry* targetEntry, Group::M
|
||||
const int comparison = compare(sourceEntry->timeInfo().lastModificationTime(),
|
||||
targetEntry->timeInfo().lastModificationTime(),
|
||||
CompareItemIgnoreMilliseconds);
|
||||
const bool preferLocal = mergeMethod == Group::KeepLocal || comparison < 0;
|
||||
const bool preferRemote = mergeMethod == Group::KeepRemote || comparison > 0;
|
||||
const bool preferLocal = comparison < 0;
|
||||
const bool preferRemote = comparison > 0;
|
||||
|
||||
QMap<QDateTime, Entry*> merged;
|
||||
for (Entry* historyItem : targetHistoryItems) {
|
||||
|
||||
Reference in new issue
Block a user