Add a "groups" field to PatchSet
This field is intended to be used as an explicit replacement for the current "Related Changes" heuristic, which may involve walking arbitrary amounts of history and making lots of database lookups in the case of some merge topologies. With this field in the index, we can implement GetRelated using a single secondary index lookup once we know the patch set's group identifiers. Combined with the stored PatchSet field, this gives us the entire set of commits that need to be considered for rendering the Related Changes tab, and the only remaining work is to do a simple walk to determine the relative topo ordering. Any idea of automatically grouping changes together requires some amount of heuristics, so we use opaque string values in this field in case we decide to change heuristics later. If we change heuristics, old groups will still be valid as long as the relevant changes stay the same. (We might also decide to add a way to manually group changes together; today, this use case is largely handled by other features such as topics, but this implementation does not rule that out.) The field is actually multi-valued, as the heuristics we implemented in GroupCollector multiple groups if it is the merge commit of two distinct branches of open changes. However, since we don't need to look up changes in the database by group, it's not worth the effort of an extra SQL table, so we just concatenate groups together. Another useful feature of this implementation is that group information is preserved when changes are closed, so submitting a change will no longer immediately cause the Related Changes tab to disappear. Use GroupCollector to assign groups in both the main ReceiveCommits case and the schema upgrade (for all open changes). See the documentation of GroupCollector for how this is intended to work. For code paths other than ReceiveCommits, the rules are much simpler, because there is only one change involved in the operation. Depending on the context, we simply either copy the existing group of the latest patch set, or we create a new group. Change-Id: I7cef275772882b045be14fd9bbbe7c52c73da2a8
This commit is contained in:
@@ -27,6 +27,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||
import com.google.gerrit.server.git.CodeReviewCommit;
|
||||
import com.google.gerrit.server.git.CommitMergeStatus;
|
||||
import com.google.gerrit.server.git.GroupCollector;
|
||||
import com.google.gerrit.server.git.MergeConflictException;
|
||||
import com.google.gerrit.server.git.MergeException;
|
||||
import com.google.gerrit.server.git.MergeIdenticalTreeException;
|
||||
@@ -186,6 +187,7 @@ public class CherryPick extends SubmitStrategy {
|
||||
args.db.changes().beginTransaction(n.change().getId());
|
||||
try {
|
||||
insertAncestors(args.db, ps.getId(), newCommit);
|
||||
ps.setGroups(GroupCollector.getCurrentGroups(args.db, n.change()));
|
||||
args.db.patchSets().insert(Collections.singleton(ps));
|
||||
n.change()
|
||||
.setCurrentPatchSet(patchSetInfoFactory.get(newCommit, ps.getId()));
|
||||
|
Reference in New Issue
Block a user