Merge "Make rebuild.Event Comparable"
This commit is contained in:
@@ -26,7 +26,6 @@ import com.google.common.base.Optional;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.ComparisonChain;
|
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
@@ -364,7 +363,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
EventList<PatchLineCommentEvent> plcel = new EventList<>();
|
EventList<PatchLineCommentEvent> plcel = new EventList<>();
|
||||||
for (Account.Id author : draftCommentEvents.keys()) {
|
for (Account.Id author : draftCommentEvents.keys()) {
|
||||||
for (PatchLineCommentEvent e :
|
for (PatchLineCommentEvent e :
|
||||||
EVENT_ORDER.sortedCopy(draftCommentEvents.get(author))) {
|
Ordering.natural().sortedCopy(draftCommentEvents.get(author))) {
|
||||||
if (!plcel.canAdd(e)) {
|
if (!plcel.canAdd(e)) {
|
||||||
flushEventsToDraftUpdate(manager, plcel, change);
|
flushEventsToDraftUpdate(manager, plcel, change);
|
||||||
checkState(plcel.canAdd(e));
|
checkState(plcel.canAdd(e));
|
||||||
@@ -399,7 +398,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
|
|
||||||
private void sortAndFillEvents(Change change, Change noteDbChange,
|
private void sortAndFillEvents(Change change, Change noteDbChange,
|
||||||
List<Event> events, Integer minPsNum) {
|
List<Event> events, Integer minPsNum) {
|
||||||
Collections.sort(events, EVENT_ORDER);
|
Collections.sort(events);
|
||||||
events.add(new FinalUpdatesEvent(change, noteDbChange));
|
events.add(new FinalUpdatesEvent(change, noteDbChange));
|
||||||
|
|
||||||
// Ensure the first event in the list creates the change, setting the author
|
// Ensure the first event in the list creates the change, setting the author
|
||||||
@@ -566,23 +565,6 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Ordering<Event> EVENT_ORDER = new Ordering<Event>() {
|
|
||||||
@Override
|
|
||||||
public int compare(Event a, Event b) {
|
|
||||||
return ComparisonChain.start()
|
|
||||||
.compare(a.when, b.when)
|
|
||||||
.compareTrueFirst(isPatchSet(a), isPatchSet(b))
|
|
||||||
.compareTrueFirst(a.predatesChange, b.predatesChange)
|
|
||||||
.compare(a.who, b.who, ReviewDbUtil.intKeyOrdering())
|
|
||||||
.compare(a.psId, b.psId, ReviewDbUtil.intKeyOrdering().nullsLast())
|
|
||||||
.result();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPatchSet(Event e) {
|
|
||||||
return e instanceof PatchSetEvent;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void createChange(ChangeUpdate update, Change change) {
|
static void createChange(ChangeUpdate update, Change change) {
|
||||||
update.setSubjectForCommit("Create change");
|
update.setSubjectForCommit("Create change");
|
||||||
update.setChangeId(change.getKey().get());
|
update.setChangeId(change.getKey().get());
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ import static com.google.common.base.Preconditions.checkState;
|
|||||||
import static com.google.gerrit.server.notedb.rebuild.ChangeRebuilderImpl.MAX_WINDOW_MS;
|
import static com.google.gerrit.server.notedb.rebuild.ChangeRebuilderImpl.MAX_WINDOW_MS;
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.collect.ComparisonChain;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
|
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||||
import com.google.gerrit.server.notedb.AbstractChangeUpdate;
|
import com.google.gerrit.server.notedb.AbstractChangeUpdate;
|
||||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@@ -28,7 +30,7 @@ import java.io.IOException;
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
abstract class Event {
|
abstract class Event implements Comparable<Event> {
|
||||||
// NOTE: EventList only supports direct subclasses, not an arbitrary
|
// NOTE: EventList only supports direct subclasses, not an arbitrary
|
||||||
// hierarchy.
|
// hierarchy.
|
||||||
|
|
||||||
@@ -68,6 +70,10 @@ abstract class Event {
|
|||||||
|
|
||||||
abstract void apply(ChangeUpdate update) throws OrmException, IOException;
|
abstract void apply(ChangeUpdate update) throws OrmException, IOException;
|
||||||
|
|
||||||
|
protected boolean isPatchSet() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this)
|
return MoreObjects.toStringHelper(this)
|
||||||
@@ -76,4 +82,16 @@ abstract class Event {
|
|||||||
.add("when", when)
|
.add("when", when)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Event other) {
|
||||||
|
return ComparisonChain.start()
|
||||||
|
.compare(this.when, other.when)
|
||||||
|
.compareTrueFirst(isPatchSet(), isPatchSet())
|
||||||
|
.compareTrueFirst(this.predatesChange, other.predatesChange)
|
||||||
|
.compare(this.who, other.who, ReviewDbUtil.intKeyOrdering())
|
||||||
|
.compare(this.psId, other.psId,
|
||||||
|
ReviewDbUtil.intKeyOrdering().nullsLast())
|
||||||
|
.result();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ class PatchSetEvent extends Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isPatchSet() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void setRevision(ChangeUpdate update, PatchSet ps)
|
private void setRevision(ChangeUpdate update, PatchSet ps)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String rev = ps.getRevision().get();
|
String rev = ps.getRevision().get();
|
||||||
|
|||||||
Reference in New Issue
Block a user