review: Batch submit all changes at once

By batch submitting all of the changes to the MergeQueue we ensure
that the merge queue can sort them by topological order and doesn't
create unnecessary merge commits.  This can be relevant if the user
accidentally uses --reverse flag when submitting changes in bulk or
when there is clock skew on the branch:

  ssh r gerrit review -s $(git rev-list --reverse origin/master..)

Unfortunately we can't do a full batch submit, as there isn't that
level of transaction support avaliable in the database API.  But we
can avoid starting the merger on the branch until after all of the
affected changes have been marked SUBMITTED.

The better way to ensure submits happen correctly is to perform a
topological sort of the changes using the same sorter as MergeOp, and
then submit them from the root down.  This ensures that an early merge
attempt started by a different thread will be unable to merge the
change, because its parent isn't yet marked SUBMITTED.  Unfortunately
reusing that code here is non-trivial, so I'm punting on it for now.

Change-Id: I0242a360fcd8ba8f8c7fa5dcee021867f91352f8
Signed-off-by: Shawn O. Pearce <sop@google.com>
1 file changed