Copy Constants.OBJECT_ID_LENGTH as ObjectIds.LEN
As with OBJECT_ID_STRING_LENGTH, our copy of the constant is shorter, and callers can use constants all from the same place. Change-Id: I39a2fa4fd7f62dd3e3bfb36cb4716c544d128ada
This commit is contained in:
@@ -24,6 +24,9 @@ import org.eclipse.jgit.lib.ObjectReader;
|
||||
|
||||
/** Static utilities for working with {@code ObjectId}s. */
|
||||
public class ObjectIds {
|
||||
/** Length of a binary SHA-1 byte array. */
|
||||
public static final int LEN = Constants.OBJECT_ID_LENGTH;
|
||||
|
||||
/** Length of a hex SHA-1 string. */
|
||||
public static final int STR_LEN = Constants.OBJECT_ID_STRING_LENGTH;
|
||||
|
||||
|
@@ -7,6 +7,7 @@ java_library(
|
||||
"//java/com/google/gerrit/common:server",
|
||||
"//java/com/google/gerrit/exceptions",
|
||||
"//java/com/google/gerrit/extensions:api",
|
||||
"//java/com/google/gerrit/git",
|
||||
"//java/com/google/gerrit/reviewdb:server",
|
||||
"//java/com/google/gerrit/server",
|
||||
"//lib:guava",
|
||||
|
@@ -20,6 +20,7 @@ import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gerrit.git.ObjectIds;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -45,7 +46,6 @@ import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.lib.CommitBuilder;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.ObjectInserter;
|
||||
import org.eclipse.jgit.lib.ObjectReader;
|
||||
@@ -75,6 +75,7 @@ import org.eclipse.jgit.util.NB;
|
||||
* after checking with a {@link PublicKeyChecker}.
|
||||
*/
|
||||
public class PublicKeyStore implements AutoCloseable {
|
||||
|
||||
private static final ObjectId EMPTY_TREE =
|
||||
ObjectId.fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904");
|
||||
|
||||
@@ -516,7 +517,7 @@ public class PublicKeyStore implements AutoCloseable {
|
||||
}
|
||||
|
||||
static ObjectId keyObjectId(long keyId) {
|
||||
byte[] buf = new byte[Constants.OBJECT_ID_LENGTH];
|
||||
byte[] buf = new byte[ObjectIds.LEN];
|
||||
NB.encodeInt64(buf, 0, keyId);
|
||||
return ObjectId.fromRaw(buf);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ java_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//java/com/google/gerrit/common:annotations",
|
||||
"//java/com/google/gerrit/git",
|
||||
"//java/com/google/gerrit/proto",
|
||||
"//lib:guava",
|
||||
"//lib:protobuf",
|
||||
|
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.cache.serialize;
|
||||
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import com.google.gerrit.git.ObjectIds;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
public enum ObjectIdCacheSerializer implements CacheSerializer<ObjectId> {
|
||||
@@ -22,14 +22,14 @@ public enum ObjectIdCacheSerializer implements CacheSerializer<ObjectId> {
|
||||
|
||||
@Override
|
||||
public byte[] serialize(ObjectId object) {
|
||||
byte[] buf = new byte[Constants.OBJECT_ID_LENGTH];
|
||||
byte[] buf = new byte[ObjectIds.LEN];
|
||||
object.copyRawTo(buf, 0);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId deserialize(byte[] in) {
|
||||
if (in == null || in.length != Constants.OBJECT_ID_LENGTH) {
|
||||
if (in == null || in.length != ObjectIds.LEN) {
|
||||
throw new IllegalArgumentException("Failed to deserialize ObjectId");
|
||||
}
|
||||
return ObjectId.fromRaw(in);
|
||||
|
@@ -15,8 +15,8 @@
|
||||
package com.google.gerrit.server.cache.serialize;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
|
||||
|
||||
import com.google.gerrit.git.ObjectIds;
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ObjectIdConverter {
|
||||
return new ObjectIdConverter();
|
||||
}
|
||||
|
||||
private final byte[] buf = new byte[OBJECT_ID_LENGTH];
|
||||
private final byte[] buf = new byte[ObjectIds.LEN];
|
||||
|
||||
private ObjectIdConverter() {}
|
||||
|
||||
@@ -46,10 +46,7 @@ public class ObjectIdConverter {
|
||||
|
||||
public ObjectId fromByteString(ByteString in) {
|
||||
checkArgument(
|
||||
in.size() == OBJECT_ID_LENGTH,
|
||||
"expected ByteString of length %s: %s",
|
||||
OBJECT_ID_LENGTH,
|
||||
in);
|
||||
in.size() == ObjectIds.LEN, "expected ByteString of length %s: %s", ObjectIds.LEN, in);
|
||||
in.copyTo(buf, 0);
|
||||
return ObjectId.fromRaw(buf);
|
||||
}
|
||||
|
Reference in New Issue
Block a user