public static void add(File path, SVNAdminArea parentDir, SVNURL copyFromURL, long copyFromRev) throws SVNException { SVNWCAccess wcAccess = parentDir.getWCAccess(); SVNFileType fileType = SVNFileType.getType(path); if (fileType == SVNFileType.NONE) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_PATH_NOT_FOUND, "''{0}'' not found", path); SVNErrorManager.error(err); } else if (fileType == SVNFileType.UNKNOWN) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_PATH_NOT_FOUND, "Unsupported node kind for path ''{0}''", path); SVNErrorManager.error(err); } SVNAdminArea dir = wcAccess.probeTry(path, true, copyFromURL != null ? SVNWCAccess.INFINITE_DEPTH : 0); SVNEntry entry = null; if (dir != null) { entry = wcAccess.getEntry(path, true); } boolean replace = false; SVNNodeKind kind = SVNFileType.getNodeKind(fileType); if (entry != null) { if (copyFromURL == null && !entry.isScheduledForDeletion() && !entry.isDeleted()) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_EXISTS, "''{0}'' is already under version control", path); SVNErrorManager.error(err); } else if (entry.getKind() != kind) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_NODE_KIND_CHANGE, "Can''t replace ''{0}'' with a node of a different type; the deletion must be committed and the parent updated before adding ''{0}''", path); SVNErrorManager.error(err); } replace = entry.isScheduledForDeletion(); } SVNEntry parentEntry = wcAccess.getEntry(path.getParentFile(), false); if (parentEntry == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, "Can''t find parent directory's entry while trying to add ''{0}''", path); SVNErrorManager.error(err); } if (parentEntry.isScheduledForDeletion()) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_SCHEDULE_CONFLICT, "Can''t add ''{0}'' to a parent directory scheduled for deletion", path); SVNErrorManager.error(err); } Map command = new HashMap(); String name = path.getName(); if (copyFromURL != null) { if (parentEntry.getRepositoryRoot() != null && !SVNPathUtil.isAncestor(parentEntry.getRepositoryRoot(), copyFromURL.toString())) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE, "The URL ''{0}'' has a different repository root than its parent", copyFromURL); SVNErrorManager.error(err); } command.put(SVNProperty.shortPropertyName(SVNProperty.COPYFROM_URL), copyFromURL.toString()); command.put(SVNProperty.shortPropertyName(SVNProperty.COPYFROM_REVISION), SVNProperty.toString(copyFromRev)); command.put(SVNProperty.shortPropertyName(SVNProperty.COPIED), Boolean.TRUE.toString()); } if (replace) { command.put(SVNProperty.shortPropertyName(SVNProperty.CHECKSUM), null); } command.put(SVNProperty.shortPropertyName(SVNProperty.SCHEDULE), SVNProperty.SCHEDULE_ADD); command.put(SVNProperty.shortPropertyName(SVNProperty.KIND), SVNFileType.getNodeKind(fileType).toString()); if (!(replace || copyFromURL != null)) { command.put(SVNProperty.shortPropertyName(SVNProperty.REVISION), "0"); } parentDir.modifyEntry(name, command, true, false);  if (entry != null && copyFromURL == null) { String propPath = SVNAdminUtil.getPropPath(name, entry.getKind(), false); File propFile = dir.getFile(propPath); SVNFileUtil.deleteFile(propFile); } if (kind == SVNNodeKind.DIR) { if (copyFromURL == null) { SVNEntry pEntry = wcAccess.getEntry(path.getParentFile(), false); SVNURL newURL = pEntry.getSVNURL().appendPath(name, false); ensureAdmiAreaExists(path, newURL.toString(), pEntry.getRepositoryRootURL().toString(), pEntry.getUUID(), 0); } else { ensureAdmiAreaExists(path, copyFromURL.toString(), parentEntry.getRepositoryRootURL().toString(), parentEntry.getUUID(), copyFromRev); } if (entry == null || entry.isDeleted()) { dir = wcAccess.open(path, true, copyFromURL != null ? SVNWCAccess.INFINITE_DEPTH : 0); } command.put(SVNProperty.shortPropertyName(SVNProperty.INCOMPLETE), null); command.put(SVNProperty.shortPropertyName(SVNProperty.SCHEDULE), replace ? SVNProperty.SCHEDULE_REPLACE : SVNProperty.SCHEDULE_ADD); dir.modifyEntry(dir.getThisDirName(), command, true, true); if (copyFromURL != null) { SVNURL newURL = parentEntry.getSVNURL().appendPath(name, false); updateCleanup(path, wcAccess, true, newURL.toString(), parentEntry.getRepositoryRoot(), -1, false); markTree(dir, null, true, COPIED); SVNPropertiesManager.deleteWCProperties(dir, null, true); } } SVNEvent event = SVNEventFactory.createAddedEvent(parentDir, name, kind, null); parentDir.getWCAccess().handleEvent(event);
public static void add(File path, SVNAdminArea parentDir, SVNURL copyFromURL, SVNRevision copyFromRev) throws SVNException { add(path, parentDir, copyFromURL, copyFromRev.getNumber());
    public static void add(File path, SVNAdminArea parentDir, SVNURL copyFromURL, long copyFromRev) throws SVNException {        SVNWCAccess wcAccess = parentDir.getWCAccess();        SVNFileType fileType = SVNFileType.getType(path);        if (fileType == SVNFileType.NONE) {            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_PATH_NOT_FOUND, "''{0}'' not found", path);            SVNErrorManager.error(err);        } else if (fileType == SVNFileType.UNKNOWN) {            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_PATH_NOT_FOUND, "Unsupported node kind for path ''{0}''", path);            SVNErrorManager.error(err);        }        SVNAdminArea dir = wcAccess.probeTry(path, true, copyFromURL != null ? SVNWCAccess.INFINITE_DEPTH : 0);        SVNEntry entry = null;        if (dir != null) {            entry = wcAccess.getEntry(path, true);        }        boolean replace = false;        SVNNodeKind kind = SVNFileType.getNodeKind(fileType);        if (entry != null) {            if (copyFromURL == null && !entry.isScheduledForDeletion() && !entry.isDeleted()) {                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_EXISTS, "''{0}'' is already under version control", path);                SVNErrorManager.error(err);            } else if (entry.getKind() != kind) {                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_NODE_KIND_CHANGE,                         "Can''t replace ''{0}'' with a node of a different type; the deletion must be committed and the parent updated before adding ''{0}''", path);                SVNErrorManager.error(err);            }            replace = entry.isScheduledForDeletion();        }        SVNEntry parentEntry = wcAccess.getEntry(path.getParentFile(), false);        if (parentEntry == null) {            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND,                     "Can''t find parent directory's entry while trying to add ''{0}''", path);            SVNErrorManager.error(err);        }        if (parentEntry.isScheduledForDeletion()) {            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_SCHEDULE_CONFLICT,                     "Can''t add ''{0}'' to a parent directory scheduled for deletion", path);            SVNErrorManager.error(err);        }        Map command = new HashMap();        String name = path.getName();        if (copyFromURL != null) {            if (parentEntry.getRepositoryRoot() != null && !SVNPathUtil.isAncestor(parentEntry.getRepositoryRoot(), copyFromURL.toString())) {                SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE,                         "The URL ''{0}'' has a different repository root than its parent", copyFromURL);                SVNErrorManager.error(err);            }            command.put(SVNProperty.shortPropertyName(SVNProperty.COPYFROM_URL), copyFromURL.toString());            command.put(SVNProperty.shortPropertyName(SVNProperty.COPYFROM_REVISION), SVNProperty.toString(copyFromRev));            command.put(SVNProperty.shortPropertyName(SVNProperty.COPIED), Boolean.TRUE.toString());        }        if (replace) {            command.put(SVNProperty.shortPropertyName(SVNProperty.CHECKSUM), null);        }        command.put(SVNProperty.shortPropertyName(SVNProperty.SCHEDULE), SVNProperty.SCHEDULE_ADD);        command.put(SVNProperty.shortPropertyName(SVNProperty.KIND), SVNFileType.getNodeKind(fileType).toString());        if (!(replace || copyFromURL != null)) {            command.put(SVNProperty.shortPropertyName(SVNProperty.REVISION), "0");        }        parentDir.modifyEntry(name, command, true, false);                if (entry != null && copyFromURL == null) {            String propPath = SVNAdminUtil.getPropPath(name, entry.getKind(), false);            File propFile = dir.getFile(propPath);            SVNFileUtil.deleteFile(propFile);        }        if (kind == SVNNodeKind.DIR) {            if (copyFromURL == null) {                SVNEntry pEntry = wcAccess.getEntry(path.getParentFile(), false);                SVNURL newURL = pEntry.getSVNURL().appendPath(name, false);                ensureAdmiAreaExists(path, newURL.toString(), pEntry.getRepositoryRootURL().toString(), pEntry.getUUID(), 0);            } else {                ensureAdmiAreaExists(path, copyFromURL.toString(), parentEntry.getRepositoryRootURL().toString(), parentEntry.getUUID(), copyFromRev);            }            if (entry == null || entry.isDeleted()) {                dir = wcAccess.open(path, true, copyFromURL != null ? SVNWCAccess.INFINITE_DEPTH : 0);            }            command.put(SVNProperty.shortPropertyName(SVNProperty.INCOMPLETE), null);            command.put(SVNProperty.shortPropertyName(SVNProperty.SCHEDULE), replace ? SVNProperty.SCHEDULE_REPLACE : SVNProperty.SCHEDULE_ADD);            dir.modifyEntry(dir.getThisDirName(), command, true, true);            if (copyFromURL != null) {                SVNURL newURL = parentEntry.getSVNURL().appendPath(name, false);                updateCleanup(path, wcAccess, true, newURL.toString(), parentEntry.getRepositoryRoot(), -1, false);                markTree(dir, null, true, COPIED);                SVNPropertiesManager.deleteWCProperties(dir, null, true);            }        }        SVNEvent event = SVNEventFactory.createAddedEvent(parentDir, name, kind, null);        parentDir.getWCAccess().handleEvent(event);    }