List<Revision> revisions =
fPersistenceProvider.query("FROM SVNRevision as f WHERE f.file.path LIKE '" + fromPath
+ "%' ORDER BY f.file.path", Revision.class);
HashMap<String, SVNRevision> m = new HashMap<String, SVNRevision>();
for (Revision rev : revisions) {
SVNRevision r = (SVNRevision) rev;
SVNRevision found = m.get(r.getFile().getPath());
if (found == null) {
if (Long.parseLong(r.getNumber()) <= copyRevision) {
m.put(r.getFile().getPath(), r);
}
} else if (Long.parseLong(r.getNumber()) <= copyRevision
&& Long.parseLong(r.getNumber()) > Long.parseLong(found.getNumber())) {
m.put(r.getFile().getPath(), r);
}
}
for (String key : m.keySet()) {
SVNRevision oldRevision = m.get(key);
String oldRevisionFileName = oldRevision.getFile().getPath();
String newRevisionFileName = oldRevisionFileName.replaceFirst(fromPath, toPath);
if (oldRevision.getState() == null) {
// I create the new SVNRevision which will have as a revision number the one of the branch/release
// creation
SVNRevision newRevision = new SVNRevision(revisionNum + "");
ModificationReport report = this.createModificationReport(creationTime, commitMessage, author);
newRevision.setReport(report);
// I also need to create a new File, as it is actually done by the SVN
// It's the same of the old one, but with a different path
SVNVersionedFile newFile = (SVNVersionedFile) createFile(newRevisionFileName);
newRevision.setChangeSet(changeSet);
changeSet.addRevision(newRevision); // Transaction -> SVNRevision
newFile.addRevision(newRevision); // File -> SVNRevision
newRevision.setFile(newFile); // SVNRevision -> File
// Keep track of a new file ancestor
newRevision.setAncestor(oldRevision);
// I check whether I'm connecting the new SVNRevision to a Branch or to a Release
if ((branch != null) && (release == null)) {
// Now I add the newly created file version to the Branch and viceversa
branch.addRevision(newRevision); // Branch -> SVNRevision
LOGGER.debug(NLS.bind(MapperMessages.SVNModelMapper_addedRevisionToBranch, new String[]{
newRevision.getFile().getPath(),
newRevision.getNumber(),
branch.getName(),
oldRevision.getFile().getPath(),
oldRevision.getNumber()}));
} else if ((branch == null) && (release != null)) {
// I add the newly created file version to the Release and viceversa
release.addReleaseRevision(newRevision);
LOGGER.debug(NLS.bind(MapperMessages.SVNModelMapper_addedRevisionToRelease, new String[]{
newRevision.getFile().getPath(),
newRevision.getNumber(),
release.getName(),
oldRevision.getFile().getPath(),
oldRevision.getNumber()}));
}
}