Subversion: correctly determine local path by URL (fix SvnCommittedViewTest)

This commit is contained in:
irengrig
2013-02-01 18:02:08 +04:00
parent bc95bb4158
commit 7b183e2366
2 changed files with 34 additions and 1 deletions
@@ -40,6 +40,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.SvnBundle;
import org.jetbrains.idea.svn.SvnRevisionNumber;
import org.jetbrains.idea.svn.SvnUtil;
import org.jetbrains.idea.svn.SvnVcs;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.io.SVNRepository;
@@ -65,7 +66,16 @@ public class SvnRepositoryContentRevision implements ContentRevision, MarkerVcsC
myFilePath = localPath;
}
else {
myFilePath = VcsContextFactory.SERVICE.getInstance().createFilePathOnNonLocal(myPath, false);
FilePath local;
try {
final String fullPath = SvnUtil.appendMultiParts(repositoryRoot, myPath);
local = VcsContextFactory.SERVICE.getInstance().createFilePathOnNonLocal(fullPath, false);
}
catch (SVNException e) {
// todo what to do safely?
local = VcsContextFactory.SERVICE.getInstance().createFilePathOnNonLocal(repositoryRoot, false);
}
myFilePath = local;
}
myRevision = revision;
}
@@ -16,12 +16,18 @@
package org.jetbrains.idea.svn.history;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.RepositoryLocation;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.NotNullFunction;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.RootUrlInfo;
import org.jetbrains.idea.svn.SvnUtil;
import org.jetbrains.idea.svn.SvnVcs;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.util.SVNURLUtil;
import java.io.File;
@@ -62,9 +68,26 @@ public class SvnRepositoryLocation implements RepositoryLocation {
@Nullable
public static FilePath getLocalPath(final String fullPath, final NotNullFunction<File, Boolean> detector, final SvnVcs vcs) {
if (vcs.getProject().isDefault()) return null;
final SVNURL fullPathURL;
try {
fullPathURL = SVNURL.parseURIEncoded(fullPath);
}
catch (SVNException e) {
return null;
}
final RootUrlInfo rootForUrl = vcs.getSvnFileUrlMapping().getWcRootForUrl(fullPath);
if (rootForUrl != null) {
return LocationDetector.filePathByUrlAndPath(fullPath, rootForUrl.getUrl().toString(), rootForUrl.getIoFile().getAbsolutePath(), detector);
} else {
final VirtualFile[] underVcs = ProjectLevelVcsManager.getInstance(vcs.getProject()).getRootsUnderVcs(vcs);
if (underVcs.length == 0) return null;
for (VirtualFile vf : underVcs) {
final File ioFile = new File(vf.getPath());
final SVNURL url = SvnUtil.getUrl(vcs, ioFile);
if (url != null && SVNURLUtil.isAncestor(url, fullPathURL)) {
return LocationDetector.filePathByUrlAndPath(fullPath, url.toString(), ioFile.getPath(), detector);
}
}
}
return null;