Class ChangeUpdate

java.lang.Object
com.google.gerrit.server.notedb.AbstractChangeUpdate
com.google.gerrit.server.notedb.ChangeUpdate

public class ChangeUpdate extends AbstractChangeUpdate
A delta to apply to a change.

This delta will become two unique commits: one in the AllUsers repo that will contain the draft comments on this change and one in the notes branch that will contain approvals, reviewers, change status, subject, submit records, the change message, and published comments. There are limitations on the set of modifications that can be handled in a single update. In particular, there is a single author and timestamp for each update.

This class is not thread-safe.

NOTE: This class also serializes the change in a custom storage format, used in NoteDB. All changes to the storage format must be both forward and backward compatible, see comment on ChangeNotesParser.

Such changes include e.g. introducing/removing footers, modifying footer formats, mutations of the attached ChangeRevisionNote.

  • Field Details

    • MAX_CUSTOM_KEY_LENGTH

      public static final int MAX_CUSTOM_KEY_LENGTH
      See Also:
    • MAX_CUSTOM_KEYED_VALUE_LENGTH

      public static final int MAX_CUSTOM_KEYED_VALUE_LENGTH
      See Also:
    • MAX_CUSTOM_KEYED_VALUES

      public static final int MAX_CUSTOM_KEYED_VALUES
      See Also:
  • Method Details

    • commit

      public org.eclipse.jgit.lib.ObjectId commit() throws IOException
      Throws:
      IOException
    • setChangeId

      public void setChangeId(String changeId)
    • setBranch

      public void setBranch(String branch)
    • setStatus

      public void setStatus(Change.Status status)
    • fixStatusToMerged

      public void fixStatusToMerged(SubmissionId submissionId)
    • putApproval

      public void putApproval(String label, short value)
    • putApprovalFor

      public void putApprovalFor(Account.Id reviewer, String label, short value)
    • getApprovals

      public com.google.common.collect.ImmutableTable<String,Account.Id,Optional<PatchSetApproval>> getApprovals()
    • removeApprovalFor

      public void removeApprovalFor(Account.Id reviewer, String label)
    • putCopiedApproval

      public void putCopiedApproval(PatchSetApproval copiedPatchSetApproval)
      We expect the copied flag of copiedPatchSetApproval to be set, since this method is only meant for copied approvals.
    • removeCopiedApprovalFor

      public void removeCopiedApprovalFor(Account.Id realUserId, Account.Id reviewerId, String label)
    • merge

      public void merge(SubmissionId submissionId, Iterable<SubmitRecord> submitRecords)
    • setSubjectForCommit

      public void setSubjectForCommit(String commitSubject)
    • setSubject

      public void setSubject(String subject)
    • setChangeMessage

      public void setChangeMessage(String changeMessage)
    • setTag

      public void setTag(String tag)
    • setPsDescription

      public void setPsDescription(String psDescription)
    • putSubmitRequirementResults

      public void putSubmitRequirementResults(Collection<SubmitRequirementResult> rs)
    • putComment

      public void putComment(Comment.Status status, HumanComment c)
    • putRobotComment

      public void putRobotComment(RobotComment c)
    • deleteComment

      public void deleteComment(HumanComment c)
    • deleteCommentByRewritingHistory

      public void deleteCommentByRewritingHistory(String uuid, String newMessage)
    • deleteChangeMessageByRewritingHistory

      public void deleteChangeMessageByRewritingHistory(String targetMessageId, String newMessage)
    • setTopic

      public void setTopic(String topic, TopicValidator validator) throws ValidationException
      Throws:
      ValidationException
    • setCommit

      public void setCommit(org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectId id) throws IOException
      Throws:
      IOException
    • setCommit

      public void setCommit(org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectId id, String pushCert) throws IOException
      Throws:
      IOException
    • setHashtags

      public void setHashtags(Set<String> hashtags)
    • addCustomKeyedValue

      public void addCustomKeyedValue(String key, String value) throws ValidationException
      Throws:
      ValidationException
    • deleteCustomKeyedValue

      public void deleteCustomKeyedValue(String key) throws ValidationException
      Throws:
      ValidationException
    • addToPlannedAttentionSetUpdates

      public void addToPlannedAttentionSetUpdates(Set<AttentionSetUpdate> updates)
      Adds attention set updates that should be stored in NoteDb.

      If invoked multiple times with attention set updates for the same user, only the attention set update of the first invocation is stored for this user and further attention set updates for this user are silently ignored. This means if callers invoke this method multiple times with attention set updates for the same user, they must ensure that the first call is being done with the attention set update that should take precedence.

      Parameters:
      updates - Attention set updates that should be performed. The updates must not have any timestamp set (AttentionSetUpdate.timestamp() must return null). This is because the timestamp of all performed updates is always the timestamp of when the NoteDb commit is created. Each of the provided updates must be for a different user, if there are multiple updates for the same user the update is rejected.
      Throws:
      IllegalArgumentException - thrown if any of the provided updates has a timestamp set, or if the provided set of updates contains multiple updates for the same user
    • addToPlannedAttentionSetUpdates

      public void addToPlannedAttentionSetUpdates(AttentionSetUpdate update)
    • getAttentionSetUpdates

      public com.google.common.collect.ImmutableList<AttentionSetUpdate> getAttentionSetUpdates()
    • getReviewers

      public Map<Account.Id,ReviewerStateInternal> getReviewers()
    • putReviewer

      public void putReviewer(Account.Id reviewer, ReviewerStateInternal type)
    • removeReviewer

      public void removeReviewer(Account.Id reviewer)
    • putReviewerByEmail

      public void putReviewerByEmail(Address reviewer, ReviewerStateInternal type)
    • removeReviewerByEmail

      public void removeReviewerByEmail(Address reviewer)
    • setPatchSetState

      public void setPatchSetState(PatchSetState psState)
    • setCurrentPatchSet

      public void setCurrentPatchSet()
    • setGroups

      public void setGroups(List<String> groups)
    • setRevertOf

      public void setRevertOf(int revertOf)
    • setCherryPickOf

      public void setCherryPickOf(String cherryPickOf)
    • resetCherryPickOf

      public void resetCherryPickOf()
    • getRefName

      protected String getRefName()
      Specified by:
      getRefName in class AbstractChangeUpdate
    • bypassMaxUpdates

      protected boolean bypassMaxUpdates()
      Description copied from class: AbstractChangeUpdate
      Whether to allow bypassing the check that an update does not exceed the max update count on an object.
      Overrides:
      bypassMaxUpdates in class AbstractChangeUpdate
    • applyImpl

      protected org.eclipse.jgit.lib.CommitBuilder applyImpl(org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter ins, org.eclipse.jgit.lib.ObjectId curr) throws IOException
      Description copied from class: AbstractChangeUpdate
      Create a commit containing the contents of this update.
      Specified by:
      applyImpl in class AbstractChangeUpdate
      ins - inserter to write to; callers should not flush.
      Returns:
      a new commit builder representing this commit, or null to indicate the meta ref should be deleted as a result of this update. The parent, author, and committer fields in the return value are always overwritten. The tree ID may be unset by this method, which indicates to the caller that it should be copied from the parent commit. To indicate that this update is a no-op (but this could not be determined by AbstractChangeUpdate.isEmpty()), return the sentinel AbstractChangeUpdate.NO_OP_UPDATE.
      Throws:
      IOException - if a lower-level error occurred.
    • ignoreFurtherAttentionSetUpdates

      public void ignoreFurtherAttentionSetUpdates()
      When set, default attention set rules are ignored (E.g, adding reviewers -> adds to attention set, etc).
    • getProjectName

      protected Project.NameKey getProjectName()
      Description copied from class: AbstractChangeUpdate
      Returns the NameKey for the project where the update will be stored, which is not necessarily the same as the change's project.
      Specified by:
      getProjectName in class AbstractChangeUpdate
    • isEmpty

      public boolean isEmpty()
      Description copied from class: AbstractChangeUpdate
      Whether no updates have been done.
      Specified by:
      isEmpty in class AbstractChangeUpdate
    • setAllowWriteToNewRef

      public void setAllowWriteToNewRef(boolean allow)
    • allowWriteToNewRef

      public boolean allowWriteToNewRef()
      Overrides:
      allowWriteToNewRef in class AbstractChangeUpdate
    • setPrivate

      public void setPrivate(boolean isPrivate)
    • setWorkInProgress

      public void setWorkInProgress(boolean workInProgress)