if (commitPackets == null || commitPackets.length == 0) {
return new SVNCommitInfo[0];
}
Collection tmpFiles = null;
SVNCommitInfo info = null;
ISVNEditor commitEditor = null;
Collection infos = new ArrayList();
boolean needsSleepForTimeStamp = false;
for (int p = 0; p < commitPackets.length; p++) {
SVNCommitPacket commitPacket = commitPackets[p].removeSkippedItems();
if (commitPacket.getCommitItems().length == 0) {
continue;
}
try {
commitMessage = getCommitHandler().getCommitMessage(commitMessage, commitPacket.getCommitItems());
if (commitMessage == null) {
infos.add(SVNCommitInfo.NULL);
continue;
}
commitMessage = validateCommitMessage(commitMessage);
Map commitables = new TreeMap();
String baseURL = SVNCommitUtil.translateCommitables(commitPacket.getCommitItems(), commitables);
Map lockTokens = SVNCommitUtil.translateLockTokens(commitPacket.getLockTokens(), baseURL);
SVNRepository repository = createRepository(SVNURL.parseURIEncoded(baseURL), true);
SVNCommitMediator mediator = new SVNCommitMediator(commitables);
tmpFiles = mediator.getTmpFiles();
String repositoryRoot = repository.getRepositoryRoot(true).getPath();
commitEditor = repository.getCommitEditor(commitMessage, lockTokens, keepLocks, mediator);
// commit.
// set event handler for each wc access.
for (int i = 0; i < commitPacket.getCommitItems().length; i++) {
commitPacket.getCommitItems()[i].getWCAccess().setEventHandler(getEventDispatcher());
}
info = SVNCommitter.commit(mediator.getTmpFiles(), commitables, repositoryRoot, commitEditor);
// update wc.
Collection processedItems = new HashSet();
Collection explicitCommitPaths = new HashSet();
for (Iterator urls = commitables.keySet().iterator(); urls.hasNext();) {
String url = (String) urls.next();
SVNCommitItem item = (SVNCommitItem) commitables.get(url);
explicitCommitPaths.add(item.getPath());
}
for (Iterator urls = commitables.keySet().iterator(); urls.hasNext();) {
String url = (String) urls.next();
SVNCommitItem item = (SVNCommitItem) commitables.get(url);
SVNWCAccess wcAccess = item.getWCAccess();
String path = item.getPath();
SVNAdminArea dir = null;
String target = null;
try {
if (item.getKind() == SVNNodeKind.DIR) {
dir = wcAccess.retrieve(item.getFile());
target = "";
} else {
dir = wcAccess.retrieve(item.getFile().getParentFile());
target = SVNPathUtil.tail(path);
}
} catch (SVNException e) {
if (e.getErrorMessage().getErrorCode() == SVNErrorCode.WC_NOT_LOCKED) {
dir = null;
}
}
if (dir == null) {
if (hasProcessedParents(processedItems, path)) {
processedItems.add(path);
continue;
}
if (item.isDeleted() && item.getKind() == SVNNodeKind.DIR) {
File parentPath = "".equals(path) ? null : item.getFile().getParentFile();
String nameInParent = "".equals(path) ? null : SVNPathUtil.tail(path);
if (parentPath != null) {
SVNAdminArea parentDir = wcAccess.retrieve(parentPath);
if (parentDir != null) {
SVNEntry entryInParent = parentDir.getEntry(nameInParent, true);
if (entryInParent != null) {
entryInParent.unschedule();
entryInParent.setDeleted(true);
parentDir.saveEntries(false);
}
}
}
processedItems.add(path);
continue;
}
}
SVNEntry entry = dir.getEntry(target, true);
if (entry == null && hasProcessedParents(processedItems, path)) {
processedItems.add(path);
continue;
}
boolean recurse = false;
if (item.isAdded() && item.getCopyFromURL() != null && item.getKind() == SVNNodeKind.DIR) {
recurse = true;
}
boolean removeLock = !keepLocks && item.isLocked();
// update entry in dir.
Map wcPropChanges = mediator.getWCProperties(item);
dir.commit(target, info, wcPropChanges, removeLock, recurse, explicitCommitPaths, getCommitParameters());
processedItems.add(path);
}
needsSleepForTimeStamp = true;
// commit completed, include revision number.
dispatchEvent(SVNEventFactory.createCommitCompletedEvent(null, info.getNewRevision()), ISVNEventHandler.UNKNOWN);
} catch (SVNException e) {
if (e instanceof SVNCancelException) {
throw e;
}
SVNErrorMessage err = SVNErrorMessage.create(e.getErrorMessage().getErrorCode(), "Commit failed (details follow):");
err.setChildErrorMessage(e.getErrorMessage());
infos.add(new SVNCommitInfo(-1, null, null, err));
dispatchEvent(new SVNEvent(err), ISVNEventHandler.UNKNOWN);
continue;
} finally {
if (info == null && commitEditor != null) {
try {