Commit 30cfbda9 authored by agurov's avatar agurov

Prompt that asks what to do after project relocation shown in a loop forever (bug 482565)

https://bugs.eclipse.org/bugs/show_bug.cgi?id=482565

git-svn-id: https://dev.eclipse.org/svnroot/technology/org.eclipse.subversive/trunk@21517 ee007c2a-0a25-0410-9ab9-bf268980928c
parent 2e41d2c4
......@@ -95,11 +95,11 @@ public class SVNTeamProvider extends RepositoryProvider implements IConnectedPro
}
public synchronized void relocateResource() throws CoreException {
//does not affect finite automate state
if (this.state != 1) {
this.restoreLocation();
}
SVNTeamProvider.setRepositoryLocation(this.getProject(), this.location);
this.state = 0;
}
public static void map(IProject project, IRepositoryResource resource) throws CoreException {
......
......@@ -11,7 +11,9 @@
package org.eclipse.team.svn.core.operation.local.management;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.eclipse.core.resources.IProject;
......@@ -30,6 +32,7 @@ import org.eclipse.team.svn.core.connector.SVNChangeStatus;
import org.eclipse.team.svn.core.connector.SVNDepth;
import org.eclipse.team.svn.core.operation.IConsoleStream;
import org.eclipse.team.svn.core.operation.IUnprotectedOperation;
import org.eclipse.team.svn.core.operation.SVNNullProgressMonitor;
import org.eclipse.team.svn.core.operation.SVNProgressMonitor;
import org.eclipse.team.svn.core.operation.local.AbstractWorkingCopyOperation;
import org.eclipse.team.svn.core.resource.IRepositoryLocation;
......@@ -75,28 +78,30 @@ public class RelocateWorkingCopyOperation extends AbstractWorkingCopyOperation i
try {
final IRepositoryResource []children = this.location.getRepositoryRoot().getChildren();
final String rootUrl = this.location.getRepositoryRootUrl();
final HashSet<String> processedPaths = new HashSet<String>(); // handle nested projects
for (int i = 0; i < projects.length && !monitor.isCanceled(); i++) {
final IProject current = (IProject)projects[i];
this.protectStep(new IUnprotectedOperation() {
public void run(IProgressMonitor monitor) throws Exception {
SVNTeamProvider provider = (SVNTeamProvider)RepositoryProvider.getProvider(current, SVNTeamPlugin.NATURE_ID);
IPath fsLocation = current.getLocation();
if (fsLocation != null) {
String path = fsLocation.toString();
SVNChangeStatus st = SVNUtility.getSVNInfoForNotConnected(current);
if (st != null) {
String url = SVNUtility.decodeURL(st.url);
String oldRoot = SVNUtility.getOldRoot(url, children);
if (oldRoot != null) {
RelocateWorkingCopyOperation.this.writeToConsole(IConsoleStream.LEVEL_CMD, "svn switch --relocate \"" + oldRoot + "\" \"" + rootUrl + "\" \"" + FileUtility.normalizePath(path) + "\"" + FileUtility.getUsernameParam(RelocateWorkingCopyOperation.this.location.getUsername()) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
proxy.relocate(oldRoot, rootUrl, path, SVNDepth.INFINITY, new SVNProgressMonitor(RelocateWorkingCopyOperation.this, monitor, null));
//XXX: provider.relocateResource();
provider.switchResource(RelocateWorkingCopyOperation.this.location.asRepositoryContainer(rootUrl + url.substring(oldRoot.length()), false));
RelocateWorkingCopyOperation.this.resources.add(current);
IPath fsLocation = FileUtility.getResourcePath(current);
if (fsLocation != FileUtility.getAlwaysIgnoredPath()) {
String path = RelocateWorkingCopyOperation.this.getWCRootPath(fsLocation.toString());
if (!processedPaths.contains(path)) {
SVNChangeStatus []stats = SVNUtility.status(proxy, path, SVNDepth.EMPTY, ISVNConnector.Options.INCLUDE_UNCHANGED, new SVNNullProgressMonitor());
if (stats.length > 0 && stats[0].url != null) {
String url = SVNUtility.decodeURL(stats[0].url);
String newURL = RelocateWorkingCopyOperation.this.remapURL(url, children);
if (!url.equals(newURL)) {
RelocateWorkingCopyOperation.this.writeToConsole(IConsoleStream.LEVEL_CMD, "svn switch --relocate \"" + newURL + "\" \"" + FileUtility.normalizePath(path) + "\"" + FileUtility.getUsernameParam(RelocateWorkingCopyOperation.this.location.getUsername()) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
proxy.relocate(url, newURL, path, SVNDepth.INFINITY, new SVNProgressMonitor(RelocateWorkingCopyOperation.this, monitor, null));
}
}
processedPaths.add(path);
}
SVNTeamProvider provider = (SVNTeamProvider)RepositoryProvider.getProvider(current, SVNTeamPlugin.NATURE_ID);
provider.relocateResource();
RelocateWorkingCopyOperation.this.resources.add(current);
}
}
}, monitor, projects.length);
......@@ -107,6 +112,25 @@ public class RelocateWorkingCopyOperation extends AbstractWorkingCopyOperation i
}
}
public String remapURL(String oldUrl, IRepositoryResource []rootChildren) {
for (int i = 0; i < rootChildren.length; i++) {
String childName = rootChildren[i].getName();
int idx = oldUrl.indexOf(childName);
if (idx > 0 && oldUrl.charAt(idx - 1) == '/' && (oldUrl.endsWith(childName) || oldUrl.charAt(idx + childName.length()) == '/')) {
return rootChildren[i].getUrl() + oldUrl.substring(idx + childName.length());
}
}
return null;
}
protected String getWCRootPath(String path) {
File wcDB = FileUtility.findWCDB(new File(path));
if (wcDB != null) {
return wcDB.getParentFile().getParent();
}
return path;
}
protected String getShortErrorMessage(Throwable t) {
return BaseMessages.format(super.getShortErrorMessage(t), new Object[] {this.location.getUrl()});
}
......
......@@ -1319,8 +1319,8 @@ public class SVNRemoteStorage extends AbstractSVNStorage implements IRemoteStora
this.setCachedResource(local);
if (current.getType() == IResource.PROJECT && !this.changeMonitorMap.containsKey(current)) {
File wcDB = this.findWCDB(new File(FileUtility.getResourcePath(current).toString()));
if (wcDB != null && wcDB.exists()) {
File wcDB = FileUtility.findWCDB(FileUtility.getResourcePath(current).toFile());
if (wcDB != null) {
this.changeMonitorMap.put(current, wcDB);
}
}
......@@ -1328,21 +1328,6 @@ public class SVNRemoteStorage extends AbstractSVNStorage implements IRemoteStora
return local;
}
protected File findWCDB(File folder) {
String fragment = "/" + SVNUtility.getSVNFolderName() + "/wc.db"; //$NON-NLS-1$
File target = null;
do
{
target = new File(folder.getAbsolutePath() + fragment);
if (target.exists()) {
return target;
}
folder = folder.getParentFile();
}
while (folder != null);
return null;
}
protected ILocalResource getFirstExistingParentLocal(IResource node) {
IResource parent = node.getParent();
if (parent == null) {
......
......@@ -70,6 +70,21 @@ public final class FileUtility {
public static final IResource []NO_CHILDREN = new IResource[0];
private static IPath ALWAYS_IGNORED_PATH = null;
public static File findWCDB(File folder) {
String fragment = "/" + SVNUtility.getSVNFolderName() + "/wc.db"; //$NON-NLS-1$
File target = null;
do
{
target = new File(folder.getAbsolutePath() + fragment);
if (target.exists()) {
return target;
}
folder = folder.getParentFile();
}
while (folder != null);
return null;
}
public static boolean isSymlink(IResource resource) {
// Files.isSymbolicLink(Paths.get(FileUtility.getWorkingCopyPath(resource)));
URI uri = null;
......
......@@ -404,17 +404,6 @@ public final class SVNUtility {
return SVNMessages.getString("Status_" + status); //$NON-NLS-1$
}
public static String getOldRoot(String oldUrl, IRepositoryResource []rootChildren) {
for (int i = 0; i < rootChildren.length; i++) {
String childName = rootChildren[i].getName();
int idx = oldUrl.indexOf(childName);
if (idx > 0 && oldUrl.charAt(idx - 1) == '/' && (oldUrl.endsWith(childName) || oldUrl.charAt(idx + childName.length()) == '/')) {
return oldUrl.substring(0, idx - 1);
}
}
return null;
}
public static IRepositoryRoot getTrunkLocation(IRepositoryResource resource) {
return SVNUtility.getRootLocation(resource, resource.getRepositoryLocation().getTrunkLocation(), IRepositoryRoot.KIND_TRUNK);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment