aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2011-01-30 09:52:37 -0500
committerChris Aniszczyk2011-01-31 11:12:38 -0500
commit5024c9193da8b3987d7651f6d97d961fea87458b (patch)
tree79cfd8a1836f40d7ccfeea39f52d64a1f23a9567
parentc03562f2202231d55e84eb761bb1462fd69a584a (diff)
downloadegit-5024c9193da8b3987d7651f6d97d961fea87458b.zip
egit-5024c9193da8b3987d7651f6d97d961fea87458b.tar.gz
egit-5024c9193da8b3987d7651f6d97d961fea87458b.tar.xz
[sync] Fix StackOverflowError and cache/working tree model
After change I137e703f Cache tree and Working tree model does not have any containers because cached structure of tree cannot be build properly based on IPath keys. Therefore I decided to revert part of this change in case of working tree and cache tree models. In previous implementation the StackOverflowError can occures when repository contains a file without extension, now this should be also fixed. Change-Id: I46570795605aae9b77910281db8ce9760ce8e70d Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCache.java28
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTree.java29
2 files changed, 36 insertions, 21 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCache.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCache.java
index b51d27b..6b445e4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCache.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCache.java
@@ -42,9 +42,11 @@ public class GitModelCache extends GitModelObjectContainer {
*/
protected int dirCacheIteratorNth;
+ private final Path location;
+
private final FileModelFactory fileFactory;
- private final Map<IPath, GitModelCacheTree> cacheTreeMap;
+ private final Map<String, GitModelCacheTree> cacheTreeMap;
private static final int BASE_NTH = 0;
@@ -111,7 +113,8 @@ public class GitModelCache extends GitModelObjectContainer {
FileModelFactory fileFactory) throws IOException {
super(parent, baseCommit, RIGHT);
this.fileFactory = fileFactory;
- cacheTreeMap = new HashMap<IPath, GitModelCacheTree>();
+ cacheTreeMap = new HashMap<String, GitModelCacheTree>();
+ location = new Path(getRepository().getWorkTree().toString());
}
@Override
@@ -174,15 +177,15 @@ public class GitModelCache extends GitModelObjectContainer {
return null;
if (shouldIncludeEntry(tw)) {
- IPath path = getLocation().append(tw.getPathString());
+ String path = tw.getPathString();
ObjectId repoId = tw.getObjectId(BASE_NTH);
ObjectId cacheId = tw.getObjectId(REMOTE_NTH);
- if (path.getFileExtension() == null)
+ if (path.contains("/")) //$NON-NLS-1$
return handleCacheTree(repoId, cacheId, path);
return fileFactory.createFileModel(this, baseCommit, repoId,
- cacheId, path);
+ cacheId, getLocation().append(path));
}
return null;
@@ -199,22 +202,25 @@ public class GitModelCache extends GitModelObjectContainer {
}
private GitModelObject handleCacheTree(ObjectId repoId, ObjectId cacheId,
- IPath path) throws IOException {
- GitModelCacheTree cacheTree = cacheTreeMap.get(path);
+ String path) throws IOException {
+ int firstSlash = path.indexOf("/");//$NON-NLS-1$
+ String pathKey = path.substring(0, firstSlash);
+ GitModelCacheTree cacheTree = cacheTreeMap.get(pathKey);
if (cacheTree == null) {
cacheTree = new GitModelCacheTree(this, baseCommit, repoId,
- cacheId, path, fileFactory);
- cacheTreeMap.put(path, cacheTree);
+ cacheId, getLocation().append(pathKey), fileFactory);
+ cacheTreeMap.put(pathKey, cacheTree);
}
- cacheTree.addChild(repoId, cacheId, path);
+ cacheTree.addChild(repoId, cacheId,
+ path.substring(firstSlash + 1));
return cacheTree;
}
@Override
public IPath getLocation() {
- return new Path(getRepository().getWorkTree().toString());
+ return location;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTree.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTree.java
index 2a20b49..169d1ca 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTree.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTree.java
@@ -26,7 +26,7 @@ public class GitModelCacheTree extends GitModelTree {
private final FileModelFactory factory;
- private final Map<IPath, GitModelObject> cacheTreeMap;
+ private final Map<String, GitModelObject> cacheTreeMap;
/**
* @param parent
@@ -47,7 +47,7 @@ public class GitModelCacheTree extends GitModelTree {
FileModelFactory factory) throws IOException {
super(parent, commit, null, repoId, repoId, cacheId, location);
this.factory = factory;
- cacheTreeMap = new HashMap<IPath, GitModelObject>();
+ cacheTreeMap = new HashMap<String, GitModelObject>();
}
@Override
@@ -60,20 +60,29 @@ public class GitModelCacheTree extends GitModelTree {
return super.hashCode();
}
- void addChild(ObjectId repoId, ObjectId cacheId, IPath path)
+ void addChild(ObjectId repoId, ObjectId cacheId, String path)
throws IOException {
- if (path.getFileExtension() == null) {
+ String pathKey;
+ int firstSlash = path.indexOf("/"); //$NON-NLS-1$
+ if (firstSlash > -1)
+ pathKey = path.substring(0, firstSlash);
+ else
+ pathKey = path;
+
+ IPath fullPath = getLocation().append(pathKey);
+ if (path.contains("/")) { //$NON-NLS-1$
GitModelCacheTree cacheEntry = (GitModelCacheTree) cacheTreeMap
- .get(path);
+ .get(pathKey);
if (cacheEntry == null) {
cacheEntry = new GitModelCacheTree(this, baseCommit, repoId,
- cacheId, path, factory);
- cacheTreeMap.put(path, cacheEntry);
+ cacheId, fullPath, factory);
+ cacheTreeMap.put(pathKey, cacheEntry);
}
- cacheEntry.addChild(repoId, cacheId, path);
+ cacheEntry.addChild(repoId, cacheId,
+ path.substring(firstSlash + 1));
} else
- cacheTreeMap.put(path, factory.createFileModel(this,
- baseCommit, repoId, cacheId, path));
+ cacheTreeMap.put(pathKey, factory.createFileModel(this,
+ baseCommit, repoId, cacheId, fullPath));
}
@Override