From bc65ef0ae6324f774e1ee5933d8c37b270b26bd2 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Thu, 2 Apr 2009 20:46:29 +0200 Subject: [PATCH] Move document to repository mapping to GitDocument Signed-off-by: Robin Rosenberg Signed-off-by: Shawn O. Pearce --- .../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 a9c0c7d9..28fb4ea6 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 + * Copyright (C) 2008, 2009 Robin Rosenberg * * 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 @@ import org.spearce.jgit.lib.TreeEntry; class GitDocument extends Document implements RepositoryListener { private final IResource resource; + static Map doc2repo = new WeakHashMap(); static GitDocument create(final IResource resource) throws IOException { GitDocument ret = null; @@ -41,7 +44,7 @@ class GitDocument extends Document implements RepositoryListener { private GitDocument(IResource resource) { this.resource = resource; - GitQuickDiffProvider.doc2repo.put(this, getRepository()); + GitDocument.doc2repo.put(this, getRepository()); } void populate() throws IOException { @@ -93,6 +96,7 @@ class GitDocument extends Document implements RepositoryListener { } void dispose() { + doc2repo.remove(this); Repository repository = getRepository(); if (repository != null) repository.removeRepositoryChangedListener(this); @@ -117,4 +121,19 @@ class GitDocument extends Document implements RepositoryListener { 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 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 88f5ea01..6c71f3c8 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 @@ public class GitQuickDiffProvider implements IQuickDiffReferenceProvider { private IResource resource; static Map baseline = new WeakHashMap(); - static Map doc2repo = new WeakHashMap(); /** * Create the GitQuickDiffProvider instance @@ -48,7 +47,6 @@ public class GitQuickDiffProvider implements IQuickDiffReferenceProvider { public void dispose() { Activator.trace("(GitQuickDiffProvider) dispose"); - doc2repo.remove(document); if (document != null) document.dispose(); } @@ -96,11 +94,7 @@ public class GitQuickDiffProvider implements IQuickDiffReferenceProvider { */ public static void setBaselineReference(final Repository repository, final String baseline) throws IOException { GitQuickDiffProvider.baseline.put(repository, baseline); - for (Map.Entry i : doc2repo.entrySet()) { - if (i.getValue() == repository) { - i.getKey().populate(); - } - } + GitDocument.refreshRelevant(repository); } } -- 2.11.4.GIT