Prevent duplicate commits in same project when uploading to refs/changes/n

Under certain circumstances, when pushing to 'refs/changes/n', the same
commit can be pushed onto multiple changes even if they are on the same
branch.

As a result of this, if the commit sha1 is used as change identifier
in the 'review' ssh command, it will fail with the error:

  'fatal: <SHA1> matches multiple patch sets.'

This commit performs the same check as when pushing to 'refs/for/branch'
to prevent this, and will show "commit already exists (in the project)"
error message to reject uploading a commit to an existing change via
`refs/changes/n` if the commit was already successfully pushed to a change
in project scope.

Bug: issue 2374
Change-Id: I1c000b2cc3e155617cdc9c295a46ce2107ec47ca
3 files changed