Add uploader's Account.Id and upload timestamp to PatchSet
This is the user that put the PatchSet into the change, and the date and time it was received in by Gerrit. We track all of this data in Gerrit1 so we might as well continue to do so in Gerrit2. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -72,9 +72,14 @@ public final class ChangeMessage {
|
||||
}
|
||||
|
||||
public ChangeMessage(final ChangeMessage.Key k, final Account.Id a) {
|
||||
this(k, a, new Timestamp(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public ChangeMessage(final ChangeMessage.Key k, final Account.Id a,
|
||||
final Timestamp wo) {
|
||||
key = k;
|
||||
author = a;
|
||||
writtenOn = new Timestamp(System.currentTimeMillis());
|
||||
writtenOn = wo;
|
||||
}
|
||||
|
||||
public ChangeMessage.Key getKey() {
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.google.gerrit.client.reviewdb;
|
||||
import com.google.gwtorm.client.Column;
|
||||
import com.google.gwtorm.client.IntKey;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/** A single revision of a {@link Change}. */
|
||||
public final class PatchSet {
|
||||
public static class Id extends IntKey<Change.Id> {
|
||||
@@ -64,6 +66,13 @@ public final class PatchSet {
|
||||
@Column(notNull = false)
|
||||
protected RevId revision;
|
||||
|
||||
@Column(name = "uploader_account_id")
|
||||
protected Account.Id uploader;
|
||||
|
||||
/** When this patch set was first introduced onto the change. */
|
||||
@Column
|
||||
protected Timestamp createdOn;
|
||||
|
||||
protected PatchSet() {
|
||||
}
|
||||
|
||||
@@ -87,6 +96,22 @@ public final class PatchSet {
|
||||
revision = i;
|
||||
}
|
||||
|
||||
public Account.Id getUploader() {
|
||||
return uploader;
|
||||
}
|
||||
|
||||
public void setUploader(final Account.Id who) {
|
||||
uploader = who;
|
||||
}
|
||||
|
||||
public Timestamp getCreatedOn() {
|
||||
return createdOn;
|
||||
}
|
||||
|
||||
public void setCreatedOn(final Timestamp ts) {
|
||||
createdOn = ts;
|
||||
}
|
||||
|
||||
public String getRefName() {
|
||||
final StringBuilder r = new StringBuilder();
|
||||
r.append("refs/changes/");
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.spearce.jgit.transport.ReceiveCommand.Result;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -468,6 +469,8 @@ class Receive extends AbstractGitCommand {
|
||||
new Change(new Change.Id(db.nextChangeId()), userAccount.getId(),
|
||||
destBranch.getNameKey());
|
||||
final PatchSet ps = new PatchSet(change.newPatchSetId());
|
||||
ps.setCreatedOn(change.getCreatedOn());
|
||||
ps.setUploader(userAccount.getId());
|
||||
final PatchSetImporter imp = new PatchSetImporter(db, repo, c, ps, true);
|
||||
imp.setTransaction(txn);
|
||||
imp.run();
|
||||
@@ -538,6 +541,8 @@ class Receive extends AbstractGitCommand {
|
||||
}
|
||||
|
||||
final PatchSet ps = new PatchSet(change.newPatchSetId());
|
||||
ps.setCreatedOn(new Timestamp(System.currentTimeMillis()));
|
||||
ps.setUploader(userAccount.getId());
|
||||
PatchSetImporter imp = new PatchSetImporter(db, repo, c, ps, true);
|
||||
imp.setTransaction(txn);
|
||||
try {
|
||||
@@ -575,7 +580,7 @@ class Receive extends AbstractGitCommand {
|
||||
|
||||
final ChangeMessage msg =
|
||||
new ChangeMessage(new ChangeMessage.Key(change.getId(), ChangeUtil
|
||||
.messageUUID(db)), me);
|
||||
.messageUUID(db)), me, ps.getCreatedOn());
|
||||
msg.setMessage("Uploaded patch set " + ps.getPatchSetId() + ".");
|
||||
db.changeMessages().insert(Collections.singleton(msg), txn);
|
||||
|
||||
|
||||
@@ -436,11 +436,16 @@ DELETE FROM patch_sets;
|
||||
INSERT INTO patch_sets
|
||||
(revision,
|
||||
change_id,
|
||||
patch_set_id) SELECT
|
||||
patch_set_id,
|
||||
created_on,
|
||||
uploader_account_id) SELECT
|
||||
r.revision_id,
|
||||
c.change_id,
|
||||
p.patchset_id
|
||||
p.patchset_id,
|
||||
p.created,
|
||||
a.account_id
|
||||
FROM gerrit1.patch_sets p
|
||||
JOIN accounts a ON a.preferred_email = p.owner
|
||||
JOIN gerrit1.changes c ON p.change_key = c.gae_key
|
||||
LEFT OUTER JOIN gerrit1.revisions r ON r.gae_key = p.revision_key;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user