Use ObjectIdSerializer from JGit [redux]
Since [1, 2] JGit provides a public ObjectIdSerializer class. Remove the ObjectIdSerialization class and use the new API. [1] https://git.eclipse.org/r/#/c/117831/ [2] https://git.eclipse.org/r/#/c/119456/ Change-Id: Ie2ea535d5b6e190159dffeb98b63f1000c97658a
This commit is contained in:
parent
3730a388c8
commit
ae599f57ac
@ -16,8 +16,8 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.readWithoutMarker;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.writeWithoutMarker;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.cache.Cache;
|
||||
@ -172,14 +172,14 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
writeNotNull(out, prior);
|
||||
writeNotNull(out, next);
|
||||
writeWithoutMarker(out, prior);
|
||||
writeWithoutMarker(out, next);
|
||||
out.writeUTF(strategyName);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException {
|
||||
prior = readNotNull(in);
|
||||
next = readNotNull(in);
|
||||
prior = readWithoutMarker(in);
|
||||
next = readWithoutMarker(in);
|
||||
strategyName = in.readUTF();
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.server.ioutil.BasicSerialization.readString;
|
||||
import static com.google.gerrit.server.ioutil.BasicSerialization.writeString;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.readWithoutMarker;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.writeWithoutMarker;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.cache.Cache;
|
||||
@ -155,8 +155,8 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
writeNotNull(out, commit);
|
||||
writeNotNull(out, into);
|
||||
writeWithoutMarker(out, commit);
|
||||
writeWithoutMarker(out, into);
|
||||
Character c = SUBMIT_TYPES.get(submitType);
|
||||
if (c == null) {
|
||||
throw new IOException("Invalid submit type: " + submitType);
|
||||
@ -166,8 +166,8 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException {
|
||||
commit = readNotNull(in);
|
||||
into = readNotNull(in);
|
||||
commit = readWithoutMarker(in);
|
||||
into = readWithoutMarker(in);
|
||||
char t = in.readChar();
|
||||
submitType = SUBMIT_TYPES.inverse().get(t);
|
||||
if (submitType == null) {
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.readWithoutMarker;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.writeWithoutMarker;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@ -194,13 +194,13 @@ class TagSet {
|
||||
for (int i = 0; i < refCnt; i++) {
|
||||
String name = in.readUTF();
|
||||
int flag = in.readInt();
|
||||
ObjectId id = readNotNull(in);
|
||||
ObjectId id = readWithoutMarker(in);
|
||||
refs.put(name, new CachedRef(flag, id));
|
||||
}
|
||||
|
||||
int tagCnt = in.readInt();
|
||||
for (int i = 0; i < tagCnt; i++) {
|
||||
ObjectId id = readNotNull(in);
|
||||
ObjectId id = readWithoutMarker(in);
|
||||
BitSet flags = (BitSet) in.readObject();
|
||||
tags.add(new Tag(id, flags));
|
||||
}
|
||||
@ -211,12 +211,12 @@ class TagSet {
|
||||
for (Map.Entry<String, CachedRef> e : refs.entrySet()) {
|
||||
out.writeUTF(e.getKey());
|
||||
out.writeInt(e.getValue().flag);
|
||||
writeNotNull(out, e.getValue().get());
|
||||
writeWithoutMarker(out, e.getValue().get());
|
||||
}
|
||||
|
||||
out.writeInt(tags.size());
|
||||
for (Tag tag : tags) {
|
||||
writeNotNull(out, tag);
|
||||
writeWithoutMarker(out, tag);
|
||||
out.writeObject(tag.refFlags);
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
package com.google.gerrit.server.patch;
|
||||
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readCanBeNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.read;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.readWithoutMarker;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.write;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.writeWithoutMarker;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||
@ -93,9 +93,9 @@ public class DiffSummaryKey implements Serializable {
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
writeCanBeNull(out, oldId);
|
||||
write(out, oldId);
|
||||
out.writeInt(parentNum == null ? 0 : parentNum);
|
||||
writeNotNull(out, newId);
|
||||
writeWithoutMarker(out, newId);
|
||||
Character c = PatchListKey.WHITESPACE_TYPES.get(whitespace);
|
||||
if (c == null) {
|
||||
throw new IOException("Invalid whitespace type: " + whitespace);
|
||||
@ -104,10 +104,10 @@ public class DiffSummaryKey implements Serializable {
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException {
|
||||
oldId = readCanBeNull(in);
|
||||
oldId = read(in);
|
||||
int n = in.readInt();
|
||||
parentNum = n == 0 ? null : Integer.valueOf(n);
|
||||
newId = readNotNull(in);
|
||||
newId = readWithoutMarker(in);
|
||||
char t = in.readChar();
|
||||
whitespace = PatchListKey.WHITESPACE_TYPES.inverse().get(t);
|
||||
if (whitespace == null) {
|
||||
|
@ -18,10 +18,10 @@ import static com.google.gerrit.server.ioutil.BasicSerialization.readBytes;
|
||||
import static com.google.gerrit.server.ioutil.BasicSerialization.readVarInt32;
|
||||
import static com.google.gerrit.server.ioutil.BasicSerialization.writeBytes;
|
||||
import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readCanBeNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.read;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.readWithoutMarker;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.write;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.writeWithoutMarker;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
@ -173,8 +173,8 @@ public class PatchList implements Serializable {
|
||||
private void writeObject(ObjectOutputStream output) throws IOException {
|
||||
final ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
||||
try (DeflaterOutputStream out = new DeflaterOutputStream(buf)) {
|
||||
writeCanBeNull(out, oldId);
|
||||
writeNotNull(out, newId);
|
||||
write(out, oldId);
|
||||
writeWithoutMarker(out, newId);
|
||||
writeVarInt32(out, isMerge ? 1 : 0);
|
||||
comparisonType.writeTo(out);
|
||||
writeVarInt32(out, insertions);
|
||||
@ -190,8 +190,8 @@ public class PatchList implements Serializable {
|
||||
private void readObject(ObjectInputStream input) throws IOException {
|
||||
final ByteArrayInputStream buf = new ByteArrayInputStream(readBytes(input));
|
||||
try (InflaterInputStream in = new InflaterInputStream(buf)) {
|
||||
oldId = readCanBeNull(in);
|
||||
newId = readNotNull(in);
|
||||
oldId = read(in);
|
||||
newId = readWithoutMarker(in);
|
||||
isMerge = readVarInt32(in) != 0;
|
||||
comparisonType = ComparisonType.readFrom(in);
|
||||
insertions = readVarInt32(in);
|
||||
|
@ -15,10 +15,10 @@
|
||||
package com.google.gerrit.server.patch;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readCanBeNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.readNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeCanBeNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerialization.writeNotNull;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.read;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.readWithoutMarker;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.write;
|
||||
import static org.eclipse.jgit.lib.ObjectIdSerializer.writeWithoutMarker;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
@ -186,9 +186,9 @@ public class PatchListKey implements Serializable {
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
writeCanBeNull(out, oldId);
|
||||
write(out, oldId);
|
||||
out.writeInt(parentNum == null ? 0 : parentNum);
|
||||
writeNotNull(out, newId);
|
||||
writeWithoutMarker(out, newId);
|
||||
Character c = WHITESPACE_TYPES.get(whitespace);
|
||||
if (c == null) {
|
||||
throw new IOException("Invalid whitespace type: " + whitespace);
|
||||
@ -198,10 +198,10 @@ public class PatchListKey implements Serializable {
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException {
|
||||
oldId = readCanBeNull(in);
|
||||
oldId = read(in);
|
||||
int n = in.readInt();
|
||||
parentNum = n == 0 ? null : Integer.valueOf(n);
|
||||
newId = readNotNull(in);
|
||||
newId = readWithoutMarker(in);
|
||||
char t = in.readChar();
|
||||
whitespace = WHITESPACE_TYPES.inverse().get(t);
|
||||
if (whitespace == null) {
|
||||
|
@ -39,7 +39,6 @@ java_library(
|
||||
srcs = [
|
||||
"diff/EditDeserializer.java",
|
||||
"diff/ReplaceEdit.java",
|
||||
"lib/ObjectIdSerialization.java",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
|
@ -1,54 +0,0 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package org.eclipse.jgit.lib;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import org.eclipse.jgit.util.IO;
|
||||
|
||||
public class ObjectIdSerialization {
|
||||
public static void writeCanBeNull(OutputStream out, AnyObjectId id) throws IOException {
|
||||
if (id != null) {
|
||||
out.write((byte) 1);
|
||||
writeNotNull(out, id);
|
||||
} else {
|
||||
out.write((byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeNotNull(OutputStream out, AnyObjectId id) throws IOException {
|
||||
id.copyRawTo(out);
|
||||
}
|
||||
|
||||
public static ObjectId readCanBeNull(InputStream in) throws IOException {
|
||||
switch (in.read()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return readNotNull(in);
|
||||
default:
|
||||
throw new IOException("Invalid flag before ObjectId");
|
||||
}
|
||||
}
|
||||
|
||||
public static ObjectId readNotNull(InputStream in) throws IOException {
|
||||
final byte[] b = new byte[20];
|
||||
IO.readFully(in, b, 0, 20);
|
||||
return ObjectId.fromRaw(b);
|
||||
}
|
||||
|
||||
private ObjectIdSerialization() {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user