Don't permit the same commit twice on the same change

Repeated uses of "repo upload --replace" for the same change id
and commit, without changing the commit SHA-1, would create more
than one patch set with identical content.  This is confusing to
read and review.  Disallowing it simplifies things for any reader.

Caused-by: jbq
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-01-26 12:39:23 -08:00
parent 59a9145fd9
commit 4679770f9a
2 changed files with 13 additions and 0 deletions

View File

@@ -27,6 +27,10 @@ public interface PatchSetAccess extends Access<PatchSet, PatchSet.Id> {
@Query("WHERE id.changeId = ? ORDER BY id.patchSetId")
ResultSet<PatchSet> byChange(Change.Id id) throws OrmException;
@Query("WHERE id.changeId = ? AND revision = ?")
ResultSet<PatchSet> byChangeRevision(Change.Id id, RevId rev)
throws OrmException;
@Query("WHERE revision = ? LIMIT 2")
ResultSet<PatchSet> byRevision(RevId rev) throws OrmException;

View File

@@ -28,6 +28,7 @@ import com.google.gerrit.client.reviewdb.ChangeMessage;
import com.google.gerrit.client.reviewdb.ContactInformation;
import com.google.gerrit.client.reviewdb.ContributorAgreement;
import com.google.gerrit.client.reviewdb.PatchSet;
import com.google.gerrit.client.reviewdb.RevId;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.git.PatchSetImporter;
@@ -597,6 +598,14 @@ class Receive extends AbstractGitCommand {
change = changeCache.get(changeId);
}
// Don't allow the same commit to appear twice on the same change
//
if (!db.patchSets().byChangeRevision(changeId,
new RevId(cmd.getNewId().name())).toList().isEmpty()) {
reject(cmd, "patch set exists");
return null;
}
final PatchSet ps = new PatchSet(change.newPatchSetId());
ps.setCreatedOn(new Timestamp(System.currentTimeMillis()));
ps.setUploader(userAccount.getId());