Merge "Use JSON for encoding PatchLineComment data."
This commit is contained in:
commit
379aa97521
@ -219,7 +219,10 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
|
||||
// Even though reading from changes might not be enabled, we need to
|
||||
// parse any existing revision notes so we can merge them.
|
||||
return RevisionNoteMap.parse(
|
||||
noteUtil, getId(), rw.getObjectReader(), noteMap, true);
|
||||
noteUtil, getId(),
|
||||
rw.getObjectReader(),
|
||||
noteMap,
|
||||
PatchLineComment.Status.DRAFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,10 +35,14 @@ import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.GerritServerId;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.revwalk.FooterKey;
|
||||
import org.eclipse.jgit.util.GitDateFormatter;
|
||||
@ -100,16 +104,20 @@ public class ChangeNoteUtil {
|
||||
private final PersonIdent serverIdent;
|
||||
private final String anonymousCowardName;
|
||||
private final String serverId;
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private final boolean writeJson;
|
||||
|
||||
@Inject
|
||||
public ChangeNoteUtil(AccountCache accountCache,
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
@AnonymousCowardName String anonymousCowardName,
|
||||
@GerritServerId String serverId) {
|
||||
@GerritServerId String serverId,
|
||||
@GerritServerConfig Config config) {
|
||||
this.accountCache = accountCache;
|
||||
this.serverIdent = serverIdent;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
this.serverId = serverId;
|
||||
this.writeJson = config.getBoolean("notedb", "writeJson", false);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@ -121,6 +129,18 @@ public class ChangeNoteUtil {
|
||||
when, serverIdent.getTimeZone());
|
||||
}
|
||||
|
||||
public boolean getWriteJson() {
|
||||
return writeJson;
|
||||
}
|
||||
|
||||
public Gson getGson() {
|
||||
return gson;
|
||||
}
|
||||
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
public Account.Id parseIdent(PersonIdent ident, Change.Id changeId)
|
||||
throws ConfigInvalidException {
|
||||
String email = ident.getEmailAddress();
|
||||
|
@ -596,7 +596,8 @@ class ChangeNotesParser {
|
||||
ObjectReader reader = walk.getObjectReader();
|
||||
ChangeNotesCommit tipCommit = walk.parseCommit(tip);
|
||||
revisionNoteMap = RevisionNoteMap.parse(
|
||||
noteUtil, id, reader, NoteMap.read(reader, tipCommit), false);
|
||||
noteUtil, id, reader, NoteMap.read(reader, tipCommit),
|
||||
PatchLineComment.Status.PUBLISHED);
|
||||
Map<RevId, RevisionNote> rns = revisionNoteMap.revisionNotes;
|
||||
|
||||
for (Map.Entry<RevId, RevisionNote> e : rns.entrySet()) {
|
||||
|
@ -452,7 +452,11 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
// Even though reading from changes might not be enabled, we need to
|
||||
// parse any existing revision notes so we can merge them.
|
||||
return RevisionNoteMap.parse(
|
||||
noteUtil, getId(), rw.getObjectReader(), noteMap, false);
|
||||
noteUtil,
|
||||
getId(),
|
||||
rw.getObjectReader(),
|
||||
noteMap,
|
||||
PatchLineComment.Status.PUBLISHED);
|
||||
}
|
||||
|
||||
private void checkComments(Map<RevId, RevisionNote> existingNotes,
|
||||
|
@ -141,7 +141,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
|
||||
ObjectReader reader = handle.walk().getObjectReader();
|
||||
revisionNoteMap = RevisionNoteMap.parse(
|
||||
args.noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit),
|
||||
true);
|
||||
PatchLineComment.Status.DRAFT);
|
||||
Multimap<RevId, PatchLineComment> cs = ArrayListMultimap.create();
|
||||
for (RevisionNote rn : revisionNoteMap.revisionNotes.values()) {
|
||||
for (PatchLineComment c : rn.comments) {
|
||||
|
@ -28,7 +28,11 @@ import org.eclipse.jgit.lib.ObjectReader;
|
||||
import org.eclipse.jgit.util.MutableInteger;
|
||||
import org.eclipse.jgit.util.RawParseUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
class RevisionNote {
|
||||
static final int MAX_NOTE_SZ = 25 << 20;
|
||||
@ -65,21 +69,51 @@ class RevisionNote {
|
||||
final String pushCert;
|
||||
|
||||
RevisionNote(ChangeNoteUtil noteUtil, Change.Id changeId,
|
||||
ObjectReader reader, ObjectId noteId, boolean draftsOnly)
|
||||
ObjectReader reader, ObjectId noteId, PatchLineComment.Status status)
|
||||
throws ConfigInvalidException, IOException {
|
||||
|
||||
raw = reader.open(noteId, OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
|
||||
MutableInteger p = new MutableInteger();
|
||||
trimLeadingEmptyLines(raw, p);
|
||||
if (!draftsOnly) {
|
||||
if (p.value >= raw.length) {
|
||||
comments = null;
|
||||
pushCert = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (isJson(raw, p.value)) {
|
||||
RevisionNoteData data = parseJson(noteUtil, p.value);
|
||||
comments = data.exportComments(status);
|
||||
if (status == PatchLineComment.Status.PUBLISHED) {
|
||||
pushCert = data.pushCert;
|
||||
} else {
|
||||
pushCert = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (status == PatchLineComment.Status.PUBLISHED) {
|
||||
pushCert = parsePushCert(changeId, raw, p);
|
||||
trimLeadingEmptyLines(raw, p);
|
||||
} else {
|
||||
pushCert = null;
|
||||
}
|
||||
PatchLineComment.Status status = draftsOnly
|
||||
? PatchLineComment.Status.DRAFT
|
||||
: PatchLineComment.Status.PUBLISHED;
|
||||
comments = ImmutableList.copyOf(
|
||||
noteUtil.parseNote(raw, p, changeId, status));
|
||||
}
|
||||
|
||||
private static boolean isJson(byte[] raw, int offset) {
|
||||
return raw[offset] == '{' || raw[offset] == '[';
|
||||
}
|
||||
|
||||
private RevisionNoteData parseJson(ChangeNoteUtil noteUtil, int offset)
|
||||
throws IOException{
|
||||
RevisionNoteData data;
|
||||
try (InputStream is = new ByteArrayInputStream(
|
||||
raw, offset, raw.length - offset);
|
||||
Reader r = new InputStreamReader(is)) {
|
||||
data = noteUtil.getGson().fromJson(r, RevisionNoteData.class);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,12 @@
|
||||
package com.google.gerrit.server.notedb;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.gerrit.server.PatchLineCommentsUtil.PLC_ORDER;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
@ -25,6 +28,10 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -79,6 +86,16 @@ class RevisionNoteBuilder {
|
||||
delete = new HashSet<>();
|
||||
}
|
||||
|
||||
public byte[] build(ChangeNoteUtil noteUtil) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
if (noteUtil.getWriteJson()) {
|
||||
buildNoteJson(noteUtil, out);
|
||||
} else {
|
||||
buildNoteLegacy(noteUtil, out);
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
void putComment(PatchLineComment comment) {
|
||||
checkArgument(!delete.contains(comment.getKey()),
|
||||
"cannot both delete and put %s", comment.getKey());
|
||||
@ -94,15 +111,9 @@ class RevisionNoteBuilder {
|
||||
this.pushCert = pushCert;
|
||||
}
|
||||
|
||||
byte[] build(ChangeNoteUtil noteUtil) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
if (pushCert != null) {
|
||||
byte[] certBytes = pushCert.getBytes(UTF_8);
|
||||
out.write(certBytes, 0, trimTrailingNewlines(certBytes));
|
||||
out.write('\n');
|
||||
}
|
||||
|
||||
private Multimap<PatchSet.Id, PatchLineComment> buildCommentMap() {
|
||||
Multimap<PatchSet.Id, PatchLineComment> all = ArrayListMultimap.create();
|
||||
|
||||
for (PatchLineComment c : baseComments) {
|
||||
if (!delete.contains(c.getKey()) && !put.containsKey(c.getKey())) {
|
||||
all.put(c.getPatchSetId(), c);
|
||||
@ -113,8 +124,39 @@ class RevisionNoteBuilder {
|
||||
all.put(c.getPatchSetId(), c);
|
||||
}
|
||||
}
|
||||
noteUtil.buildNote(all, out);
|
||||
return out.toByteArray();
|
||||
return all;
|
||||
}
|
||||
|
||||
private void buildNoteJson(final ChangeNoteUtil noteUtil, OutputStream out)
|
||||
throws IOException {
|
||||
Multimap<PatchSet.Id, PatchLineComment> comments = buildCommentMap();
|
||||
if (comments.isEmpty() && pushCert == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
RevisionNoteData data = new RevisionNoteData();
|
||||
data.comments = FluentIterable.from(PLC_ORDER.sortedCopy(comments.values()))
|
||||
.transform(new Function<PatchLineComment, RevisionNoteData.Comment>() {
|
||||
@Override
|
||||
public RevisionNoteData.Comment apply(PatchLineComment plc) {
|
||||
return new RevisionNoteData.Comment(plc, noteUtil.getServerId());
|
||||
}
|
||||
}).toList();
|
||||
data.pushCert = pushCert;
|
||||
|
||||
try (OutputStreamWriter osw = new OutputStreamWriter(out)) {
|
||||
noteUtil.getGson().toJson(data, osw);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildNoteLegacy(ChangeNoteUtil noteUtil, OutputStream out)
|
||||
throws IOException {
|
||||
if (pushCert != null) {
|
||||
byte[] certBytes = pushCert.getBytes(UTF_8);
|
||||
out.write(certBytes, 0, trimTrailingNewlines(certBytes));
|
||||
out.write('\n');
|
||||
}
|
||||
noteUtil.buildNote(buildCommentMap(), out);
|
||||
}
|
||||
|
||||
private static int trimTrailingNewlines(byte[] bytes) {
|
||||
|
@ -0,0 +1,148 @@
|
||||
// Copyright (C) 2016 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 com.google.gerrit.server.notedb;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Holds the raw data of a RevisionNote.
|
||||
* <p>It is intended for (de)serialization to JSON only.
|
||||
*/
|
||||
class RevisionNoteData {
|
||||
static class Identity {
|
||||
int id;
|
||||
|
||||
Identity(Account.Id id) {
|
||||
this.id = id.get();
|
||||
}
|
||||
|
||||
Account.Id export() {
|
||||
return new Account.Id(id);
|
||||
}
|
||||
}
|
||||
|
||||
static class CommentKey {
|
||||
String uuid;
|
||||
String filename;
|
||||
int patchSetId;
|
||||
int changeId;
|
||||
|
||||
CommentKey(PatchLineComment.Key k) {
|
||||
uuid = k.get();
|
||||
filename = k.getParentKey().getFileName();
|
||||
patchSetId = k.getParentKey().getParentKey().get();
|
||||
changeId = k.getParentKey().getParentKey().getParentKey().get();
|
||||
}
|
||||
|
||||
PatchLineComment.Key export() {
|
||||
return new PatchLineComment.Key(
|
||||
new Patch.Key(
|
||||
new PatchSet.Id(new Change.Id(changeId), patchSetId),
|
||||
filename),
|
||||
uuid);
|
||||
}
|
||||
}
|
||||
|
||||
static class CommentRange {
|
||||
int startLine;
|
||||
int startChar;
|
||||
int endLine;
|
||||
int endChar;
|
||||
|
||||
CommentRange(com.google.gerrit.reviewdb.client.CommentRange cr) {
|
||||
startLine = cr.getStartLine();
|
||||
startChar = cr.getStartCharacter();
|
||||
endLine = cr.getEndLine();
|
||||
endChar = cr.getEndCharacter();
|
||||
}
|
||||
|
||||
com.google.gerrit.reviewdb.client.CommentRange export() {
|
||||
return new com.google.gerrit.reviewdb.client.CommentRange(
|
||||
startLine, startChar, endLine, endChar);
|
||||
}
|
||||
}
|
||||
|
||||
static class Comment {
|
||||
CommentKey key;
|
||||
int lineNbr;
|
||||
Identity author;
|
||||
Timestamp writtenOn;
|
||||
char status;
|
||||
short side;
|
||||
String message;
|
||||
String parentUuid;
|
||||
CommentRange range;
|
||||
String tag;
|
||||
String revId;
|
||||
String serverId;
|
||||
|
||||
public Comment(PatchLineComment plc, String serverId) {
|
||||
key = new CommentKey(plc.getKey());
|
||||
lineNbr = plc.getLine();
|
||||
author = new Identity(plc.getAuthor());
|
||||
writtenOn = plc.getWrittenOn();
|
||||
status = plc.getStatus().getCode();
|
||||
side = plc.getSide();
|
||||
message = plc.getMessage();
|
||||
parentUuid = plc.getParentUuid();
|
||||
range = plc.getRange() != null ? new CommentRange(plc.getRange()) : null;
|
||||
tag = plc.getTag();
|
||||
revId = plc.getRevId().get();
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
PatchLineComment export() {
|
||||
PatchLineComment plc = new PatchLineComment(
|
||||
key.export(), lineNbr, author.export(), parentUuid, writtenOn);
|
||||
plc.setSide(side);
|
||||
plc.setStatus(PatchLineComment.Status.forCode(status));
|
||||
plc.setMessage(message);
|
||||
if (range != null) {
|
||||
plc.setRange(range.export());
|
||||
}
|
||||
plc.setTag(tag);
|
||||
plc.setRevId(new RevId(revId));
|
||||
return plc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String pushCert;
|
||||
List<Comment> comments;
|
||||
|
||||
ImmutableList<PatchLineComment> exportComments(
|
||||
final PatchLineComment.Status status) {
|
||||
return ImmutableList.copyOf(
|
||||
Lists.transform(comments, new Function<Comment, PatchLineComment>() {
|
||||
@Override
|
||||
public PatchLineComment apply(Comment c) {
|
||||
PatchLineComment plc = c.export();
|
||||
plc.setStatus(status);
|
||||
return plc;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ package com.google.gerrit.server.notedb;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
@ -33,11 +34,12 @@ class RevisionNoteMap {
|
||||
|
||||
static RevisionNoteMap parse(ChangeNoteUtil noteUtil,
|
||||
Change.Id changeId, ObjectReader reader, NoteMap noteMap,
|
||||
boolean draftsOnly) throws ConfigInvalidException, IOException {
|
||||
PatchLineComment.Status status)
|
||||
throws ConfigInvalidException, IOException {
|
||||
Map<RevId, RevisionNote> result = new HashMap<>();
|
||||
for (Note note : noteMap) {
|
||||
RevisionNote rn = new RevisionNote(
|
||||
noteUtil, changeId, reader, note.getData(), draftsOnly);
|
||||
noteUtil, changeId, reader, note.getData(), status);
|
||||
result.put(new RevId(note.name()), rn);
|
||||
}
|
||||
return new RevisionNoteMap(noteMap, ImmutableMap.copyOf(result));
|
||||
|
@ -54,6 +54,7 @@ import com.google.gerrit.server.git.GitModule;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.gerrit.testutil.FakeAccountCache;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
||||
@ -66,6 +67,7 @@ import com.google.gwtorm.server.StandardKeyEncoder;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
@ -76,12 +78,31 @@ import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@Ignore
|
||||
@RunWith(ConfigSuite.class)
|
||||
public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
@ConfigSuite.Default
|
||||
public static Config changeNotesLegacy() {
|
||||
Config cfg = new Config();
|
||||
cfg.setBoolean("notedb", null, "writeJson", false);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@ConfigSuite.Config
|
||||
public static Config changeNotesJson() {
|
||||
Config cfg = new Config();
|
||||
cfg.setBoolean("notedb", null, "writeJson", true);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@ConfigSuite.Parameter
|
||||
public Config testConfig;
|
||||
|
||||
private static final TimeZone TZ =
|
||||
TimeZone.getTimeZone("America/Los_Angeles");
|
||||
|
||||
@ -109,13 +130,10 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
@Inject
|
||||
protected AllUsersName allUsers;
|
||||
|
||||
@Inject
|
||||
protected ChangeNoteUtil noteUtil;
|
||||
|
||||
@Inject
|
||||
protected AbstractChangeNotes.Args args;
|
||||
|
||||
private Injector injector;
|
||||
protected Injector injector;
|
||||
private String systemTimeZone;
|
||||
|
||||
@Before
|
||||
@ -143,9 +161,8 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
injector = Guice.createInjector(new FactoryModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
Config cfg = new Config();
|
||||
install(new GitModule());
|
||||
install(NoteDbModule.forTest(cfg));
|
||||
install(NoteDbModule.forTest(testConfig));
|
||||
bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
|
||||
bind(String.class).annotatedWith(GerritServerId.class)
|
||||
.toInstance("gerrit");
|
||||
@ -155,7 +172,7 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
bind(CapabilityControl.Factory.class)
|
||||
.toProvider(Providers.<CapabilityControl.Factory> of(null));
|
||||
bind(Config.class).annotatedWith(GerritServerConfig.class)
|
||||
.toInstance(cfg);
|
||||
.toInstance(testConfig);
|
||||
bind(String.class).annotatedWith(AnonymousCowardName.class)
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
bind(String.class).annotatedWith(CanonicalWebUrl.class)
|
||||
|
@ -449,6 +449,7 @@ public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||
}
|
||||
|
||||
private RevCommit writeCommit(String body) throws Exception {
|
||||
ChangeNoteUtil noteUtil = injector.getInstance(ChangeNoteUtil.class);
|
||||
return writeCommit(body, noteUtil.newIdent(
|
||||
changeOwner.getAccount(), TimeUtil.nowTs(), serverIdent,
|
||||
"Anonymous Coward"));
|
||||
@ -496,6 +497,7 @@ public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||
|
||||
private ChangeNotesParser newParser(ObjectId tip) throws Exception {
|
||||
walk.reset();
|
||||
ChangeNoteUtil noteUtil = injector.getInstance(ChangeNoteUtil.class);
|
||||
return new ChangeNotesParser(
|
||||
newChange().getId(), tip, walk, noteUtil, args.metrics);
|
||||
}
|
||||
|
@ -76,6 +76,9 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
@Inject
|
||||
private DraftCommentNotes.Factory draftNotesFactory;
|
||||
|
||||
@Inject
|
||||
private ChangeNoteUtil noteUtil;
|
||||
|
||||
@Test
|
||||
public void tagChangeMessage() throws Exception {
|
||||
String tag = "jenkins";
|
||||
@ -966,7 +969,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
update.commit();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
assertThat(readNote(notes, commit)).isEqualTo(pushCert);
|
||||
String note = readNote(notes, commit);
|
||||
if (!testJson()) {
|
||||
assertThat(note).isEqualTo(pushCert);
|
||||
}
|
||||
Map<PatchSet.Id, PatchSet> patchSets = notes.getPatchSets();
|
||||
assertThat(patchSets.get(psId1).getPushCertificate()).isNull();
|
||||
assertThat(patchSets.get(psId2).getPushCertificate()).isEqualTo(pushCert);
|
||||
@ -982,23 +988,27 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
update.commit();
|
||||
|
||||
notes = newNotes(c);
|
||||
assertThat(readNote(notes, commit)).isEqualTo(
|
||||
pushCert
|
||||
+ "Revision: " + commit.name() + "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "File: a.txt\n"
|
||||
+ "\n"
|
||||
+ "1:2-3:4\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, ts) + "\n"
|
||||
+ "Author: Change Owner <1@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 7\n"
|
||||
+ "Comment\n"
|
||||
+ "\n");
|
||||
|
||||
patchSets = notes.getPatchSets();
|
||||
assertThat(patchSets.get(psId1).getPushCertificate()).isNull();
|
||||
assertThat(patchSets.get(psId2).getPushCertificate()).isEqualTo(pushCert);
|
||||
assertThat(notes.getComments()).isNotEmpty();
|
||||
|
||||
if (!testJson()) {
|
||||
assertThat(readNote(notes, commit)).isEqualTo(
|
||||
pushCert
|
||||
+ "Revision: " + commit.name() + "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "File: a.txt\n"
|
||||
+ "\n"
|
||||
+ "1:2-3:4\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, ts) + "\n"
|
||||
+ "Author: Change Owner <1@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 7\n"
|
||||
+ "Comment\n"
|
||||
+ "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1403,34 +1413,37 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
walk.getObjectReader().open(
|
||||
note.getData(), Constants.OBJ_BLOB).getBytes();
|
||||
String noteString = new String(bytes, UTF_8);
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time1) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 1\n"
|
||||
+ "\n"
|
||||
+ "2:1-3:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time2) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid2\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 2\n"
|
||||
+ "\n"
|
||||
+ "File: file2\n"
|
||||
+ "\n"
|
||||
+ "3:0-4:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time3) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid3\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 3\n"
|
||||
+ "\n");
|
||||
|
||||
if (!testJson()) {
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time1) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 1\n"
|
||||
+ "\n"
|
||||
+ "2:1-3:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time2) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid2\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 2\n"
|
||||
+ "\n"
|
||||
+ "File: file2\n"
|
||||
+ "\n"
|
||||
+ "3:0-4:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time3) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid3\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 3\n"
|
||||
+ "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1474,25 +1487,28 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
walk.getObjectReader().open(
|
||||
note.getData(), Constants.OBJ_BLOB).getBytes();
|
||||
String noteString = new String(bytes, UTF_8);
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Base-for-patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time1) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 1\n"
|
||||
+ "\n"
|
||||
+ "2:1-3:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time2) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid2\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 2\n"
|
||||
+ "\n");
|
||||
|
||||
if (!testJson()) {
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Base-for-patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time1) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 1\n"
|
||||
+ "\n"
|
||||
+ "2:1-3:1\n"
|
||||
+ ChangeNoteUtil.formatTime(serverIdent, time2) + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid2\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 2\n"
|
||||
+ "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1543,37 +1559,39 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
note.getData(), Constants.OBJ_BLOB).getBytes();
|
||||
String noteString = new String(bytes, UTF_8);
|
||||
String timeStr = ChangeNoteUtil.formatTime(serverIdent, time);
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Base-for-patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 1\n"
|
||||
+ "\n"
|
||||
+ "2:1-3:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid2\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 2\n"
|
||||
+ "\n"
|
||||
+ "Base-for-patch-set: 2\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid3\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 3\n"
|
||||
+ "\n");
|
||||
}
|
||||
|
||||
if (!testJson()) {
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Base-for-patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid1\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 1\n"
|
||||
+ "\n"
|
||||
+ "2:1-3:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid2\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 2\n"
|
||||
+ "\n"
|
||||
+ "Base-for-patch-set: 2\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Other Account <2@gerrit>\n"
|
||||
+ "UUID: uuid3\n"
|
||||
+ "Bytes: 9\n"
|
||||
+ "comment 3\n"
|
||||
+ "\n");
|
||||
}
|
||||
}
|
||||
assertThat(notes.getComments()).isEqualTo(
|
||||
ImmutableMultimap.of(
|
||||
revId, comment1,
|
||||
@ -1615,20 +1633,22 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
note.getData(), Constants.OBJ_BLOB).getBytes();
|
||||
String noteString = new String(bytes, UTF_8);
|
||||
String timeStr = ChangeNoteUtil.formatTime(serverIdent, time);
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Weird\u0002User <3@gerrit>\n"
|
||||
+ "UUID: uuid\n"
|
||||
+ "Bytes: 7\n"
|
||||
+ "comment\n"
|
||||
+ "\n");
|
||||
}
|
||||
|
||||
if (!testJson()) {
|
||||
assertThat(noteString).isEqualTo(
|
||||
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "File: file1\n"
|
||||
+ "\n"
|
||||
+ "1:1-2:1\n"
|
||||
+ timeStr + "\n"
|
||||
+ "Author: Weird\u0002User <3@gerrit>\n"
|
||||
+ "UUID: uuid\n"
|
||||
+ "Bytes: 7\n"
|
||||
+ "comment\n"
|
||||
+ "\n");
|
||||
}
|
||||
}
|
||||
assertThat(notes.getComments())
|
||||
.isEqualTo(ImmutableMultimap.of(comment.getRevId(), comment));
|
||||
}
|
||||
@ -2300,6 +2320,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
assertThat(comments.get(1).getMessage()).isEqualTo("comment 2");
|
||||
}
|
||||
|
||||
private boolean testJson() {
|
||||
return noteUtil.getWriteJson();
|
||||
}
|
||||
|
||||
private String readNote(ChangeNotes notes, ObjectId noteId) throws Exception {
|
||||
ObjectId dataId = notes.revisionNoteMap.noteMap.getNote(noteId).getData();
|
||||
return new String(
|
||||
|
@ -23,6 +23,7 @@ import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.util.RequestId;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.gerrit.testutil.TestChanges;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@ -30,10 +31,12 @@ import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(ConfigSuite.class)
|
||||
public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
@Test
|
||||
public void approvalsCommitFormatSimple() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user