diff --git a/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ChunkKeyTest.java b/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ChunkKeyTest.java index 63cbf520c..921966366 100644 --- a/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ChunkKeyTest.java +++ b/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ChunkKeyTest.java @@ -43,7 +43,8 @@ package org.eclipse.jgit.storage.dht; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import org.eclipse.jgit.lib.ObjectId; import org.junit.Test; @@ -59,19 +60,19 @@ public void testKey() { ChunkKey key1 = ChunkKey.create(repo1, id); assertEquals(repo1.asInt(), key1.getRepositoryId()); assertEquals(id, key1.getChunkHash()); - assertEquals("3e.41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", + assertEquals("41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", key1.asString()); ChunkKey key2 = ChunkKey.fromBytes(key1.asBytes()); assertEquals(repo1.asInt(), key2.getRepositoryId()); assertEquals(id, key2.getChunkHash()); - assertEquals("3e.41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", + assertEquals("41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", key2.asString()); ChunkKey key3 = ChunkKey.fromString(key1.asString()); assertEquals(repo1.asInt(), key3.getRepositoryId()); assertEquals(id, key3.getChunkHash()); - assertEquals("3e.41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", + assertEquals("41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", key3.asString()); assertEquals(key1, key2); diff --git a/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ObjectIndexKeyTest.java b/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ObjectIndexKeyTest.java index ab3b423ed..d3419bd14 100644 --- a/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ObjectIndexKeyTest.java +++ b/org.eclipse.jgit.storage.dht.test/tst/org/eclipse/jgit/storage/dht/ObjectIndexKeyTest.java @@ -58,19 +58,19 @@ public void testKey() { ObjectIndexKey key1 = ObjectIndexKey.create(repo, id); assertEquals(repo.asInt(), key1.getRepositoryId()); assertEquals(key1, id); - assertEquals("3e.41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", + assertEquals("41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", key1.asString()); ObjectIndexKey key2 = ObjectIndexKey.fromBytes(key1.asBytes()); assertEquals(repo.asInt(), key2.getRepositoryId()); assertEquals(key2, id); - assertEquals("3e.41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", + assertEquals("41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", key2.asString()); ObjectIndexKey key3 = ObjectIndexKey.fromString(key1.asString()); assertEquals(repo.asInt(), key3.getRepositoryId()); assertEquals(key3, id); - assertEquals("3e.41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", + assertEquals("41234567.3e64b928d51b3a28e89cfe2a3f0eeae35ef07839", key3.asString()); } } diff --git a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ChunkKey.java b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ChunkKey.java index 272b5ea17..11a151f6b 100644 --- a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ChunkKey.java +++ b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ChunkKey.java @@ -54,7 +54,7 @@ /** Unique identifier of a {@link PackChunk} in the DHT. */ public final class ChunkKey implements RowKey { - static final int KEYLEN = 52; + static final int KEYLEN = 49; /** * @param repo @@ -84,8 +84,8 @@ public static ChunkKey fromBytes(byte[] key, int ptr, int len) { throw new IllegalArgumentException(MessageFormat.format( DhtText.get().invalidChunkKey, decode(key, ptr, ptr + len))); - int repo = parse32(key, ptr + 3); - ObjectId chunk = ObjectId.fromString(key, ptr + 12); + int repo = parse32(key, ptr); + ObjectId chunk = ObjectId.fromString(key, ptr + 9); return new ChunkKey(repo, chunk); } @@ -122,13 +122,9 @@ public ObjectId getChunkHash() { public byte[] asBytes() { byte[] r = new byte[KEYLEN]; - chunk.copyTo(r, 12); - format32(r, 3, repo); - // bucket is the leading 2 digits of the SHA-1. - r[11] = '.'; - r[2] = '.'; - r[1] = r[12 + 1]; - r[0] = r[12 + 0]; + format32(r, 0, repo); + r[8] = '.'; + chunk.copyTo(r, 9); return r; } diff --git a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ObjectIndexKey.java b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ObjectIndexKey.java index b38fdcec2..ab8f8352b 100644 --- a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ObjectIndexKey.java +++ b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/ObjectIndexKey.java @@ -55,7 +55,7 @@ /** Identifies an ObjectId in the DHT. */ public final class ObjectIndexKey extends ObjectId implements RowKey { - private static final int KEYLEN = 52; + private static final int KEYLEN = 49; /** * @param repo @@ -75,8 +75,8 @@ public static ObjectIndexKey fromBytes(byte[] key) { throw new IllegalArgumentException(MessageFormat.format( DhtText.get().invalidChunkKey, decode(key))); - int repo = parse32(key, 3); - ObjectId id = ObjectId.fromString(key, 12); + int repo = parse32(key, 0); + ObjectId id = ObjectId.fromString(key, 9); return new ObjectIndexKey(repo, id); } @@ -106,13 +106,9 @@ int getRepositoryId() { public byte[] asBytes() { byte[] r = new byte[KEYLEN]; - copyTo(r, 12); - format32(r, 3, repo); - // bucket is the leading 2 digits of the SHA-1. - r[11] = '.'; - r[2] = '.'; - r[1] = r[12 + 1]; - r[0] = r[12 + 0]; + format32(r, 0, repo); + r[8] = '.'; + copyTo(r, 9); return r; }