Merge branch 'stable-3.0'

* stable-3.0:
  ExportReviewNotes: Use @CommandMetaData to define command name and description

Change-Id: Icddffc96b2b7bed8011b5592a308083363481349
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 903aa9c..9faf80e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
@@ -19,6 +19,7 @@
 import com.google.gerrit.common.data.LabelTypes;
 import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.git.LockFailureException;
+import com.google.gerrit.git.ObjectIds;
 import com.google.gerrit.reviewdb.client.Change;
 import com.google.gerrit.reviewdb.client.PatchSet;
 import com.google.gerrit.reviewdb.client.PatchSetApproval;
@@ -148,7 +149,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);
@@ -172,9 +173,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");
       }
     }
@@ -238,7 +238,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;
         }
       }
@@ -255,32 +255,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::getAccount));
         }
       }
     }
     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::getAccount));
+      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..b6455bb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
@@ -54,6 +54,8 @@
 
   @Inject private RetryHelper retryHelper;
 
+  private static final Object lock = new Object();
+
   private ListMultimap<Project.NameKey, ChangeNotes> changes;
   private ThreadSafeProgressMonitor monitor;
 
@@ -111,7 +113,7 @@
   }
 
   private Map.Entry<Project.NameKey, List<ChangeNotes>> next() {
-    synchronized (changes) {
+    synchronized (lock) {
       if (changes.isEmpty()) {
         return null;
       }