diff options
-rw-r--r-- | org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties | 2 | ||||
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java | 2 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/LocalDiskRefTreeDatabaseTest.java | 2 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LongMapTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/LongMapTest.java) | 2 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java | 65 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java | 2 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java | 1 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/LongMap.java (renamed from org.eclipse.jgit/src/org/eclipse/jgit/transport/LongMap.java) | 42 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java | 41 |
9 files changed, 144 insertions, 15 deletions
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties index 8666c34296..7c9816cf7b 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties @@ -257,7 +257,7 @@ usage_PrunePreserved=Remove the preserved subdirectory containing previously pre usage_ReadDirCache= Read the DirCache 100 times usage_RebuildCommitGraph=Recreate a repository from another one's commit graph usage_RebuildRefTree=Copy references into a RefTree -usage_RebuildRefTreeEnable=set extensions.refsStorage = reftree +usage_RebuildRefTreeEnable=set extensions.refStorage = reftree usage_Remote=Manage set of tracked repositories usage_RepositoryToReadFrom=Repository to read from usage_RepositoryToReceiveInto=Repository to receive into diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java index 57345e20dc..8cde5138a4 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java @@ -133,7 +133,7 @@ class RebuildRefTree extends TextBuiltin { if (enable && !(db.getRefDatabase() instanceof RefTreeDatabase)) { StoredConfig cfg = db.getConfig(); cfg.setInt("core", null, "repositoryformatversion", 1); //$NON-NLS-1$ //$NON-NLS-2$ - cfg.setString("extensions", null, "refsStorage", "reftree"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + cfg.setString("extensions", null, "refStorage", "reftree"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ cfg.save(); errw.println("Enabled reftree."); //$NON-NLS-1$ errw.flush(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/LocalDiskRefTreeDatabaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/LocalDiskRefTreeDatabaseTest.java index 67a7819900..d5a07e02fa 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/LocalDiskRefTreeDatabaseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/LocalDiskRefTreeDatabaseTest.java @@ -83,7 +83,7 @@ public class LocalDiskRefTreeDatabaseTest extends LocalDiskRepositoryTestCase { FileRepository init = createWorkRepository(); FileBasedConfig cfg = init.getConfig(); cfg.setInt("core", null, "repositoryformatversion", 1); - cfg.setString("extensions", null, "refsStorage", "reftree"); + cfg.setString("extensions", null, "refStorage", "reftree"); cfg.save(); repo = (FileRepository) new FileRepositoryBuilder() diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/LongMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LongMapTest.java index 1a86aaff33..054c61e2be 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/LongMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LongMapTest.java @@ -41,7 +41,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.eclipse.jgit.transport; +package org.eclipse.jgit.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java index 7e11a61035..d2d44ffdc8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/NBTest.java @@ -90,6 +90,24 @@ public class NBTest { } @Test + public void testDecodeUInt24() { + assertEquals(0, NB.decodeUInt24(b(0, 0, 0), 0)); + assertEquals(0, NB.decodeUInt24(padb(3, 0, 0, 0), 3)); + + assertEquals(3, NB.decodeUInt24(b(0, 0, 3), 0)); + assertEquals(3, NB.decodeUInt24(padb(3, 0, 0, 3), 3)); + + assertEquals(0xcede03, NB.decodeUInt24(b(0xce, 0xde, 3), 0)); + assertEquals(0xbade03, NB.decodeUInt24(padb(3, 0xba, 0xde, 3), 3)); + + assertEquals(0x03bade, NB.decodeUInt24(b(3, 0xba, 0xde), 0)); + assertEquals(0x03bade, NB.decodeUInt24(padb(3, 3, 0xba, 0xde), 3)); + + assertEquals(0xffffff, NB.decodeUInt24(b(0xff, 0xff, 0xff), 0)); + assertEquals(0xffffff, NB.decodeUInt24(padb(3, 0xff, 0xff, 0xff), 3)); + } + + @Test public void testDecodeInt32() { assertEquals(0, NB.decodeInt32(b(0, 0, 0, 0), 0)); assertEquals(0, NB.decodeInt32(padb(3, 0, 0, 0, 0), 3)); @@ -198,6 +216,39 @@ public class NBTest { } @Test + public void testEncodeInt24() { + byte[] out = new byte[16]; + + prepareOutput(out); + NB.encodeInt24(out, 0, 0); + assertOutput(b(0, 0, 0), out, 0); + + prepareOutput(out); + NB.encodeInt24(out, 3, 0); + assertOutput(b(0, 0, 0), out, 3); + + prepareOutput(out); + NB.encodeInt24(out, 0, 3); + assertOutput(b(0, 0, 3), out, 0); + + prepareOutput(out); + NB.encodeInt24(out, 3, 3); + assertOutput(b(0, 0, 3), out, 3); + + prepareOutput(out); + NB.encodeInt24(out, 0, 0xc0deac); + assertOutput(b(0xc0, 0xde, 0xac), out, 0); + + prepareOutput(out); + NB.encodeInt24(out, 3, 0xbadeac); + assertOutput(b(0xba, 0xde, 0xac), out, 3); + + prepareOutput(out); + NB.encodeInt24(out, 3, -1); + assertOutput(b(0xff, 0xff, 0xff), out, 3); + } + + @Test public void testEncodeInt32() { final byte[] out = new byte[16]; @@ -315,10 +366,24 @@ public class NBTest { return r; } + private static byte[] b(int a, int b, int c) { + return new byte[] { (byte) a, (byte) b, (byte) c }; + } + private static byte[] b(final int a, final int b, final int c, final int d) { return new byte[] { (byte) a, (byte) b, (byte) c, (byte) d }; } + private static byte[] padb(int len, int a, int b, int c) { + final byte[] r = new byte[len + 4]; + for (int i = 0; i < len; i++) + r[i] = (byte) 0xaf; + r[len] = (byte) a; + r[len + 1] = (byte) b; + r[len + 2] = (byte) c; + return r; + } + private static byte[] padb(final int len, final int a, final int b, final int c, final int d) { final byte[] r = new byte[len + 4]; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index 6a674aa658..646feac8cf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java @@ -216,7 +216,7 @@ public class FileRepository extends Repository { ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0); String reftype = repoConfig.getString( - "extensions", null, "refsStorage"); //$NON-NLS-1$ //$NON-NLS-2$ + "extensions", null, "refStorage"); //$NON-NLS-1$ //$NON-NLS-2$ if (repositoryFormatVersion >= 1 && reftype != null) { if (StringUtils.equalsIgnoreCase(reftype, "reftree")) { //$NON-NLS-1$ refs = new RefTreeDatabase(this, new RefDirectory(this)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java index db3578bdb4..2f6b271d87 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java @@ -82,6 +82,7 @@ import org.eclipse.jgit.lib.ObjectStream; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.util.BlockList; import org.eclipse.jgit.util.IO; +import org.eclipse.jgit.util.LongMap; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.sha1.SHA1; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/LongMap.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/LongMap.java index 4d60202a6f..7b0b0c728a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/LongMap.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/LongMap.java @@ -41,15 +41,16 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.eclipse.jgit.transport; +package org.eclipse.jgit.util; /** - * Simple Map<long,Object> helper for {@link PackParser}. + * Simple Map<long,Object>. * * @param <V> * type of the value instance. + * @since 4.9 */ -final class LongMap<V> { +public class LongMap<V> { private static final float LOAD_FACTOR = 0.75f; private Node<V>[] table; @@ -60,16 +61,27 @@ final class LongMap<V> { /** Next {@link #size} to trigger a {@link #grow()}. */ private int growAt; - LongMap() { + /** Initialize an empty LongMap. */ + public LongMap() { table = createArray(64); growAt = (int) (table.length * LOAD_FACTOR); } - boolean containsKey(final long key) { + /** + * @param key + * the key to find. + * @return {@code true} if {@code key} is present in the map. + */ + public boolean containsKey(long key) { return get(key) != null; } - V get(final long key) { + /** + * @param key + * the key to find. + * @return stored value of the key, or {@code null}. + */ + public V get(long key) { for (Node<V> n = table[index(key)]; n != null; n = n.next) { if (n.key == key) return n.value; @@ -77,7 +89,12 @@ final class LongMap<V> { return null; } - V remove(final long key) { + /** + * @param key + * key to remove from the map. + * @return old value of the key, or {@code null}. + */ + public V remove(long key) { Node<V> n = table[index(key)]; Node<V> prior = null; while (n != null) { @@ -95,7 +112,14 @@ final class LongMap<V> { return null; } - V put(final long key, final V value) { + /** + * @param key + * key to store {@code value} under. + * @param value + * new value. + * @return prior value, or null. + */ + public V put(long key, V value) { for (Node<V> n = table[index(key)]; n != null; n = n.next) { if (n.key == key) { final V o = n.value; @@ -145,9 +169,7 @@ final class LongMap<V> { private static class Node<V> { final long key; - V value; - Node<V> next; Node(final long k, final V v) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java index 8536f1dc25..471a4998d7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java @@ -113,6 +113,24 @@ public final class NB { } /** + * Convert sequence of 3 bytes (network byte order) into unsigned value. + * + * @param intbuf + * buffer to acquire the 3 bytes of data from. + * @param offset + * position within the buffer to begin reading from. This + * position and the next 2 bytes after it (for a total of 3 + * bytes) will be read. + * @return signed integer value that matches the 24 bits read. + * @since 4.9 + */ + public static int decodeUInt24(byte[] intbuf, int offset) { + int r = (intbuf[offset] & 0xff) << 8; + r |= intbuf[offset + 1] & 0xff; + return (r << 8) | (intbuf[offset + 2] & 0xff); + } + + /** * Convert sequence of 4 bytes (network byte order) into signed value. * * @param intbuf @@ -223,6 +241,29 @@ public final class NB { } /** + * Write a 24 bit integer as a sequence of 3 bytes (network byte order). + * + * @param intbuf + * buffer to write the 3 bytes of data into. + * @param offset + * position within the buffer to begin writing to. This position + * and the next 2 bytes after it (for a total of 3 bytes) will be + * replaced. + * @param v + * the value to write. + * @since 4.9 + */ + public static void encodeInt24(byte[] intbuf, int offset, int v) { + intbuf[offset + 2] = (byte) v; + v >>>= 8; + + intbuf[offset + 1] = (byte) v; + v >>>= 8; + + intbuf[offset] = (byte) v; + } + + /** * Write a 32 bit integer as a sequence of 4 bytes (network byte order). * * @param intbuf |