if (topURL.equals(pair.mySource)) {
topURL = SVNPathUtil.removeTail(topURL);
}
}
}
SVNRepository topRepos = createRepository(SVNURL.parseURIEncoded(topURL), null, null, true);
List newDirs = new ArrayList();
if (makeParents) {
CopyPair pair = (CopyPair) copyPairs.get(0);
String relativeDir = SVNPathUtil.getPathAsChild(topURL, SVNPathUtil.removeTail(pair.myDst));
if (relativeDir != null) {
relativeDir = SVNEncodingUtil.uriDecode(relativeDir);
SVNNodeKind kind = topRepos.checkPath(relativeDir, -1);
while(kind == SVNNodeKind.NONE) {
newDirs.add(relativeDir);
relativeDir = SVNPathUtil.removeTail(relativeDir);
kind = topRepos.checkPath(relativeDir, -1);
}
}
}
String rootURL = topRepos.getRepositoryRoot(true).toString();
for (int i = 0; i < copyPairs.size(); i++) {
CopyPair pair = (CopyPair) copyPairs.get(i);
CopyPathInfo info = (CopyPathInfo) pathInfos.get(i);
if (!pair.myDst.equals(rootURL) && SVNPathUtil.getPathAsChild(pair.myDst, pair.mySource) != null) {
info.isResurrection = true;
// TODO still looks like a bug.
// if (SVNPathUtil.removeTail(pair.myDst).equals(topURL)) {
topURL = SVNPathUtil.removeTail(topURL);
// }
}
}
topRepos.setLocation(SVNURL.parseURIEncoded(topURL), false);
long latestRevision = topRepos.getLatestRevision();
for (int i = 0; i < copyPairs.size(); i++) {
CopyPair pair = (CopyPair) copyPairs.get(i);
CopyPathInfo info = (CopyPathInfo) pathInfos.get(i);
pair.mySourceRevisionNumber = getRevisionNumber(pair.mySourceRevision, topRepos, null);
info.mySourceRevisionNumber = pair.mySourceRevisionNumber;
SVNRepositoryLocation[] locations = getLocations(SVNURL.parseURIEncoded(pair.mySource), null, topRepos, pair.mySourcePegRevision, pair.mySourceRevision, SVNRevision.UNDEFINED);
pair.mySource = locations[0].getURL().toString();
String srcRelative = SVNPathUtil.getPathAsChild(topURL, pair.mySource);
if (srcRelative != null) {
srcRelative = SVNEncodingUtil.uriDecode(srcRelative);
} else {
srcRelative = "";
}
String dstRelative = SVNPathUtil.getPathAsChild(topURL, pair.myDst);
if (dstRelative != null) {
dstRelative = SVNEncodingUtil.uriDecode(dstRelative);
} else {
dstRelative = "";
}
if ("".equals(srcRelative) && isMove) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE, "Cannot move URL ''{0}'' into itself", SVNURL.parseURIEncoded(pair.mySource));
SVNErrorManager.error(err, SVNLogType.WC);
}
info.mySourceKind = topRepos.checkPath(srcRelative, pair.mySourceRevisionNumber);
if (info.mySourceKind == SVNNodeKind.NONE) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_NOT_FOUND,
"Path ''{0}'' does not exist in revision {1}", new Object[] {SVNURL.parseURIEncoded(pair.mySource), new Long(pair.mySourceRevisionNumber)});
SVNErrorManager.error(err, SVNLogType.WC);
}
SVNNodeKind dstKind = topRepos.checkPath(dstRelative, latestRevision);
if (dstKind != SVNNodeKind.NONE) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_ALREADY_EXISTS,
"Path ''{0}'' already exists", dstRelative);
SVNErrorManager.error(err, SVNLogType.WC);
}
info.mySource = pair.mySource;
info.mySourcePath = srcRelative;
info.myDstPath = dstRelative;
}
List paths = new ArrayList(copyPairs.size() * 2);
List commitItems = new ArrayList(copyPairs.size() * 2);
if (makeParents) {
for (Iterator newDirsIter = newDirs.iterator(); newDirsIter.hasNext();) {
String dirPath = (String) newDirsIter.next();
SVNURL itemURL = SVNURL.parseURIEncoded(SVNPathUtil.append(topURL, dirPath));
SVNCommitItem item = new SVNCommitItem(null, itemURL, null, SVNNodeKind.NONE, null, null, true, false, false, false, false, false);
commitItems.add(item);
}
}
for (Iterator infos = pathInfos.iterator(); infos.hasNext();) {
CopyPathInfo info = (CopyPathInfo) infos.next();
SVNURL itemURL = SVNURL.parseURIEncoded(SVNPathUtil.append(topURL, info.myDstPath));
SVNCommitItem item = new SVNCommitItem(null, itemURL, null, SVNNodeKind.NONE, null, null, true, false, false, false, false, false);
commitItems.add(item);
pathsMap.put(info.myDstPath, info);
if (isMove && !info.isResurrection) {
itemURL = SVNURL.parseURIEncoded(SVNPathUtil.append(topURL, info.mySourcePath));
item = new SVNCommitItem(null, itemURL, null, SVNNodeKind.NONE, null, null, false, true, false, false, false, false);
commitItems.add(item);
pathsMap.put(info.mySourcePath, info);
}
}
if (makeParents) {
for (Iterator newDirsIter = newDirs.iterator(); newDirsIter.hasNext();) {
String dirPath = (String) newDirsIter.next();
CopyPathInfo info = new CopyPathInfo();
info.myDstPath = dirPath;
info.isDirAdded = true;
paths.add(info.myDstPath);
pathsMap.put(dirPath, info);
}
}
for (Iterator infos = pathInfos.iterator(); infos.hasNext();) {
CopyPathInfo info = (CopyPathInfo) infos.next();
Map mergeInfo = calculateTargetMergeInfo(null, null, SVNURL.parseURIEncoded(info.mySource),
info.mySourceRevisionNumber, topRepos, false);
if (mergeInfo != null) {
info.myMergeInfoProp = SVNMergeInfoUtil.formatMergeInfoToString(mergeInfo, null);
}
paths.add(info.myDstPath);
if (isMove && !info.isResurrection) {
paths.add(info.mySourcePath);
}
}
SVNCommitItem[] commitables = (SVNCommitItem[]) commitItems.toArray(new SVNCommitItem[commitItems.size()]);
message = commitHandler.getCommitMessage(message, commitables);
if (message == null) {
return SVNCommitInfo.NULL;
}
message = SVNCommitUtil.validateCommitMessage(message);
revprops = commitHandler.getRevisionProperties(message, commitables, revprops == null ? new SVNProperties() : revprops);
if (revprops == null) {
return SVNCommitInfo.NULL;
}
// now do real commit.
ISVNEditor commitEditor = topRepos.getCommitEditor(message, null, true, revprops, null);
ISVNCommitPathHandler committer = new CopyCommitPathHandler(pathsMap, isMove);
SVNCommitInfo result = null;
try {
SVNCommitUtil.driveCommitEditor(committer, paths, commitEditor, latestRevision);