TreeMap<String, SVNLogEntryPath> sortedPaths = new TreeMap<String, SVNLogEntryPath>(logEntry.getChangedPaths());
Transaction changeSet = fModelMapper.createTransaction(logEntry.getDate());
// I get the first logEntryPath, the one containing the creation of the tag folder and I create a release with
// that
SVNLogEntryPath tagPath = sortedPaths.values().iterator().next();
SVNRelease release =
fModelMapper.createRelease(
logEntry.getDate(),
changeSet,
logEntry.getMessage(),
logEntry.getAuthor(),
tagPath.getPath(),
tagPath.getCopyPath(),
tagPath.getCopyRevision(),
logEntry.getRevision());
// I iterate over remaining log entry paths
sortedPaths.remove(tagPath.getPath());
ArrayList<SVNLogEntryPath> delete = new ArrayList<SVNLogEntryPath>();
TreeMap<String, SVNLogEntryPath> add = new TreeMap<String, SVNLogEntryPath>();
TreeMap<String, SVNLogEntryPath> replace = new TreeMap<String, SVNLogEntryPath>();
ArrayList<SVNLogEntryPath> alreadyAdded = new ArrayList<SVNLogEntryPath>();
// I get all the single log entry paths and classify them as delete, add or replace
for (SVNLogEntryPath logEntryPath : sortedPaths.values()) {
if (logEntryPath.getType() == SVNLogEntryPath.TYPE_DELETED) {
delete.add(logEntryPath);
} else if (logEntryPath.getType() == SVNLogEntryPath.TYPE_ADDED) {
add.put(logEntryPath.getPath().replace(tagPath.getPath(), ""), logEntryPath);
} else if (logEntryPath.getType() == SVNLogEntryPath.TYPE_REPLACED) {
replace.put(logEntryPath.getPath().replace(tagPath.getPath(), ""), logEntryPath);
}
}
/*
* I iterate over the replaces of the log entry
* Since they are stored in a TreeMap, they are sorted by their names ==> which also means by their path length.
* In this way if there are chains of recursive replacements inside some directories,
* I will always replace the father before the child, thus always having consistent data!
*/
for (SVNLogEntryPath replaceEntry : replace.values()) {
// for each replace I check whether there is any parent directory involved in an ADD operation.
// If so I first take care of those related ADD operations
for (SVNLogEntryPath addEntry : add.values()) {
if (replaceEntry.getPath().contains(addEntry.getPath())) {
/*
* I also keep track of the ADDs that I already took care of, as
* multiple replacements might share a common directory that has been added and thus
* I need to be sure that I add it to the release only once!
*/
if (!alreadyAdded.contains(addEntry)) {
alreadyAdded.add(addEntry);
// add to release
addToRelease(addEntry, logEntry, release, changeSet);
}
}
}
// eventually I do the replace
fModelMapper.replaceInRelease(
release,
changeSet,
logEntry.getDate(),
logEntry.getMessage(),
logEntry.getAuthor(),
replaceEntry.getPath(),
replaceEntry.getCopyPath(),
replaceEntry.getCopyRevision(),
logEntry.getRevision());
}
for (SVNLogEntryPath addEntry : add.values()) {
if (!alreadyAdded.contains(addEntry)) {
addToRelease(addEntry, logEntry, release, changeSet);
}
}
// At last I take care of deletes, after I did all the replacement and additions in the current log
for (SVNLogEntryPath deleteEntry : delete) {
LOGGER.debug(NLS.bind(
ImporterMessages.EvolizerSVNImporter_deleteFromRelease,
deleteEntry.getPath(),
release.getName()));
fModelMapper.removeFromRelease(release, deleteEntry.getPath());
}
ArrayList<String> toDelete = new ArrayList<String>();
for (SVNLogEntryPath deleteEntry : delete) {
toDelete.add(deleteEntry.getPath());
}
fModelMapper.finalizeTransaction(changeSet, toDelete);
fModelMapper.finalizeRelease(release);
LOGGER.debug(NLS.bind(ImporterMessages.EvolizerSVNImporter_createdRelease, release.getName()));
}