Merge branch 'stable-3.0'
* stable-3.0:
CreateReviewNotes: Use UTF_8 constant from StandardCharsets
Change-Id: I2e483631ef609aefba3532cf4e798f6e8abf8953
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
index ff255ae..2cee7cb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
@@ -19,12 +19,13 @@
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.LabelTypes;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.PatchSet;
+import com.google.gerrit.entities.PatchSetApproval;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.git.LockFailureException;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.PatchSet;
-import com.google.gerrit.reviewdb.client.PatchSetApproval;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.git.ObjectIds;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.PatchSetUtil;
@@ -150,7 +151,7 @@
for (RevCommit c : rw) {
PatchSet ps = loadPatchSet(c, branch);
if (ps != null) {
- ChangeNotes notes = notesFactory.create(project, ps.getId().changeId());
+ ChangeNotes notes = notesFactory.create(project, ps.id().changeId());
ObjectId content = createNoteContent(notes, ps);
if (content != null) {
monitor.update(1);
@@ -174,9 +175,8 @@
for (ChangeNotes cn : notes) {
monitor.update(1);
PatchSet ps = psUtil.current(cn);
- ObjectId commitId = ObjectId.fromString(ps.getRevision().get());
- RevCommit commit = rw.parseCommit(commitId);
- getNotes().set(commitId, createNoteContent(cn, ps));
+ RevCommit commit = rw.parseCommit(ps.commitId());
+ getNotes().set(commit, createNoteContent(cn, ps));
getMessage().append("* ").append(commit.getShortMessage()).append("\n");
}
}
@@ -240,7 +240,7 @@
String hash = c.name();
for (ChangeData cd : queryProvider.get().byBranchCommit(project.get(), destBranch, hash)) {
for (PatchSet ps : cd.patchSets()) {
- if (ps.getRevision().matches(hash)) {
+ if (ObjectIds.matchesAbbreviation(ps.commitId(), hash)) {
return ps;
}
}
@@ -257,32 +257,31 @@
// commit time so we will be able to skip this normalization step.
Change change = notes.getChange();
PatchSetApproval submit = null;
- for (PatchSetApproval a : approvalsUtil.byPatchSet(notes, ps.getId(), null, null)) {
- if (a.getValue() == 0) {
+ for (PatchSetApproval a : approvalsUtil.byPatchSet(notes, ps.id(), null, null)) {
+ if (a.value() == 0) {
// Ignore 0 values.
} else if (a.isLegacySubmit()) {
submit = a;
} else {
- LabelType type = labelTypes.byLabel(a.getLabelId());
+ LabelType type = labelTypes.byLabel(a.labelId());
if (type != null) {
fmt.appendApproval(
type,
- a.getValue(),
- a.getAccountId(),
- accountCache.get(a.getAccountId()).map(AccountState::getAccount));
+ a.value(),
+ a.accountId(),
+ accountCache.get(a.accountId()).map(AccountState::account));
}
}
}
if (submit != null) {
fmt.appendSubmittedBy(
- submit.getAccountId(),
- accountCache.get(submit.getAccountId()).map(AccountState::getAccount));
- fmt.appendSubmittedAt(submit.getGranted());
+ submit.accountId(), accountCache.get(submit.accountId()).map(AccountState::account));
+ fmt.appendSubmittedAt(submit.granted());
}
UrlFormatter uf = urlFormatter.get();
if (uf != null && uf.getWebUrl().isPresent()) {
- fmt.appendReviewedOn(uf, notes.getChange().getProject(), ps.getId().changeId());
+ fmt.appendReviewedOn(uf, notes.getChange().getProject(), ps.id().changeId());
}
fmt.appendProject(project.get());
fmt.appendBranch(change.getDest().branch());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
index 1d512c6..e8ece83 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
@@ -20,8 +20,8 @@
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.MultimapBuilder;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.restapi.RestApiException;
-import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.update.RetryHelper;
@@ -54,6 +54,8 @@
@Inject private RetryHelper retryHelper;
+ private static final Object lock = new Object();
+
private ListMultimap<Project.NameKey, ChangeNotes> changes;
private ThreadSafeProgressMonitor monitor;
@@ -88,30 +90,31 @@
private void export(Project.NameKey project, List<ChangeNotes> notes)
throws RestApiException, UpdateException {
- retryHelper.execute(
- updateFactory -> {
- try (Repository git = gitManager.openRepository(project)) {
- CreateReviewNotes crn = reviewNotesFactory.create(project, git);
- crn.createNotes(notes, monitor);
- crn.commitNotes();
- } catch (RepositoryNotFoundException e) {
- stderr.println("Unable to open project: " + project.get());
- }
- return null;
- },
- RetryHelper.options()
- .listener(
- new RetryListener() {
- @Override
- public <V> void onRetry(Attempt<V> attempt) {
- monitor.update(-notes.size());
- }
- })
- .build());
+ retryHelper
+ .changeUpdate(
+ "exportReviewNotes",
+ updateFactory -> {
+ try (Repository git = gitManager.openRepository(project)) {
+ CreateReviewNotes crn = reviewNotesFactory.create(project, git);
+ crn.createNotes(notes, monitor);
+ crn.commitNotes();
+ } catch (RepositoryNotFoundException e) {
+ stderr.println("Unable to open project: " + project.get());
+ }
+ return null;
+ })
+ .listener(
+ new RetryListener() {
+ @Override
+ public <V> void onRetry(Attempt<V> attempt) {
+ monitor.update(-notes.size());
+ }
+ })
+ .call();
}
private Map.Entry<Project.NameKey, List<ChangeNotes>> next() {
- synchronized (changes) {
+ synchronized (lock) {
if (changes.isEmpty()) {
return null;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java
index 5559eeb..480a268 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java
@@ -19,9 +19,9 @@
import com.google.common.base.Strings;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.LabelValue;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.config.UrlFormatter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -76,20 +76,20 @@
*/
private void appendUserData(Account.Id accountId, Optional<Account> account) {
checkState(
- !account.isPresent() || accountId.equals(account.get().getId()), "mismatching account IDs");
+ !account.isPresent() || accountId.equals(account.get().id()), "mismatching account IDs");
boolean needSpace = false;
boolean wroteData = false;
if (account.isPresent()) {
- String fullName = account.get().getFullName();
+ String fullName = account.get().fullName();
if (!Strings.isNullOrEmpty(fullName)) {
sb.append(fullName);
needSpace = true;
wroteData = true;
}
- String preferredEmail = account.get().getPreferredEmail();
+ String preferredEmail = account.get().preferredEmail();
if (!Strings.isNullOrEmpty(preferredEmail)) {
if (needSpace) {
sb.append(" ");
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java
index 3365abe..311a808 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java
@@ -15,10 +15,10 @@
package com.googlesource.gerrit.plugins.reviewnotes;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
import com.google.gerrit.extensions.restapi.RestApiException;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.ProjectRunnable;
@@ -96,20 +96,23 @@
return;
}
try {
- retryHelper.execute(
- updateFactory -> {
- Project.NameKey projectName = Project.nameKey(e.getProjectName());
- try (Repository git = repoManager.openRepository(projectName)) {
- CreateReviewNotes crn = reviewNotesFactory.create(projectName, git);
- crn.createNotes(
- e.getRefName(),
- ObjectId.fromString(e.getOldObjectId()),
- ObjectId.fromString(e.getNewObjectId()),
- null);
- crn.commitNotes();
- }
- return null;
- });
+ retryHelper
+ .changeUpdate(
+ "createReviewNotes",
+ updateFactory -> {
+ Project.NameKey projectName = Project.nameKey(e.getProjectName());
+ try (Repository git = repoManager.openRepository(projectName)) {
+ CreateReviewNotes crn = reviewNotesFactory.create(projectName, git);
+ crn.createNotes(
+ e.getRefName(),
+ ObjectId.fromString(e.getOldObjectId()),
+ ObjectId.fromString(e.getNewObjectId()),
+ null);
+ crn.commitNotes();
+ }
+ return null;
+ })
+ .call();
} catch (RestApiException | UpdateException x) {
logger.atSevere().withCause(x).log(x.getMessage());
}