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 5/5] Cache resolved ids in quickdiff document for faster update
Date: Thu,  2 Apr 2009 20:46:31 +0200	[thread overview]
Message-ID: <1238697991-12990-6-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1238697991-12990-5-git-send-email-robin.rosenberg@dewire.com>

We do this by caching the commit, tree and blob ids and can then
very quickly decide whether a change in baseline actually results in a
changed version of the reference blob used for quickdiff.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../egit/ui/internal/decorators/GitDocument.java   |   70 +++++++++++++++++---
 1 files changed, 60 insertions(+), 10 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 347e6fc..59a738c 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
@@ -20,8 +20,11 @@
 import org.spearce.egit.core.GitProvider;
 import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.egit.ui.Activator;
+import org.spearce.jgit.lib.AnyObjectId;
+import org.spearce.jgit.lib.Commit;
 import org.spearce.jgit.lib.Constants;
 import org.spearce.jgit.lib.IndexChangedEvent;
+import org.spearce.jgit.lib.ObjectId;
 import org.spearce.jgit.lib.ObjectLoader;
 import org.spearce.jgit.lib.RefsChangedEvent;
 import org.spearce.jgit.lib.Repository;
@@ -31,6 +34,11 @@
 
 class GitDocument extends Document implements RepositoryListener {
 	private final IResource resource;
+
+	private AnyObjectId lastCommit;
+	private AnyObjectId lastTree;
+	private AnyObjectId lastBlob;
+
 	static Map<GitDocument,Repository> doc2repo = new WeakHashMap<GitDocument, Repository>();
 
 	static GitDocument create(final IResource resource) throws IOException {
@@ -51,29 +59,68 @@ private GitDocument(IResource resource) {
 		GitDocument.doc2repo.put(this, getRepository());
 	}
 
+	private void setResolved(final AnyObjectId commit, final AnyObjectId tree, final AnyObjectId blob, final String value) {
+		lastCommit = commit != null ? commit.copy() : null;
+		lastTree = tree != null ? tree.copy() : null;
+		lastBlob = blob != null ? blob.copy() : null;
+		set(value);
+		if (blob != null)
+			Activator.trace("(GitDocument) resolved " + resource + " to " + lastBlob + " in " + lastCommit + "/" + lastTree);
+		else
+			Activator.trace("(GitDocument) unresolved " + resource);
+	}
+
 	void populate() throws IOException {
 		Activator.trace("(GitDocument) populate: " + resource);
-		set("");
 		final IProject project = resource.getProject();
 		RepositoryMapping mapping = RepositoryMapping.getMapping(project);
-		if (mapping == null)
+		if (mapping == null) {
+			setResolved(null, null, null, "");
 			return;
+		}
 		final String gitPath = mapping.getRepoRelativePath(resource);
-		final Repository repository = getRepository();
+		final Repository repository = mapping.getRepository();
 		String baseline = GitQuickDiffProvider.baseline.get(repository);
 		if (baseline == null)
 			baseline = Constants.HEAD;
-		Tree baselineTree = repository.mapTree(baseline);
-		if (baselineTree == null) {
+		ObjectId commitId = repository.resolve(baseline);
+		if (commitId != null) {
+			if (commitId.equals(lastCommit)) {
+				Activator.trace("(GitDocument) already resolved"); 
+				return;
+			}
+		} else {
 			Activator.logError("Could not resolve quickdiff baseline "
 					+ baseline + " corresponding to " + resource + " in "
 					+ repository, new Throwable());
+			setResolved(null, null, null, "");
+			return;
+		}
+		Commit baselineCommit = repository.mapCommit(commitId);
+		if (baselineCommit == null) {
+			Activator.logError("Could not load commit " + commitId + " for "
+					+ baseline + " corresponding to " + resource + " in "
+					+ repository, new Throwable());
+			setResolved(null, null, null, "");
+			return;
+		}
+		ObjectId treeId = baselineCommit.getTreeId();
+		if (treeId.equals(lastTree)) {
+			Activator.trace("(GitDocument) already resolved"); 
+			return;
+		}
+		Tree baselineTree = baselineCommit.getTree();
+		if (baselineTree == null) {
+			Activator.logError("Could not load tree " + treeId + " for "
+					+ baseline + " corresponding to " + resource + " in "
+					+ repository, new Throwable());
+			setResolved(null, null, null, "");
 			return;
 		}
-		TreeEntry blobEnry = baselineTree.findBlobMember(gitPath);
-		if (blobEnry != null) {
+		TreeEntry blobEntry = baselineTree.findBlobMember(gitPath);
+		if (blobEntry != null && !blobEntry.getId().equals(lastBlob)) {
 			Activator.trace("(GitDocument) compareTo: " + baseline);
-			ObjectLoader loader = repository.openBlob(blobEnry.getId());
+			ObjectLoader loader = repository.openBlob(blobEntry.getId());
 			byte[] bytes = loader.getBytes();
 			String charset;
 			// Get the encoding for the current version. As a matter of
@@ -92,10 +139,13 @@ void populate() throws IOException {
 			// Finally we could consider validating the content with respect
 			// to the content. We don't do that here.
 			String s = new String(bytes, charset);
-			set(s);
+			setResolved(commitId, baselineTree.getId(), blobEntry.getId(), s);
 			Activator.trace("(GitDocument) has reference doc, size=" + s.length() + " bytes");
 		} else {
-			Activator.trace("(GitDocument) no revision.");
+			if (blobEntry == null)
+				setResolved(null, null, null, "");
+			else
+				Activator.trace("(GitDocument) already resolved"); 
 		}
 	}
 
-- 
1.6.2.1.345.g89fb

  reply	other threads:[~2009-04-02 18:49 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     ` [EGIT PATCH 3/5] Move dcocument to repository mapping to GitDocument Robin Rosenberg
2009-04-02 18:46       ` [EGIT PATCH 4/5] Update Quickdiff tracing statements Robin Rosenberg
2009-04-02 18:46         ` Robin Rosenberg [this message]
2009-04-05 20:36           ` [EGIT PATCH 5/5] Cache resolved ids in quickdiff document for faster update 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-6-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).