Create new patch set references before database records

Ensure the commit used by a new change or replacement patch set
always exists in the Git repository by writing the reference first
as part of the overall BatchRefUpdate, then inserting the database
records if all of the references stored successfully.

This refactoring simplifies some of the logic involved, and lets
some JGit backends that benefit from batching references see all
updates at once, which may reduce the overall transaction time.

Change-Id: Id5a4d8c3d7abd035accc9682714ac782924f0a33
2 files changed