[EGIT RFC PATCH(was Re: egit problem with sym linked eclipse project dirs)] Add some support for symlinked projects.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If a project is not in therepository via the path we found it,  we look for its canonical path and
see if that path is in the repository.

We only do this lookup at the project level. Odd linking at resource level
will not be recognized because this lookup is expensive.
---
 .../egit/core/project/RepositoryMapping.java       |   54 ++++++++++++++++++-
 1 files changed, 51 insertions(+), 3 deletions(-)

fredag 23 januari 2009 22:33:59 skrev Robin Rosenberg <robin.rosenberg.lists@xxxxxxxxxx>:
> fredag 23 januari 2009 02:56:16 skrev Stephen Bannasch:
> > At 6:27 PM -0500 1/13/09, Stephen Bannasch wrote:
> ...
> > >Done: http://code.google.com/p/egit/issues/detail?id=52
> > >
> > >Fxing this will make using Eclipse and Git together SO much nicer!

Since I started looking at this, I may as well post what I came up with before
I lost interest in the issue.

This patch solved some of the problem. I'm not sure it doesn't cause more
problem than it solves, e.g. should the solution support more fine grained
handling of links, be faster or.. 

Shawn: don't  push in this state. 
Stephen: come up with a test suite and pro's cons, potholes etc.

-- robin

diff --git a/org.spearce.egit.core/src/org/spearce/egit/core/project/RepositoryMapping.java b/org.spearce.egit.core/src/org/spearce/egit/core/project/RepositoryMapping.java
index e9df630..f2a0977 100644
--- a/org.spearce.egit.core/src/org/spearce/egit/core/project/RepositoryMapping.java
+++ b/org.spearce.egit.core/src/org/spearce/egit/core/project/RepositoryMapping.java
@@ -23,6 +23,7 @@
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.team.core.RepositoryProvider;
+import org.spearce.egit.core.Activator;
 import org.spearce.egit.core.GitProvider;
 import org.spearce.jgit.lib.Constants;
 import org.spearce.jgit.lib.GitIndex;
@@ -49,6 +50,10 @@ static boolean isInitialKey(final String key) {
 
 	private IContainer container;
 
+	private String replace;
+
+	private String replaceWith;
+
 	/**
 	 * Construct a {@link RepositoryMapping} for a previously connected project.
 	 *
@@ -97,6 +102,45 @@ public RepositoryMapping(final IContainer mappedContainer, final File gitDir) {
 		}
 	}
 
+	private void checkIsLinked() {
+		File containerFile = container.getLocation().toFile();
+		String absoluteContainer = containerFile.getAbsoluteFile().getPath();
+		String canonicalContainer;
+		try {
+			canonicalContainer = containerFile.getCanonicalFile().getPath();
+			if (!absoluteContainer.equals(canonicalContainer)) {
+				int ic = canonicalContainer.length() - 1;
+				int ac = absoluteContainer.length() - 1;
+				char lastCh = File.separatorChar;
+				while (ic >= 0 && ac >= 0) {
+					char curchar = canonicalContainer.charAt(ic);
+					if (curchar != absoluteContainer.charAt(ac)) {
+						if (lastCh == File.separatorChar) {
+							String linkPointSrc = absoluteContainer.substring(
+									0, ac + 1);
+							String linkPointDest = canonicalContainer
+									.substring(workdirPrefix.length(), ic + 1);
+							replace = linkPointSrc.substring(
+									workdirPrefix.length()).replace(
+									File.separatorChar, '/');
+							replaceWith = linkPointDest.replace(
+									File.separatorChar, '/');
+							break;
+						}
+					}
+					lastCh = curchar;
+					ic--;
+					ac--;
+				}
+				if (ic == 0 || ac == 0)
+					Activator.logError(String.format("Cannot find the canonical location of %s within the repo %s", containerFile.toString(), gitdirPath), null);
+
+			}
+		} catch (IOException e) {
+			Activator.logError("Cannot get canonical path for container " + container.toString(), e);
+		}
+	}
+
 	IPath getContainerPath() {
 		return Path.fromPortableString(containerPath);
 	}
@@ -136,6 +180,7 @@ synchronized void setRepository(final Repository r) {
 		workdirPrefix = workdirPrefix.replace('\\', '/');
 		if (!workdirPrefix.endsWith("/"))
 			workdirPrefix += "/";
+		checkIsLinked();
 	}
 
 	/**
@@ -209,9 +254,12 @@ public String getRepoRelativePath(final IResource rsrc) {
 		final int pfxLen = workdirPrefix.length();
 		final String p = rsrc.getLocation().toString();
 		final int pLen = p.length();
-		if (pLen > pfxLen)
+		if (pLen > pfxLen) {
+			if (replace != null) {
+				return replaceWith + "/" + p.substring(pfxLen + replace.length() + 1);
+			}
 			return p.substring(pfxLen);
-		else if (p.length() == pfxLen - 1)
+		} else if (p.length() == pfxLen - 1)
 			return "";
 		return null;
 	}
-- 
1.6.1.285.g35d8b

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux