aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2017-07-19 05:53:30 -0700
committerShawn Pearce <spearce@spearce.org>2017-07-19 05:53:30 -0700
commit4321ccd468aa1ac9b4c5ec0839433401c9bec136 (patch)
tree6fb14aea4d436b7ce3e0683bc5a4b623be06cb95
parent90a957c9472f82ff86c6b792dc6292c41052bc6c (diff)
downloadjgit-4321ccd468aa1ac9b4c5ec0839433401c9bec136.tar.gz
jgit-4321ccd468aa1ac9b4c5ec0839433401c9bec136.zip
dfs: Fix default DfsStreamKey to include DfsRepositoryDescription
Not all DFS implementations use globally unique pack names in the DfsPackDescription. Most require the DfsRepositoryDescription to qualify the pack. Include DfsRepositoryDescription in the default DfsStreamKey implementation, to prevent cache collisions. Change-Id: I9ebf0c76bf2b414a702ae050b32e42588067bc44
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java26
2 files changed, 12 insertions, 16 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java
index 86a04893b7..0e2ed3b894 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackDescription.java
@@ -133,7 +133,7 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
* @return cache key for use by the block cache.
*/
public DfsStreamKey getStreamKey(PackExt ext) {
- return DfsStreamKey.of(getFileName(ext));
+ return DfsStreamKey.of(getRepositoryDescription(), getFileName(ext));
}
/** @return the source of the pack. */
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java
index f0a5da01f3..54a74899ea 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java
@@ -50,22 +50,14 @@ import java.util.Arrays;
/** Key used by {@link DfsBlockCache} to disambiguate streams. */
public abstract class DfsStreamKey {
/**
+ * @param repo
+ * description of the containing repository.
* @param name
* compute the key from a string name.
* @return key for {@code name}
*/
- public static DfsStreamKey of(String name) {
- return of(name.getBytes(UTF_8));
- }
-
- /**
- * @param name
- * compute the key from a byte array. The key takes ownership of
- * the passed {@code byte[] name}.
- * @return key for {@code name}
- */
- public static DfsStreamKey of(byte[] name) {
- return new ByteArrayDfsStreamKey(name);
+ public static DfsStreamKey of(DfsRepositoryDescription repo, String name) {
+ return new ByteArrayDfsStreamKey(repo, name.getBytes(UTF_8));
}
final int hash;
@@ -95,10 +87,12 @@ public abstract class DfsStreamKey {
}
private static final class ByteArrayDfsStreamKey extends DfsStreamKey {
+ private final DfsRepositoryDescription repo;
private final byte[] name;
- ByteArrayDfsStreamKey(byte[] name) {
- super(Arrays.hashCode(name));
+ ByteArrayDfsStreamKey(DfsRepositoryDescription repo, byte[] name) {
+ super(repo.hashCode() * 31 + Arrays.hashCode(name));
+ this.repo = repo;
this.name = name;
}
@@ -106,7 +100,9 @@ public abstract class DfsStreamKey {
public boolean equals(Object o) {
if (o instanceof ByteArrayDfsStreamKey) {
ByteArrayDfsStreamKey k = (ByteArrayDfsStreamKey) o;
- return hash == k.hash && Arrays.equals(name, k.name);
+ return hash == k.hash
+ && repo.equals(k.repo)
+ && Arrays.equals(name, k.name);
}
return false;
}