git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 3/5] Move dcocument to repository mapping to GitDocument
Date: Thu,  2 Apr 2009 20:46:29 +0200	[thread overview]
Message-ID: <1238697991-12990-4-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1238697991-12990-3-git-send-email-robin.rosenberg@dewire.com>

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../egit/ui/internal/decorators/GitDocument.java   |   23 ++++++++++++++++++-
 .../internal/decorators/GitQuickDiffProvider.java  |    8 +------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java
index 69e9295..8c82a55 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, 2009 Robin Rosenberg <robin.rosenberg@dewire.com>
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,8 @@
 package org.spearce.egit.ui.internal.decorators;
 
 import java.io.IOException;
+import java.util.Map;
+import java.util.WeakHashMap;
 
 import org.eclipse.core.resources.IEncodedStorage;
 import org.eclipse.core.resources.IProject;
@@ -29,6 +31,7 @@
 
 class GitDocument extends Document implements RepositoryListener {
 	private final IResource resource;
+	static Map<GitDocument,Repository> doc2repo = new WeakHashMap<GitDocument, Repository>();
 
 	static GitDocument create(final IResource resource) throws IOException {
 		GitDocument ret = null;
@@ -44,7 +47,7 @@ static GitDocument create(final IResource resource) throws IOException {
 
 	private GitDocument(IResource resource) {
 		this.resource = resource;
-		GitQuickDiffProvider.doc2repo.put(this, getRepository());
+		GitDocument.doc2repo.put(this, getRepository());
 	}
 
 	void populate() throws IOException {
@@ -95,6 +98,7 @@ void populate() throws IOException {
 	}
 
 	void dispose() {
+		doc2repo.remove(this);
 		Repository repository = getRepository();
 		if (repository != null)
 			repository.removeRepositoryChangedListener(this);
@@ -119,4 +123,19 @@ private Repository getRepository() {
 			return mapping.getRepository();
 		return null;
 	}
+
+	/**
+	 * A change occurred to a repository. Update any GitDocument instances
+	 * referring to such repositories.
+	 * 
+	 * @param repository Repository which changed 
+	 * @throws IOException
+	 */
+	static void refreshRelevant(final Repository repository) throws IOException {
+		for (Map.Entry<GitDocument, Repository> i : doc2repo.entrySet()) {
+			if (i.getValue() == repository) {
+				i.getKey().populate();
+			}
+		}
+	}
 }
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitQuickDiffProvider.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitQuickDiffProvider.java
index 88f5ea0..6c71f3c 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitQuickDiffProvider.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitQuickDiffProvider.java
@@ -37,7 +37,6 @@
 	private IResource resource;
 
 	static Map<Repository,String> baseline = new WeakHashMap<Repository,String>();
-	static Map<GitDocument,Repository> doc2repo = new WeakHashMap<GitDocument, Repository>();
 
 	/**
 	 * Create the GitQuickDiffProvider instance
@@ -48,7 +47,6 @@ public GitQuickDiffProvider() {
 
 	public void dispose() {
 		Activator.trace("(GitQuickDiffProvider) dispose");
-		doc2repo.remove(document);
 		if (document != null)
 			document.dispose();
 	}
@@ -96,11 +94,7 @@ public void setId(String id) {
 	 */
 	public static void setBaselineReference(final Repository repository, final String baseline) throws IOException {
 		GitQuickDiffProvider.baseline.put(repository, baseline);
-		for (Map.Entry<GitDocument, Repository> i : doc2repo.entrySet()) {
-			if (i.getValue() == repository) {
-				i.getKey().populate();
-			}
-		}
+		GitDocument.refreshRelevant(repository);
 	}
 
 }
-- 
1.6.2.1.345.g89fb

  reply	other threads:[~2009-04-02 18:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02 18:46 [EGIT PATCH 0/5] Quickdiff improvements Robin Rosenberg
2009-04-02 18:46 ` [EGIT PATCH 1/5] Make the equals method work for AnyObjectId, not just ObjectId Robin Rosenberg
2009-04-02 18:46   ` [EGIT PATCH 2/5] quickdiff - Don't add GitDocument as repository listener more than once Robin Rosenberg
2009-04-02 18:46     ` Robin Rosenberg [this message]
2009-04-02 18:46       ` [EGIT PATCH 4/5] Update Quickdiff tracing statements Robin Rosenberg
2009-04-02 18:46         ` [EGIT PATCH 5/5] Cache resolved ids in quickdiff document for faster update Robin Rosenberg
2009-04-05 20:36           ` Shawn O. Pearce
2009-04-05 21:40             ` Robin Rosenberg
2009-04-05 21:43               ` Shawn O. Pearce
2009-04-05 20:24     ` [EGIT PATCH 2/5] quickdiff - Don't add GitDocument as repository listener more than once Shawn O. Pearce
2009-04-05 21:41       ` 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=1238697991-12990-4-git-send-email-robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.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).