threads / patch / 7210

patchDistignuish between commit id and key in commit cache

Subject: [PATCH] Distignuish between commit id and key in commit cache

## tl;dr

2 messages between Mar 12, 2007 and Mar 12, 2007. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Robin Rosenberg· Mar 12, 2007, 17:51 UTC · lore

See WeakHashMap documentation. If the key is the same object as the objectid the keys can never be collected.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../src/org/spearce/jgit/lib/Repository.java       |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +3 −1
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index f7c470d..8b1f42c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -199,7 +199,9 @@ public class Repository {
 		final byte[] raw = or.getBytes();
 		if (Constants.TYPE_COMMIT.equals(or.getType())) {
 			ret = new Commit(this, id, raw);
-			cache.put(id, ret);
+			// The key must not be the referenced strongly
+			// by the value in WeakHashMaps
+			cache.put(new ObjectId(id.getBytes()), ret);
 			return ret;
 		}
 		throw new IncorrectObjectTypeException(id, Constants.TYPE_COMMIT);
Shawn O. Pearce· Mar 12, 2007, 21:05 UTC · re: Robin Rosenberg · lore

Re: [PATCH] Distignuish between commit id and key in commit cache

Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> See WeakHashMap documentation. If the key is the same object
> as the objectid the keys can never be collected.

Thanks. I have applied this in the middle of your other recent series, tagged 0.2.1 and pushed it out to the usual locations. The history view looks pretty nice... and is reasonably quick too!

-- 
Shawn.

← back to recent threads