From: Robin Rosenberg <robin.rosenberg.lists@dewire.com>
To: Stephen Bannasch <stephen.bannasch@deanbrook.org>
Cc: "Shawn O. Pearce" <spearce@spearce.org>, git@vger.kernel.org
Subject: [EGIT RFC PATCH(was Re: egit problem with sym linked eclipse project dirs)] Add some support for symlinked projects.
Date: Wed, 11 Mar 2009 23:17:41 +0100 [thread overview]
Message-ID: <200903112317.41380.robin.rosenberg.lists@dewire.com> (raw)
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>:
> 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
next prev parent reply other threads:[~2009-03-11 22:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-13 20:00 egit problem with sym linked eclipse project dirs Stephen Bannasch
2009-01-13 21:37 ` Robin Rosenberg
2009-01-13 23:27 ` Stephen Bannasch
2009-01-23 1:56 ` Stephen Bannasch
2009-01-23 21:33 ` Robin Rosenberg
2009-03-11 22:17 ` Robin Rosenberg [this message]
2009-03-12 2:57 ` [EGIT RFC PATCH(was Re: egit problem with sym linked eclipse project dirs)] Add some support for symlinked projects Stephen Bannasch
2009-03-12 6:56 ` Robin Rosenberg
2009-03-18 16:02 ` Stephen Bannasch
2009-03-18 21:09 ` Robin Rosenberg
2009-03-18 21:10 ` Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200903112317.41380.robin.rosenberg.lists@dewire.com \
--to=robin.rosenberg.lists@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
--cc=stephen.bannasch@deanbrook.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).