Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2010-05-28 10:25:40 +0000
committerCode Review2010-05-28 10:25:40 +0000
commit3fe5ae1c5ae3168f553303ad02aa25d1f60c6064 (patch)
treea5b085e34ff6ef7f4e2796c8a26058d1dcad84fa
parent6948fee4189fd689dc0efad2694bc1a9731ecba8 (diff)
parent506fb7a70eee7f970682e9218d599ea63bd0d88d (diff)
downloadegit-3fe5ae1c5ae3168f553303ad02aa25d1f60c6064.tar.gz
egit-3fe5ae1c5ae3168f553303ad02aa25d1f60c6064.tar.xz
egit-3fe5ae1c5ae3168f553303ad02aa25d1f60c6064.zip
Merge "Extract public class RepositoryCache from GitProjectData"
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java10
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryCache.java63
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java32
3 files changed, 77 insertions, 28 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java
index cf78246e74..4ef9aa18c8 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java
@@ -24,6 +24,7 @@ import org.osgi.util.tracker.ServiceTracker;
*/
public class Activator extends Plugin {
private static Activator plugin;
+ private RepositoryCache repositoryCache;
/**
* @return the singleton {@link Activator}
@@ -80,12 +81,21 @@ public class Activator extends Plugin {
GitTraceLocation.initializeFromOptions(opts, true);
}
+ repositoryCache = new RepositoryCache();
GitProjectData.reconfigureWindowCache();
GitProjectData.attachToWorkspace(true);
}
+ /**
+ * @return cache for Repository objects
+ */
+ public RepositoryCache getRepositoryCache() {
+ return repositoryCache;
+ }
+
public void stop(final BundleContext context) throws Exception {
GitProjectData.detachFromWorkspace();
+ repositoryCache = null;
super.stop(context);
plugin = null;
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryCache.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryCache.java
new file mode 100644
index 0000000000..ca7f96c3ed
--- /dev/null
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/RepositoryCache.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.jgit.lib.Repository;
+
+/**
+ * Central cache for Repository instances
+ *
+ */
+public class RepositoryCache {
+ private final Map<File, Reference<Repository>> repositoryCache = new HashMap<File, Reference<Repository>>();
+
+ RepositoryCache() {
+ // package private constructor
+ }
+
+ /**
+ *
+ * @param gitDir
+ * @return an existing instance of Repository for <code>gitDir</code> or a
+ * new one if no Repository instance for <code>gitDir</code> exists
+ * in the cache.
+ * @throws IOException
+ */
+ public synchronized Repository lookupRepository(final File gitDir)
+ throws IOException {
+ Reference<Repository> r = repositoryCache.get(gitDir);
+ Repository d = r != null ? r.get() : null;
+ if (d == null) {
+ d = new Repository(gitDir);
+ repositoryCache.put(gitDir, new WeakReference<Repository>(d));
+ }
+ prune(repositoryCache);
+ return d;
+ }
+
+ private static <K, V> void prune(Map<K, Reference<V>> map) {
+ for (final Iterator<Map.Entry<K, Reference<V>>> i = map.entrySet()
+ .iterator(); i.hasNext();) {
+ if (i.next().getValue().get() == null)
+ i.remove();
+ }
+ }
+
+}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java
index f9b21fa5b5..60550af6ad 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java
@@ -15,13 +15,10 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -40,12 +37,12 @@ import org.eclipse.egit.core.CoreText;
import org.eclipse.egit.core.GitCorePreferences;
import org.eclipse.egit.core.GitProvider;
import org.eclipse.egit.core.internal.trace.GitTraceLocation;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.WindowCache;
import org.eclipse.jgit.lib.WindowCacheConfig;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.team.core.RepositoryProvider;
/**
* This class keeps information about how a project is mapped to
@@ -54,8 +51,6 @@ import org.eclipse.jgit.lib.WindowCacheConfig;
public class GitProjectData {
private static final Map<IProject, GitProjectData> projectDataCache = new HashMap<IProject, GitProjectData>();
- private static final Map<File, Reference<Repository>> repositoryCache = new HashMap<File, Reference<Repository>>();
-
private static Set<RepositoryChangeListener> repositoryChangeListeners = new HashSet<RepositoryChangeListener>();
@SuppressWarnings("synthetic-access")
@@ -215,26 +210,6 @@ public class GitProjectData {
return projectDataCache.get(p);
}
- private synchronized static Repository lookupRepository(final File gitDir)
- throws IOException {
- Reference<Repository> r = repositoryCache.get(gitDir);
- Repository d = r != null ? r.get() : null;
- if (d == null) {
- d = new Repository(gitDir);
- repositoryCache.put(gitDir, new WeakReference<Repository>(d));
- }
- prune(repositoryCache);
- return d;
- }
-
- private static <K, V> void prune(Map<K, Reference<V>> map) {
- for (final Iterator<Map.Entry<K, Reference<V>>> i = map.entrySet()
- .iterator(); i.hasNext();) {
- if (i.next().getValue().get() == null)
- i.remove();
- }
- }
-
/**
* Update the settings for the global window cache of the workspace.
*/
@@ -470,7 +445,8 @@ public class GitProjectData {
}
try {
- m.setRepository(lookupRepository(git));
+ m.setRepository(Activator.getDefault().getRepositoryCache()
+ .lookupRepository(git));
} catch (IOException ioe) {
Activator.logError(CoreText.GitProjectData_mappedResourceGone,
new FileNotFoundException(m.getContainerPath().toString()));

Back to the top