# [PATCH] Distignuish between commit id and key in commit cache

2 messages from 2007-03-12 to 2007-03-12. Participants: Robin Rosenberg, Shawn O. Pearce.
Thread: https://gitlist.dev/t/7210

## Robin Rosenberg, 2007-03-12 17:51

Subject: [PATCH] Distignuish between commit id and key in commit cache
Message-ID: <20070312175115.10884.87646.stgit@lathund.dewire.com>
URL: https://gitlist.dev/e/20070312175115.10884.87646.stgit%40lathund.dewire.com

```
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(-)

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, 2007-03-12 21:05

Subject: Re: [PATCH] Distignuish between commit id and key in commit cache
Message-ID: <20070312210540.GA16513@spearce.org>
URL: https://gitlist.dev/e/20070312210540.GA16513%40spearce.org
In-Reply-To: <20070312175115.10884.87646.stgit@lathund.dewire.com>

```
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.

```
