} else {
wcAccess = createWCAccess();
info = wcAccess.openAnchor(path, true, SVNWCAccess.INFINITE_DEPTH);
}
final SVNReporter reporter = new SVNReporter(info, path, true, false, depth, false, false, !depthIsSticky, getDebugLog());
SVNAdminArea anchorArea = info.getAnchor();
SVNEntry entry = anchorArea.getVersionedEntry(anchorArea.getThisDirName(), false);
SVNURL sourceURL = entry.getSVNURL();
if (sourceURL == null) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_MISSING_URL, "Directory ''{0}'' has no URL", anchorArea.getRoot());
SVNErrorManager.error(err, SVNLogType.WC);
}
long[] revs = new long[1];
// should fail on missing repository.
SVNRepository repository = createRepository(url, null, anchorArea, pegRevision, revision, revs);
long revNumber = revs[0];
url = repository.getLocation();
// root of the switched repos.
SVNURL sourceRoot = repository.getRepositoryRoot(true);
if (!SVNPathUtil.isAncestor(sourceRoot.toString(), sourceURL.toString())) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_INVALID_SWITCH, "''{0}''\nis not the same repository as\n''{1}''",
new Object[] {url.toString(), sourceRoot.toString()});
SVNErrorManager.error(err, SVNLogType.WC);
}
if (depthIsSticky && depth.compareTo(SVNDepth.INFINITY) < 0) {
SVNEntry targetEntry = anchorArea.getEntry(info.getTargetName(), true);
if (targetEntry != null && targetEntry.isDirectory()) {
SVNWCManager.crop(info, depth);
}
}
// reparent to the sourceURL
repository.setLocation(sourceURL, false);
String[] preservedExts = getOptions().getPreservedConflictFileExtensions();
ISVNUpdateEditor editor = wcAccess.createUpdateEditor(info, url.toString(),
allowUnversionedObstructions, depthIsSticky, depth, preservedExts, null, false);
ISVNEditor filterEditor = SVNAmbientDepthFilterEditor.wrap(editor, info, depthIsSticky);
String target = "".equals(info.getTargetName()) ? null : info.getTargetName();
repository.update(url, revNumber, target, depth, reporter, SVNCancellableEditor.newInstance(filterEditor, this, getDebugLog()));
long targetRevision = editor.getTargetRevision();
if (targetRevision >= 0 && !isIgnoreExternals() && depth.isRecursive()) {
url = target == null ? url : url.removePathTail();
handleExternals(wcAccess, info.getAnchor().getRoot(), info.getOldExternals(), info.getNewExternals(),
info.getDepths(), url, sourceRoot, depth, false, true);
}
dispatchEvent(SVNEventFactory.createSVNEvent(info.getTarget().getRoot(), SVNNodeKind.NONE, null,
targetRevision, SVNEventAction.UPDATE_COMPLETED, null, null, null, reporter.getReportedFilesCount(), reporter.getTotalFilesCount()));
return targetRevision;
} finally {
if (closeAccess) {
wcAccess.close();
}