SVNRepository repos = null; SVNFileType srcKind = SVNFileType.getType(path); List newPaths = new ArrayList(); SVNURL rootURL = dstURL; while (true) { try { repos = createRepository(rootURL, true); } catch (SVNException e) { SVNErrorManager.error("svn: invalid URL '" + dstURL + "'"); } if (repos == null) { SVNErrorManager.error("svn: invalid URL '" + dstURL + "'"); } else if (repos.checkPath("", -1) == SVNNodeKind.NONE) { newPaths.add(SVNPathUtil.tail(rootURL.getPath())); rootURL = rootURL.removePathTail(); } else { break; } } if (newPaths.isEmpty() && (srcKind == SVNFileType.FILE || srcKind == SVNFileType.SYMLINK)) { SVNErrorManager.error("svn: Path '" + dstURL + "' already exists"); } if (newPaths.contains(SVNFileUtil.getAdminDirectoryName())) { SVNErrorManager.error("svn: '.svn' is a reserved name and cannot be imported"); } SVNCommitItem[] items = new SVNCommitItem[1]; items[0] = new SVNCommitItem(path, dstURL, null, srcKind == SVNFileType.DIRECTORY ? SVNNodeKind.DIR : SVNNodeKind.FILE, SVNRevision.UNDEFINED, true, false, false, false, false, false); commitMessage = getCommitHandler().getCommitMessage(commitMessage, items); if (commitMessage == null) { return SVNCommitInfo.NULL; } ISVNEditor commitEditor = repos.getCommitEditor(commitMessage, null, false, new SVNImportMediator(srcKind == SVNFileType.DIRECTORY ? path : path.getParentFile())); String filePath = ""; if (srcKind != SVNFileType.DIRECTORY) { filePath = (String) newPaths.remove(0); for (int i = 0; i < newPaths.size(); i++) { String newDir = (String) newPaths.get(i); filePath = newDir + "/" + filePath; } } checkCancelled(); commitEditor.openRoot(-1); String newDirPath = null; for (int i = newPaths.size() - 1; i >= 0; i--) { newDirPath = newDirPath == null ? (String) newPaths.get(i) : SVNPathUtil.append(newDirPath, (String) newPaths.get(i)); commitEditor.addDir(newDirPath, null, -1); } boolean changed; if (srcKind == SVNFileType.DIRECTORY) { changed = importDir(path, path, newDirPath, recursive, commitEditor); } else { changed = importFile(path.getParentFile(), path, srcKind, filePath, commitEditor); } if (!changed) { try { commitEditor.abortEdit(); } catch (SVNException e) {  } return SVNCommitInfo.NULL; } for (int i = 0; i < newPaths.size(); i++) { commitEditor.closeDir(); } SVNCommitInfo info = null; try { info = commitEditor.closeEdit(); } catch (SVNException e) { try { commitEditor.abortEdit(); } catch (SVNException e1) {  } throw e; } if (info != null && info.getNewRevision() >= 0) { dispatchEvent(SVNEventFactory.createCommitCompletedEvent(null, info.getNewRevision()), ISVNEventHandler.UNKNOWN); } return info != null ? info : SVNCommitInfo.NULL;
return doImport(path, dstURL, commitMessage, true, recursive);
    public SVNCommitInfo doImport(File path, SVNURL dstURL, String commitMessage, boolean recursive) throws SVNException {        // first find dstURL root.        SVNRepository repos = null;        SVNFileType srcKind = SVNFileType.getType(path);        List newPaths = new ArrayList();        SVNURL rootURL = dstURL;        while (true) {            try {                repos = createRepository(rootURL, true);            } catch (SVNException e) {                SVNErrorManager.error("svn: invalid URL '" + dstURL + "'");            }            if (repos == null) {                SVNErrorManager.error("svn: invalid URL '" + dstURL + "'");            } else if (repos.checkPath("", -1) == SVNNodeKind.NONE) {                newPaths.add(SVNPathUtil.tail(rootURL.getPath()));                rootURL = rootURL.removePathTail();            } else {                break;            }        }        if (newPaths.isEmpty() && (srcKind == SVNFileType.FILE || srcKind == SVNFileType.SYMLINK)) {            SVNErrorManager.error("svn: Path '" + dstURL + "' already exists");        }        if (newPaths.contains(SVNFileUtil.getAdminDirectoryName())) {            SVNErrorManager.error("svn: '.svn' is a reserved name and cannot be imported");        }        SVNCommitItem[] items = new SVNCommitItem[1];        items[0] = new SVNCommitItem(path, dstURL, null, srcKind == SVNFileType.DIRECTORY ? SVNNodeKind.DIR : SVNNodeKind.FILE, SVNRevision.UNDEFINED,                         true, false, false, false, false, false);        commitMessage = getCommitHandler().getCommitMessage(commitMessage, items);        if (commitMessage == null) {            return SVNCommitInfo.NULL;        }        ISVNEditor commitEditor = repos.getCommitEditor(commitMessage, null, false, new SVNImportMediator(srcKind == SVNFileType.DIRECTORY ? path : path.getParentFile()));        String filePath = "";        if (srcKind != SVNFileType.DIRECTORY) {            filePath = (String) newPaths.remove(0);            for (int i = 0; i < newPaths.size(); i++) {                String newDir = (String) newPaths.get(i);                filePath = newDir + "/" + filePath;            }        }        checkCancelled();        commitEditor.openRoot(-1);        String newDirPath = null;        for (int i = newPaths.size() - 1; i >= 0; i--) {            newDirPath = newDirPath == null ? (String) newPaths.get(i) : SVNPathUtil.append(newDirPath, (String) newPaths.get(i));            commitEditor.addDir(newDirPath, null, -1);        }        boolean changed;        if (srcKind == SVNFileType.DIRECTORY) {            changed = importDir(path, path, newDirPath, recursive, commitEditor);        } else {            changed = importFile(path.getParentFile(), path, srcKind, filePath, commitEditor);        }        if (!changed) {            try {                commitEditor.abortEdit();            } catch (SVNException e) {                //            }            return SVNCommitInfo.NULL;        }        for (int i = 0; i < newPaths.size(); i++) {            commitEditor.closeDir();        }        SVNCommitInfo info = null;        try {            info = commitEditor.closeEdit();        } catch (SVNException e) {            try {                commitEditor.abortEdit();            } catch (SVNException e1) {                // inner            }            throw e;        }        if (info != null && info.getNewRevision() >= 0) {             dispatchEvent(SVNEventFactory.createCommitCompletedEvent(null, info.getNewRevision()), ISVNEventHandler.UNKNOWN);        }        return info != null ? info : SVNCommitInfo.NULL;    }