break;
}
}
}
File baseDir = new Resource(rootPath).getAbsoluteFile();
rootPath = baseDir.getAbsolutePath().replace(File.separatorChar, '/');
Collection dirsToLock = new SVNHashSet(); // relative paths to lock.
Collection dirsToLockRecursively = new SVNHashSet();
if (relativePaths.isEmpty()) {
statusClient.checkCancelled();
String target = SVNWCManager.getActualTarget(baseDir);
if (!"".equals(target)) {
// we will have to lock target as well, not only base dir.
SVNFileType targetType = SVNFileType.getType(new Resource(rootPath));
relativePaths.add(target);
if (targetType == SVNFileType.DIRECTORY) {
// lock recursively if forced and copied...
if (depth == SVNDepth.INFINITY || depth == SVNDepth.IMMEDIATES ||
(force && isRecursiveCommitForced(baseDir))) {
// dir is copied, include children
dirsToLockRecursively.add(target);
} else {
dirsToLock.add(target);
}
}
baseDir = baseDir.getParentFile();
} else {
lockAll = true;
}
} else if (!lockAll) {
baseDir = adjustRelativePaths(baseDir, relativePaths);
// there are multiple paths.
for (Iterator targets = relativePaths.iterator(); targets.hasNext();) {
statusClient.checkCancelled();
String targetPath = (String) targets.next();
File targetFile = new Resource(baseDir, targetPath);
SVNFileType targetKind = SVNFileType.getType(targetFile);
if (targetKind == SVNFileType.DIRECTORY) {
if (depth == SVNDepth.INFINITY || depth == SVNDepth.IMMEDIATES ||
(force && isRecursiveCommitForced(targetFile))) {
dirsToLockRecursively.add(targetPath);
} else if (!targetFile.equals(baseDir)){
dirsToLock.add(targetPath);
}
}
if (!targetFile.equals(baseDir)) {
targetFile = targetFile.getParentFile();
targetPath = SVNPathUtil.removeTail(targetPath);
while (targetFile != null && !targetFile.equals(baseDir) && !dirsToLock.contains(targetPath)) {
dirsToLock.add(targetPath);
targetPath = SVNPathUtil.removeTail(targetPath);
targetFile = targetFile.getParentFile();
}
}
}
}
SVNWCAccess baseAccess = SVNWCAccess.newInstance(new ISVNEventHandler() {
public void handleEvent(SVNEvent event, double progress) throws SVNException {
}
public void checkCancelled() throws SVNCancelException {
statusClient.checkCancelled();
}
});
baseAccess.setOptions(statusClient.getOptions());
try {
baseAccess.open(baseDir, true, lockAll ? SVNWCAccess.INFINITE_DEPTH : 0);
statusClient.checkCancelled();
dirsToLock = new ArrayList(dirsToLock);
dirsToLockRecursively = new ArrayList(dirsToLockRecursively);
Collections.sort((List) dirsToLock, SVNPathUtil.PATH_COMPARATOR);
Collections.sort((List) dirsToLockRecursively, SVNPathUtil.PATH_COMPARATOR);
if (!lockAll) {
List uniqueDirsToLockRecursively = new ArrayList();
uniqueDirsToLockRecursively.addAll(dirsToLockRecursively);
Map processedPaths = new SVNHashMap();
for(Iterator ps = uniqueDirsToLockRecursively.iterator(); ps.hasNext();) {
String pathToLock = (String) ps.next();
if (processedPaths.containsKey(pathToLock)) {
//remove any duplicates
ps.remove();
continue;
}
processedPaths.put(pathToLock, pathToLock);
for(Iterator existing = dirsToLockRecursively.iterator(); existing.hasNext();) {
String existingPath = (String) existing.next();
if (pathToLock.startsWith(existingPath + "/")) {
// child of other path
ps.remove();
break;
}
}
}
Collections.sort(uniqueDirsToLockRecursively, SVNPathUtil.PATH_COMPARATOR);
dirsToLockRecursively = uniqueDirsToLockRecursively;
removeRedundantPaths(dirsToLockRecursively, dirsToLock);
for (Iterator nonRecusivePaths = dirsToLock.iterator(); nonRecusivePaths.hasNext();) {
statusClient.checkCancelled();
String path = (String) nonRecusivePaths.next();
File pathFile = new Resource(baseDir, path);
baseAccess.open(pathFile, true, 0);
}
for (Iterator recusivePaths = dirsToLockRecursively.iterator(); recusivePaths.hasNext();) {
statusClient.checkCancelled();
String path = (String) recusivePaths.next();
File pathFile = new Resource(baseDir, path);
baseAccess.open(pathFile, true, SVNWCAccess.INFINITE_DEPTH);
}
}
for(int i = 0; i < paths.length; i++) {