# # # patch "src/model/Inventory.cpp" # from [63a2f7d906ea4aaaccb8f64c63425efe50ca488e] # to [71b1d68fbad33d2b5325e725728b29a49c51e6a0] # ============================================================ --- src/model/Inventory.cpp 63a2f7d906ea4aaaccb8f64c63425efe50ca488e +++ src/model/Inventory.cpp 71b1d68fbad33d2b5325e725728b29a49c51e6a0 @@ -212,118 +212,6 @@ void Inventory::processTaskResult(const emit inventoryRead(queriedPath); } -QMap Inventory::findUnaccountedRenames() const -{ - QList missingItems; - QList unknownItems; - - foreach (InventoryItem * item, itemMap.values()) - { - if (item->hasStatus(InventoryItem::Missing)) - { - missingItems.append(item); - } - - if (item->hasStatus(InventoryItem::Unknown)) - { - unknownItems.append(item); - } - } - - // TODO: progess bar here! - QString parentRev = MonotoneUtil::getBaseWorkspaceRevision(workspacePath); - FileEntryList parentList = MonotoneUtil::getRevisionManifest( - MonotoneUtil::getDatabaseFile(workspacePath), - parentRev - ); - - QMap unaccountedRenames; - QMap fileIds; - - foreach (InventoryItem * missingItem, missingItems) - { - FileEntryList candidates; - FileEntry entry; - - // this is a new entry not recorded in the base roster - if (missingItem->hasStatus(InventoryItem::Added) || - missingItem->hasStatus(InventoryItem::RenameTarget)) - { - entry.path = missingItem->getPath(); - entry.is_dir = missingItem->isDirectory(); - } - else - { - bool found = false; - foreach (entry, parentList) - { - if (entry.path == missingItem->getPath()) - { - found = true; - break; - } - } - I(found); - } - - foreach (InventoryItem * unknownItem, unknownItems) - { - QString unknownPath = unknownItem->getPath(); - - // calculate the file id of the unknown file - if (!unknownItem->isDirectory() && - !fileIds.contains(unknownPath)) - { - QString fileid = MonotoneUtil::getFileId( - MonotoneUtil::getDatabaseFile(workspacePath), - unknownPath - ); - // file was not readable, etc. - if (fileid.isEmpty()) continue; - fileIds.insert(unknownPath, fileid); - } - - // at first do a simple file name check for items of the same type - if (missingItem->isDirectory() == unknownItem->isDirectory()) - { - // equal names / different paths or different names / equal paths - if (missingItem->getFilename() == unknownItem->getFilename() || - missingItem->getBaseDirectory() == unknownItem->getBaseDirectory()) - { - FileEntry can(unknownPath, unknownItem->isDirectory()); - if (fileIds.contains(unknownPath)) - { - can.fileid = fileIds.value(unknownPath); - } - candidates.append(can); - continue; - } - } - - // we can't do anything for directories from here on - if (missingItem->isDirectory() || unknownItem->isDirectory()) - continue; - - // we now rely on the fact that we have a fileid - I(fileIds.contains(unknownPath)); - - if (fileIds.value(unknownPath) == entry.fileid) - { - candidates.append(FileEntry(unknownPath, false, entry.fileid)); - } - } - - // only add those missing items to the map which are having any - // candidates, i.e. are likely to be renamed - if (candidates.size() > 0) - { - unaccountedRenames.insert(entry, candidates); - } - } - - return unaccountedRenames; -} - void Inventory::insertRowsRecursive(ModelItem * parentItem, const QMap > & parentChildRelations) { I(parentItem); @@ -451,3 +339,115 @@ void Inventory::removeRowsRecursive(Mode emit endRemoveRows(); } +QMap Inventory::findUnaccountedRenames() const +{ + QList missingItems; + QList unknownItems; + + foreach (InventoryItem * item, itemMap.values()) + { + if (item->hasStatus(InventoryItem::Missing)) + { + missingItems.append(item); + } + + if (item->hasStatus(InventoryItem::Unknown)) + { + unknownItems.append(item); + } + } + + // TODO: progess bar here! + QString parentRev = MonotoneUtil::getBaseWorkspaceRevision(workspacePath); + FileEntryList parentList = MonotoneUtil::getRevisionManifest( + MonotoneUtil::getDatabaseFile(workspacePath), + parentRev + ); + + QMap unaccountedRenames; + QMap fileIds; + + foreach (InventoryItem * missingItem, missingItems) + { + FileEntryList candidates; + FileEntry entry; + + // this is a new entry not recorded in the base roster + if (missingItem->hasStatus(InventoryItem::Added) || + missingItem->hasStatus(InventoryItem::RenameTarget)) + { + entry.path = missingItem->getPath(); + entry.is_dir = missingItem->isDirectory(); + } + else + { + bool found = false; + foreach (entry, parentList) + { + if (entry.path == missingItem->getPath()) + { + found = true; + break; + } + } + I(found); + } + + foreach (InventoryItem * unknownItem, unknownItems) + { + QString unknownPath = unknownItem->getPath(); + + // calculate the file id of the unknown file + if (!unknownItem->isDirectory() && + !fileIds.contains(unknownPath)) + { + QString fileid = MonotoneUtil::getFileId( + MonotoneUtil::getDatabaseFile(workspacePath), + unknownPath + ); + // file was not readable, etc. + if (fileid.isEmpty()) continue; + fileIds.insert(unknownPath, fileid); + } + + // at first do a simple file name check for items of the same type + if (missingItem->isDirectory() == unknownItem->isDirectory()) + { + // equal names / different paths or different names / equal paths + if (missingItem->getFilename() == unknownItem->getFilename() || + missingItem->getBaseDirectory() == unknownItem->getBaseDirectory()) + { + FileEntry can(unknownPath, unknownItem->isDirectory()); + if (fileIds.contains(unknownPath)) + { + can.fileid = fileIds.value(unknownPath); + } + candidates.append(can); + continue; + } + } + + // we can't do anything for directories from here on + if (missingItem->isDirectory() || unknownItem->isDirectory()) + continue; + + // we now rely on the fact that we have a fileid + I(fileIds.contains(unknownPath)); + + if (fileIds.value(unknownPath) == entry.fileid) + { + candidates.append(FileEntry(unknownPath, false, entry.fileid)); + } + } + + // only add those missing items to the map which are having any + // candidates, i.e. are likely to be renamed + if (candidates.size() > 0) + { + unaccountedRenames.insert(entry, candidates); + } + } + + return unaccountedRenames; +} +