git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Robin Rosenberg <robin.rosenberg.lists@dewire.com>
Date
Mar 11, 2009, 22:17 UTC
Message-ID
<200903112317.41380.robin.rosenberg.lists@dewire.com>
In-Reply-To
<200901232233.59232.robin.rosenberg.lists@dewire.com>

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@dewire.com>:
Show 6 quoted lines
> 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
Previous: Robin RosenbergNext: Stephen Bannasch
Message 6 of 11 in “egit problem with sym linked eclipse project dirs”
  1. Stephen BannaschJan 13, 2009
  2. Robin RosenbergJan 13, 2009
  3. Stephen BannaschJan 13, 2009
  4. Stephen BannaschJan 23, 2009
  5. Robin RosenbergJan 23, 2009
  6. Add some support for symlinked projects.Robin Rosenberg, Mar 11, 2009
  7. Stephen BannaschMar 12, 2009
  8. Robin RosenbergMar 12, 2009
  9. Stephen BannaschMar 18, 2009
  10. Robin RosenbergMar 18, 2009
  11. Robin RosenbergMar 18, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.