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:
@@ -27,6 +27,10 @@ public interface PatchSetAccess extends Access<PatchSet, PatchSet.Id> {
|
|||||||
@Query("WHERE id.changeId = ? ORDER BY id.patchSetId")
|
@Query("WHERE id.changeId = ? ORDER BY id.patchSetId")
|
||||||
ResultSet<PatchSet> byChange(Change.Id id) throws OrmException;
|
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")
|
@Query("WHERE revision = ? LIMIT 2")
|
||||||
ResultSet<PatchSet> byRevision(RevId rev) throws OrmException;
|
ResultSet<PatchSet> byRevision(RevId rev) throws OrmException;
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ import com.google.gerrit.client.reviewdb.ChangeMessage;
|
|||||||
import com.google.gerrit.client.reviewdb.ContactInformation;
|
import com.google.gerrit.client.reviewdb.ContactInformation;
|
||||||
import com.google.gerrit.client.reviewdb.ContributorAgreement;
|
import com.google.gerrit.client.reviewdb.ContributorAgreement;
|
||||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
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.reviewdb.ReviewDb;
|
||||||
import com.google.gerrit.client.rpc.Common;
|
import com.google.gerrit.client.rpc.Common;
|
||||||
import com.google.gerrit.git.PatchSetImporter;
|
import com.google.gerrit.git.PatchSetImporter;
|
||||||
@@ -597,6 +598,14 @@ class Receive extends AbstractGitCommand {
|
|||||||
change = changeCache.get(changeId);
|
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());
|
final PatchSet ps = new PatchSet(change.newPatchSetId());
|
||||||
ps.setCreatedOn(new Timestamp(System.currentTimeMillis()));
|
ps.setCreatedOn(new Timestamp(System.currentTimeMillis()));
|
||||||
ps.setUploader(userAccount.getId());
|
ps.setUploader(userAccount.getId());
|
||||||
|
Reference in New Issue
Block a user