Merge changes from topic "jgit-4.11"

* changes:
  Use ObjectIdSerializer from JGit [redux]
  Upgrade JGit to 4.11.0.201803080745-r.2-g61e4f1665
This commit is contained in:
David Ostrovsky
2018-03-16 07:43:38 +00:00
committed by Gerrit Code Review
9 changed files with 50 additions and 105 deletions

View File

@@ -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();
}
}

View File

@@ -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) {

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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) {

View File

@@ -39,7 +39,6 @@ java_library(
srcs = [
"diff/EditDeserializer.java",
"diff/ReplaceEdit.java",
"lib/ObjectIdSerialization.java",
],
visibility = ["//visibility:public"],
deps = [

View File

@@ -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() {}
}

View File

@@ -1,12 +1,12 @@
load("//tools/bzl:maven_jar.bzl", "GERRIT", "MAVEN_LOCAL", "MAVEN_CENTRAL", "maven_jar")
_JGIT_VERS = "4.11.0.201803080745-r"
_JGIT_VERS = "4.11.0.201803080745-r.2-g61e4f1665"
_DOC_VERS = _JGIT_VERS # Set to _JGIT_VERS unless using a snapshot
_DOC_VERS = "4.11.0.201803080745-r" # Set to _JGIT_VERS unless using a snapshot
JGIT_DOC_URL = "http://download.eclipse.org/jgit/site/" + _DOC_VERS + "/apidocs"
_JGIT_REPO = MAVEN_CENTRAL # Leave here even if set to MAVEN_CENTRAL.
_JGIT_REPO = GERRIT # Leave here even if set to MAVEN_CENTRAL.
# set this to use a local version.
# "/home/<user>/projects/jgit"
@@ -26,28 +26,28 @@ def jgit_maven_repos():
name = "jgit_lib",
artifact = "org.eclipse.jgit:org.eclipse.jgit:" + _JGIT_VERS,
repository = _JGIT_REPO,
sha1 = "4ae44a6157e1bc4c5b373be0c274a8f1d9badd76",
src_sha1 = "ad6f30f7b7f016a1390f8d289be7da2a9a1f47c5",
sha1 = "38489eca0a4308087081d07774af86aa6a50b2ab",
src_sha1 = "e43c58829c72b5b18e16d1b2bbd1396ddd93098f",
unsign = True,
)
maven_jar(
name = "jgit_servlet",
artifact = "org.eclipse.jgit:org.eclipse.jgit.http.server:" + _JGIT_VERS,
repository = _JGIT_REPO,
sha1 = "687f1d10cfc6424dfbe06acb54b9e67afe2fd917",
sha1 = "f5be45e4f97f0bf0825e4ff8fcb2f47588dd7e92",
unsign = True,
)
maven_jar(
name = "jgit_archive",
artifact = "org.eclipse.jgit:org.eclipse.jgit.archive:" + _JGIT_VERS,
repository = _JGIT_REPO,
sha1 = "134489ba021e0923735ec85d07f2adde2c8d1e8d",
sha1 = "f202f169b2e3a50be90b4123baa941136eda3ed6",
)
maven_jar(
name = "jgit_junit",
artifact = "org.eclipse.jgit:org.eclipse.jgit.junit:" + _JGIT_VERS,
repository = _JGIT_REPO,
sha1 = "532ad27983c0d77254020ab22d0b2bb8f3d7cd0f",
sha1 = "dd9f7e4cc41b4f47591ce51c4752ccfef012c553",
unsign = True,
)