use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeEditModifier method rebaseEdit.
/**
* Rebase change edit on latest patch set
*
* @param repository the affected Git repository
* @param changeControl the {@code ChangeControl} of the change whose change edit should be
* rebased
* @throws AuthException if the user isn't authenticated or not allowed to use change edits
* @throws InvalidChangeOperationException if a change edit doesn't exist for the specified
* change, the change edit is already based on the latest patch set, or the change represents
* the root commit
* @throws MergeConflictException if rebase fails due to merge conflicts
* @throws PermissionBackendException
*/
public void rebaseEdit(Repository repository, ChangeControl changeControl) throws AuthException, InvalidChangeOperationException, IOException, OrmException, MergeConflictException, PermissionBackendException {
assertCanEdit(changeControl);
Optional<ChangeEdit> optionalChangeEdit = lookupChangeEdit(changeControl);
if (!optionalChangeEdit.isPresent()) {
throw new InvalidChangeOperationException(String.format("No change edit exists for change %s", changeControl.getId()));
}
ChangeEdit changeEdit = optionalChangeEdit.get();
PatchSet currentPatchSet = lookupCurrentPatchSet(changeControl);
if (isBasedOn(changeEdit, currentPatchSet)) {
throw new InvalidChangeOperationException(String.format("Change edit for change %s is already based on latest patch set %s", changeControl.getId(), currentPatchSet.getId()));
}
rebase(repository, changeEdit, currentPatchSet);
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeEditUtil method getBasePatchSet.
private PatchSet getBasePatchSet(ChangeControl ctl, Ref ref) throws IOException {
try {
int pos = ref.getName().lastIndexOf("/");
checkArgument(pos > 0, "invalid edit ref: %s", ref.getName());
String psId = ref.getName().substring(pos + 1);
return psUtil.get(db.get(), ctl.getNotes(), new PatchSet.Id(ctl.getId(), Integer.parseInt(psId)));
} catch (OrmException | NumberFormatException e) {
throw new IOException(e);
}
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class StreamEventsApiListener method onDraftPublished.
@Override
public void onDraftPublished(DraftPublishedListener.Event ev) {
try {
ChangeNotes notes = getNotes(ev.getChange());
Change change = notes.getChange();
PatchSet ps = getPatchSet(notes, ev.getRevision());
DraftPublishedEvent event = new DraftPublishedEvent(change);
event.change = changeAttributeSupplier(change);
event.patchSet = patchSetAttributeSupplier(change, ps);
event.uploader = accountAttributeSupplier(ev.getWho());
dispatcher.get().postEvent(change, event);
} catch (OrmException e) {
log.error("Failed to dispatch event", e);
}
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class EventFactory method addDependsOn.
private void addDependsOn(RevWalk rw, ChangeAttribute ca, Change change, PatchSet currentPs) throws OrmException, IOException {
RevCommit commit = rw.parseCommit(ObjectId.fromString(currentPs.getRevision().get()));
final List<String> parentNames = new ArrayList<>(commit.getParentCount());
for (RevCommit p : commit.getParents()) {
parentNames.add(p.name());
}
// this patch set's revision.
for (ChangeData cd : queryProvider.get().byProjectCommits(change.getProject(), parentNames)) {
for (PatchSet ps : cd.patchSets()) {
for (String p : parentNames) {
if (!ps.getRevision().get().equals(p)) {
continue;
}
ca.dependsOn.add(newDependsOn(checkNotNull(cd.change()), ps));
}
}
}
// Sort by original parent order.
Collections.sort(ca.dependsOn, comparing((DependencyAttribute d) -> {
for (int i = 0; i < parentNames.size(); i++) {
if (parentNames.get(i).equals(d.revision)) {
return i;
}
}
return parentNames.size() + 1;
}));
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeRebuilderImpl method buildUpdates.
@Override
public void buildUpdates(NoteDbUpdateManager manager, ChangeBundle bundle) throws IOException, OrmException {
manager.setCheckExpectedState(false).setRefLogMessage("Rebuilding change");
Change change = new Change(bundle.getChange());
if (bundle.getPatchSets().isEmpty()) {
throw new NoPatchSetsException(change.getId());
}
// We will rebuild all events, except for draft comments, in buckets based
// on author and timestamp.
List<Event> events = new ArrayList<>();
ListMultimap<Account.Id, DraftCommentEvent> draftCommentEvents = MultimapBuilder.hashKeys().arrayListValues().build();
events.addAll(getHashtagsEvents(change, manager));
// Delete ref only after hashtags have been read
deleteChangeMetaRef(change, manager.getChangeRepo().cmds);
deleteDraftRefs(change, manager.getAllUsersRepo());
Integer minPsNum = getMinPatchSetNum(bundle);
TreeMap<PatchSet.Id, PatchSetEvent> patchSetEvents = new TreeMap<>(ReviewDbUtil.intKeyOrdering());
for (PatchSet ps : bundle.getPatchSets()) {
PatchSetEvent pse = new PatchSetEvent(change, ps, manager.getChangeRepo().rw);
patchSetEvents.put(ps.getId(), pse);
events.add(pse);
for (Comment c : getComments(bundle, serverId, Status.PUBLISHED, ps)) {
CommentEvent e = new CommentEvent(c, change, ps, patchListCache);
events.add(e.addDep(pse));
}
for (Comment c : getComments(bundle, serverId, Status.DRAFT, ps)) {
DraftCommentEvent e = new DraftCommentEvent(c, change, ps, patchListCache);
draftCommentEvents.put(c.author.getId(), e);
}
}
ensurePatchSetOrder(patchSetEvents);
for (PatchSetApproval psa : bundle.getPatchSetApprovals()) {
PatchSetEvent pse = patchSetEvents.get(psa.getPatchSetId());
if (pse != null) {
events.add(new ApprovalEvent(psa, change.getCreatedOn()).addDep(pse));
}
}
for (Table.Cell<ReviewerStateInternal, Account.Id, Timestamp> r : bundle.getReviewers().asTable().cellSet()) {
events.add(new ReviewerEvent(r, change.getCreatedOn()));
}
Change noteDbChange = new Change(null, null, null, null, null);
for (ChangeMessage msg : bundle.getChangeMessages()) {
Event msgEvent = new ChangeMessageEvent(change, noteDbChange, msg, change.getCreatedOn());
if (msg.getPatchSetId() != null) {
PatchSetEvent pse = patchSetEvents.get(msg.getPatchSetId());
if (pse == null) {
// Ignore events for missing patch sets.
continue;
}
msgEvent.addDep(pse);
}
events.add(msgEvent);
}
sortAndFillEvents(change, noteDbChange, bundle.getPatchSets(), events, minPsNum);
EventList<Event> el = new EventList<>();
for (Event e : events) {
if (!el.canAdd(e)) {
flushEventsToUpdate(manager, el, change);
checkState(el.canAdd(e));
}
el.add(e);
}
flushEventsToUpdate(manager, el, change);
EventList<DraftCommentEvent> plcel = new EventList<>();
for (Account.Id author : draftCommentEvents.keys()) {
for (DraftCommentEvent e : Ordering.natural().sortedCopy(draftCommentEvents.get(author))) {
if (!plcel.canAdd(e)) {
flushEventsToDraftUpdate(manager, plcel, change);
checkState(plcel.canAdd(e));
}
plcel.add(e);
}
flushEventsToDraftUpdate(manager, plcel, change);
}
}
Aggregations