summaryrefslogtreecommitdiffstats
path: root/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeUpdate.java
diff options
context:
space:
mode:
Diffstat (limited to 'gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeUpdate.java')
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeUpdate.java111
1 files changed, 93 insertions, 18 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeUpdate.java b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeUpdate.java
index 7af0cb4766..7e0daa61c4 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeUpdate.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/notedb/ChangeUpdate.java
@@ -29,14 +29,17 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_HASHTAGS;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_LABEL;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET_DESCRIPTION;
+import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PRIVATE;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_READ_ONLY_UNTIL;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_REAL_USER;
+import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_REVERT_OF;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_STATUS;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBJECT;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMISSION_ID;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMITTED_WITH;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TAG;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC;
+import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_WORK_IN_PROGRESS;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.sanitizeFooter;
import static java.util.Comparator.comparing;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
@@ -56,11 +59,12 @@ import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.client.RobotComment;
+import com.google.gerrit.server.CurrentUser;
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.project.ChangeControl;
+import com.google.gerrit.server.mail.Address;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.util.LabelVote;
import com.google.gerrit.server.util.RequestId;
@@ -104,9 +108,9 @@ import org.eclipse.jgit.revwalk.RevWalk;
*/
public class ChangeUpdate extends AbstractChangeUpdate {
public interface Factory {
- ChangeUpdate create(ChangeControl ctl);
+ ChangeUpdate create(ChangeNotes notes, CurrentUser user);
- ChangeUpdate create(ChangeControl ctl, Date when);
+ ChangeUpdate create(ChangeNotes notes, CurrentUser user, Date when);
ChangeUpdate create(
Change change,
@@ -117,16 +121,19 @@ public class ChangeUpdate extends AbstractChangeUpdate {
Comparator<String> labelNameComparator);
@VisibleForTesting
- ChangeUpdate create(ChangeControl ctl, Date when, Comparator<String> labelNameComparator);
+ ChangeUpdate create(
+ ChangeNotes notes, CurrentUser user, Date when, Comparator<String> labelNameComparator);
}
private final AccountCache accountCache;
+ private final NoteDbUpdateManager.Factory updateManagerFactory;
private final ChangeDraftUpdate.Factory draftUpdateFactory;
private final RobotCommentUpdate.Factory robotCommentUpdateFactory;
- private final NoteDbUpdateManager.Factory updateManagerFactory;
+ private final DeleteCommentRewriter.Factory deleteCommentRewriterFactory;
private final Table<String, Account.Id, Optional<Short>> approvals;
private final Map<Account.Id, ReviewerStateInternal> reviewers = new LinkedHashMap<>();
+ private final Map<Address, ReviewerStateInternal> reviewersByEmail = new LinkedHashMap<>();
private final List<Comment> comments = new ArrayList<>();
private String commitSubject;
@@ -149,9 +156,13 @@ public class ChangeUpdate extends AbstractChangeUpdate {
private String psDescription;
private boolean currentPatchSet;
private Timestamp readOnlyUntil;
+ private Boolean isPrivate;
+ private Boolean workInProgress;
+ private Integer revertOf;
private ChangeDraftUpdate draftUpdate;
private RobotCommentUpdate robotCommentUpdate;
+ private DeleteCommentRewriter deleteCommentRewriter;
@AssistedInject
private ChangeUpdate(
@@ -163,8 +174,10 @@ public class ChangeUpdate extends AbstractChangeUpdate {
NoteDbUpdateManager.Factory updateManagerFactory,
ChangeDraftUpdate.Factory draftUpdateFactory,
RobotCommentUpdate.Factory robotCommentUpdateFactory,
+ DeleteCommentRewriter.Factory deleteCommentRewriterFactory,
ProjectCache projectCache,
- @Assisted ChangeControl ctl,
+ @Assisted ChangeNotes notes,
+ @Assisted CurrentUser user,
ChangeNoteUtil noteUtil) {
this(
cfg,
@@ -175,8 +188,10 @@ public class ChangeUpdate extends AbstractChangeUpdate {
updateManagerFactory,
draftUpdateFactory,
robotCommentUpdateFactory,
+ deleteCommentRewriterFactory,
projectCache,
- ctl,
+ notes,
+ user,
serverIdent.getWhen(),
noteUtil);
}
@@ -191,8 +206,10 @@ public class ChangeUpdate extends AbstractChangeUpdate {
NoteDbUpdateManager.Factory updateManagerFactory,
ChangeDraftUpdate.Factory draftUpdateFactory,
RobotCommentUpdate.Factory robotCommentUpdateFactory,
+ DeleteCommentRewriter.Factory deleteCommentRewriterFactory,
ProjectCache projectCache,
- @Assisted ChangeControl ctl,
+ @Assisted ChangeNotes notes,
+ @Assisted CurrentUser user,
@Assisted Date when,
ChangeNoteUtil noteUtil) {
this(
@@ -204,16 +221,14 @@ public class ChangeUpdate extends AbstractChangeUpdate {
updateManagerFactory,
draftUpdateFactory,
robotCommentUpdateFactory,
- ctl,
+ deleteCommentRewriterFactory,
+ notes,
+ user,
when,
- projectCache.get(getProjectName(ctl)).getLabelTypes().nameComparator(),
+ projectCache.get(notes.getProjectName()).getLabelTypes().nameComparator(),
noteUtil);
}
- private static Project.NameKey getProjectName(ChangeControl ctl) {
- return ctl.getProject().getNameKey();
- }
-
private static Table<String, Account.Id, Optional<Short>> approvals(
Comparator<String> nameComparator) {
return TreeBasedTable.create(nameComparator, comparing(IntKey::get));
@@ -229,15 +244,18 @@ public class ChangeUpdate extends AbstractChangeUpdate {
NoteDbUpdateManager.Factory updateManagerFactory,
ChangeDraftUpdate.Factory draftUpdateFactory,
RobotCommentUpdate.Factory robotCommentUpdateFactory,
- @Assisted ChangeControl ctl,
+ DeleteCommentRewriter.Factory deleteCommentRewriterFactory,
+ @Assisted ChangeNotes notes,
+ @Assisted CurrentUser user,
@Assisted Date when,
@Assisted Comparator<String> labelNameComparator,
ChangeNoteUtil noteUtil) {
- super(cfg, migration, ctl, serverIdent, anonymousCowardName, noteUtil, when);
+ super(cfg, migration, notes, user, serverIdent, anonymousCowardName, noteUtil, when);
this.accountCache = accountCache;
+ this.updateManagerFactory = updateManagerFactory;
this.draftUpdateFactory = draftUpdateFactory;
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
- this.updateManagerFactory = updateManagerFactory;
+ this.deleteCommentRewriterFactory = deleteCommentRewriterFactory;
this.approvals = approvals(labelNameComparator);
}
@@ -251,6 +269,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
NoteDbUpdateManager.Factory updateManagerFactory,
ChangeDraftUpdate.Factory draftUpdateFactory,
RobotCommentUpdate.Factory robotCommentUpdateFactory,
+ DeleteCommentRewriter.Factory deleteCommentRewriterFactory,
ChangeNoteUtil noteUtil,
@Assisted Change change,
@Assisted("effective") @Nullable Account.Id accountId,
@@ -274,6 +293,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
this.draftUpdateFactory = draftUpdateFactory;
this.robotCommentUpdateFactory = robotCommentUpdateFactory;
this.updateManagerFactory = updateManagerFactory;
+ this.deleteCommentRewriterFactory = deleteCommentRewriterFactory;
this.approvals = approvals(labelNameComparator);
}
@@ -388,6 +408,11 @@ public class ChangeUpdate extends AbstractChangeUpdate {
createDraftUpdateIfNull().deleteComment(c);
}
+ public void deleteCommentByRewritingHistory(String uuid, String newMessage) {
+ deleteCommentRewriter =
+ deleteCommentRewriterFactory.create(getChange().getId(), uuid, newMessage);
+ }
+
@VisibleForTesting
ChangeDraftUpdate createDraftUpdateIfNull() {
if (draftUpdate == null) {
@@ -469,6 +494,15 @@ public class ChangeUpdate extends AbstractChangeUpdate {
reviewers.put(reviewer, ReviewerStateInternal.REMOVED);
}
+ public void putReviewerByEmail(Address reviewer, ReviewerStateInternal type) {
+ checkArgument(type != ReviewerStateInternal.REMOVED, "invalid ReviewerType");
+ reviewersByEmail.put(reviewer, type);
+ }
+
+ public void removeReviewerByEmail(Address reviewer) {
+ reviewersByEmail.put(reviewer, ReviewerStateInternal.REMOVED);
+ }
+
public void setPatchSetState(PatchSetState psState) {
this.psState = psState;
}
@@ -482,6 +516,13 @@ public class ChangeUpdate extends AbstractChangeUpdate {
this.groups = groups;
}
+ public void setRevertOf(int revertOf) {
+ int ownId = getChange().getId().get();
+ checkArgument(ownId != revertOf, "A change cannot revert itself");
+ this.revertOf = revertOf;
+ rootOnly = true;
+ }
+
/** @return the tree id for the updated tree */
private ObjectId storeRevisionNotes(RevWalk rw, ObjectInserter inserter, ObjectId curr)
throws ConfigInvalidException, OrmException, IOException {
@@ -581,6 +622,8 @@ public class ChangeUpdate extends AbstractChangeUpdate {
@Override
protected CommitBuilder applyImpl(RevWalk rw, ObjectInserter ins, ObjectId curr)
throws OrmException, IOException {
+ checkState(deleteCommentRewriter == null, "cannot update and rewrite ref in one BatchUpdate");
+
CommitBuilder cb = new CommitBuilder();
int ps = psId != null ? psId.get() : getChange().currentPatchSetId().get();
@@ -658,6 +701,10 @@ public class ChangeUpdate extends AbstractChangeUpdate {
addIdent(msg, e.getKey()).append('\n');
}
+ for (Map.Entry<Address, ReviewerStateInternal> e : reviewersByEmail.entrySet()) {
+ addFooter(msg, e.getValue().getByEmailFooterKey(), e.getKey().toString());
+ }
+
for (Table.Cell<String, Account.Id, Optional<Short>> c : approvals.cellSet()) {
addFooter(msg, FOOTER_LABEL);
// Label names/values are safe to append without sanitizing.
@@ -711,6 +758,18 @@ public class ChangeUpdate extends AbstractChangeUpdate {
addFooter(msg, FOOTER_READ_ONLY_UNTIL, ChangeNoteUtil.formatTime(serverIdent, readOnlyUntil));
}
+ if (isPrivate != null) {
+ addFooter(msg, FOOTER_PRIVATE, isPrivate);
+ }
+
+ if (workInProgress != null) {
+ addFooter(msg, FOOTER_WORK_IN_PROGRESS, workInProgress);
+ }
+
+ if (revertOf != null) {
+ addFooter(msg, FOOTER_REVERT_OF, revertOf);
+ }
+
cb.setMessage(msg.toString());
try {
ObjectId treeId = storeRevisionNotes(rw, ins, curr);
@@ -743,6 +802,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
&& changeMessage == null
&& comments.isEmpty()
&& reviewers.isEmpty()
+ && reviewersByEmail.isEmpty()
&& changeId == null
&& branch == null
&& status == null
@@ -757,7 +817,10 @@ public class ChangeUpdate extends AbstractChangeUpdate {
&& tag == null
&& psDescription == null
&& !currentPatchSet
- && readOnlyUntil == null;
+ && readOnlyUntil == null
+ && isPrivate == null
+ && workInProgress == null
+ && revertOf == null;
}
ChangeDraftUpdate getDraftUpdate() {
@@ -768,6 +831,10 @@ public class ChangeUpdate extends AbstractChangeUpdate {
return robotCommentUpdate;
}
+ public DeleteCommentRewriter getDeleteCommentRewriter() {
+ return deleteCommentRewriter;
+ }
+
public void setAllowWriteToNewRef(boolean allow) {
isAllowWriteToNewtRef = allow;
}
@@ -777,6 +844,14 @@ public class ChangeUpdate extends AbstractChangeUpdate {
return isAllowWriteToNewtRef;
}
+ public void setPrivate(boolean isPrivate) {
+ this.isPrivate = isPrivate;
+ }
+
+ public void setWorkInProgress(boolean workInProgress) {
+ this.workInProgress = workInProgress;
+ }
+
void setReadOnlyUntil(Timestamp readOnlyUntil) {
this.readOnlyUntil = readOnlyUntil;
}