Pass project to ChangeData so that it can load the change from notes
ChangeData currently loads the change directly from the database, but now when we support notedb it should load the change via the change notes factory. Loading the change via the change notes factory requires the project name in addition to the change ID, hence ChangeData must know it. The only caller of ChangeData that cannot provide the project name is HasDraftByLegacyPredicate. Due to this HasDraftByLegacyPredicate loads the changes on its own from the database for now. We may remove this deprecated predicate before migrating to notedb or find another solution later. When the change is now loaded from notedb its last modified timestamp is only precise to seconds, while when its loaded from the database it is precise to milliseconds. Due to this different changes got the same last modified timestamp when notedb was enabled and as result the GetRelatedIT#getRelatedReworkThenExtendInTheMiddleOfSeries test started to fail. Defining a 1s time clock step for this test fixes this issue. Change-Id: Iee0dce795766f543c996d75fde4067cb23a357dd Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -640,7 +640,8 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected PatchSet getPatchSet(PatchSet.Id psId) throws OrmException {
|
protected PatchSet getPatchSet(PatchSet.Id psId) throws OrmException {
|
||||||
return changeDataFactory.create(db, psId.getParentKey()).patchSet(psId);
|
return changeDataFactory.create(db, project, psId.getParentKey())
|
||||||
|
.patchSet(psId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IdentifiedUser user(TestAccount testAccount) {
|
protected IdentifiedUser user(TestAccount testAccount) {
|
||||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.server.change;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.gerrit.acceptance.GitUtil.pushHead;
|
import static com.google.gerrit.acceptance.GitUtil.pushHead;
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
@@ -33,17 +34,34 @@ import com.google.gerrit.server.edit.ChangeEditUtil;
|
|||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
|
import com.google.gerrit.testutil.TestTimeUtil;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GetRelatedIT extends AbstractDaemonTest {
|
public class GetRelatedIT extends AbstractDaemonTest {
|
||||||
|
private String systemTimeZone;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setTimeForTesting() {
|
||||||
|
systemTimeZone = System.setProperty("user.timezone", "US/Eastern");
|
||||||
|
TestTimeUtil.resetWithClockStep(1, SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void resetTime() {
|
||||||
|
TestTimeUtil.useSystemTime();
|
||||||
|
System.setProperty("user.timezone", systemTimeZone);
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ChangeEditUtil editUtil;
|
private ChangeEditUtil editUtil;
|
||||||
|
|
||||||
@@ -573,7 +591,8 @@ public class GetRelatedIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
// Pretend PS1,1 was pushed before the groups field was added.
|
// Pretend PS1,1 was pushed before the groups field was added.
|
||||||
clearGroups(psId1_1);
|
clearGroups(psId1_1);
|
||||||
indexer.index(changeDataFactory.create(db, psId1_1.getParentKey()));
|
indexer.index(
|
||||||
|
changeDataFactory.create(db, project, psId1_1.getParentKey()));
|
||||||
|
|
||||||
// PS1,1 has no groups, so disappeared from related changes.
|
// PS1,1 has no groups, so disappeared from related changes.
|
||||||
assertRelated(psId2_1);
|
assertRelated(psId2_1);
|
||||||
|
@@ -456,11 +456,9 @@ public class LuceneChangeIndex implements ChangeIndex {
|
|||||||
ChangeProtoField.CODEC.decode(cb.bytes, cb.offset, cb.length));
|
ChangeProtoField.CODEC.decode(cb.bytes, cb.offset, cb.length));
|
||||||
} else {
|
} else {
|
||||||
int id = doc.getField(idFieldName).numericValue().intValue();
|
int id = doc.getField(idFieldName).numericValue().intValue();
|
||||||
// TODO(ekempin): Pass project to changeDataFactory
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
Project.NameKey project =
|
Project.NameKey project =
|
||||||
new Project.NameKey(doc.getField(PROJECT.getName()).stringValue());
|
new Project.NameKey(doc.getField(PROJECT.getName()).stringValue());
|
||||||
cd = changeDataFactory.create(db.get(), new Change.Id(id));
|
cd = changeDataFactory.create(db.get(), project, new Change.Id(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields.contains(PATCH_SET_FIELD)) {
|
if (fields.contains(PATCH_SET_FIELD)) {
|
||||||
|
@@ -281,7 +281,7 @@ public class ChangeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RevertedSender cm = revertedSenderFactory.create(changeId);
|
RevertedSender cm = revertedSenderFactory.create(project, changeId);
|
||||||
cm.setFrom(user.get().getAccountId());
|
cm.setFrom(user.get().getAccountId());
|
||||||
cm.setChangeMessage(ins.getChangeMessage());
|
cm.setChangeMessage(ins.getChangeMessage());
|
||||||
cm.send();
|
cm.send();
|
||||||
|
@@ -162,7 +162,8 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
|||||||
@Override
|
@Override
|
||||||
public void postUpdate(Context ctx) throws OrmException {
|
public void postUpdate(Context ctx) throws OrmException {
|
||||||
try {
|
try {
|
||||||
ReplyToChangeSender cm = abandonedSenderFactory.create(change.getId());
|
ReplyToChangeSender cm =
|
||||||
|
abandonedSenderFactory.create(ctx.getProject(), change.getId());
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
cm.setFrom(account.getId());
|
cm.setFrom(account.getId());
|
||||||
}
|
}
|
||||||
|
@@ -361,8 +361,8 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
CreateChangeSender cm =
|
CreateChangeSender cm = createChangeSenderFactory
|
||||||
createChangeSenderFactory.create(change.getId());
|
.create(change.getProject(), change.getId());
|
||||||
cm.setFrom(change.getOwner());
|
cm.setFrom(change.getOwner());
|
||||||
cm.setPatchSet(patchSet, patchSetInfo);
|
cm.setPatchSet(patchSet, patchSetInfo);
|
||||||
cm.setNotify(notify);
|
cm.setNotify(notify);
|
||||||
|
@@ -231,7 +231,7 @@ public class ChangeJson {
|
|||||||
if (!has(CHECK)) {
|
if (!has(CHECK)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return checkOnly(changeDataFactory.create(db.get(), id));
|
return checkOnly(changeDataFactory.create(db.get(), project, id));
|
||||||
}
|
}
|
||||||
return format(changeDataFactory.create(db.get(), notes.getChange()));
|
return format(changeDataFactory.create(db.get(), notes.getChange()));
|
||||||
}
|
}
|
||||||
@@ -381,7 +381,7 @@ public class ChangeJson {
|
|||||||
// If any problems were fixed, the ChangeData needs to be reloaded.
|
// If any problems were fixed, the ChangeData needs to be reloaded.
|
||||||
for (ProblemInfo p : out.problems) {
|
for (ProblemInfo p : out.problems) {
|
||||||
if (p.status == ProblemInfo.Status.FIXED) {
|
if (p.status == ProblemInfo.Status.FIXED) {
|
||||||
cd = changeDataFactory.create(cd.db(), cd.getId());
|
cd = changeDataFactory.create(cd.db(), cd.getProject(), cd.getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -105,7 +105,8 @@ public class EmailReviewComments implements Runnable, RequestContext {
|
|||||||
RequestContext old = requestContext.setContext(this);
|
RequestContext old = requestContext.setContext(this);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
CommentSender cm = commentSenderFactory.create(notes.getChangeId());
|
CommentSender cm = commentSenderFactory.create(notes.getProjectName(),
|
||||||
|
notes.getChangeId());
|
||||||
cm.setFrom(authorId);
|
cm.setFrom(authorId);
|
||||||
cm.setPatchSet(patchSet,
|
cm.setPatchSet(patchSet,
|
||||||
patchSetInfoFactory.get(notes.getProjectName(), patchSet));
|
patchSetInfoFactory.get(notes.getProjectName(), patchSet));
|
||||||
|
@@ -259,7 +259,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
|||||||
if (sendMail) {
|
if (sendMail) {
|
||||||
try {
|
try {
|
||||||
ReplacePatchSetSender cm = replacePatchSetFactory.create(
|
ReplacePatchSetSender cm = replacePatchSetFactory.create(
|
||||||
change.getId());
|
ctx.getProject(), change.getId());
|
||||||
cm.setFrom(ctx.getUser().getAccountId());
|
cm.setFrom(ctx.getUser().getAccountId());
|
||||||
cm.setPatchSet(patchSet, patchSetInfo);
|
cm.setPatchSet(patchSet, patchSetInfo);
|
||||||
cm.setChangeMessage(changeMessage);
|
cm.setChangeMessage(changeMessage);
|
||||||
|
@@ -248,7 +248,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
|||||||
|
|
||||||
update.commit();
|
update.commit();
|
||||||
CheckedFuture<?, IOException> indexFuture =
|
CheckedFuture<?, IOException> indexFuture =
|
||||||
indexer.indexAsync(rsrc.getId());
|
indexer.indexAsync(rsrc.getProject(), rsrc.getId());
|
||||||
result.reviewers = Lists.newArrayListWithCapacity(added.size());
|
result.reviewers = Lists.newArrayListWithCapacity(added.size());
|
||||||
for (PatchSetApproval psa : added) {
|
for (PatchSetApproval psa : added) {
|
||||||
// New reviewers have value 0, don't bother normalizing.
|
// New reviewers have value 0, don't bother normalizing.
|
||||||
@@ -286,7 +286,8 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
|||||||
}
|
}
|
||||||
if (!toMail.isEmpty()) {
|
if (!toMail.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
AddReviewerSender cm = addReviewerSenderFactory.create(change.getId());
|
AddReviewerSender cm = addReviewerSenderFactory
|
||||||
|
.create(change.getProject(), change.getId());
|
||||||
cm.setFrom(userId);
|
cm.setFrom(userId);
|
||||||
cm.addReviewers(toMail);
|
cm.addReviewers(toMail);
|
||||||
cm.send();
|
cm.send();
|
||||||
|
@@ -245,7 +245,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
|||||||
|
|
||||||
private void sendCreateChange(Context ctx) throws EmailException {
|
private void sendCreateChange(Context ctx) throws EmailException {
|
||||||
CreateChangeSender cm =
|
CreateChangeSender cm =
|
||||||
createChangeSenderFactory.create(change.getId());
|
createChangeSenderFactory.create(ctx.getProject(), change.getId());
|
||||||
cm.setFrom(ctx.getUser().getAccountId());
|
cm.setFrom(ctx.getUser().getAccountId());
|
||||||
cm.setPatchSet(patchSet, patchSetInfo);
|
cm.setPatchSet(patchSet, patchSetInfo);
|
||||||
cm.addReviewers(recipients.getReviewers());
|
cm.addReviewers(recipients.getReviewers());
|
||||||
@@ -262,7 +262,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
|||||||
ctx.getWhen(), psId);
|
ctx.getWhen(), psId);
|
||||||
msg.setMessage("Uploaded patch set " + psId.get() + ".");
|
msg.setMessage("Uploaded patch set " + psId.get() + ".");
|
||||||
ReplacePatchSetSender cm =
|
ReplacePatchSetSender cm =
|
||||||
replacePatchSetFactory.create(change.getId());
|
replacePatchSetFactory.create(ctx.getProject(), change.getId());
|
||||||
cm.setFrom(accountId);
|
cm.setFrom(accountId);
|
||||||
cm.setPatchSet(patchSet, patchSetInfo);
|
cm.setPatchSet(patchSet, patchSetInfo);
|
||||||
cm.setChangeMessage(msg);
|
cm.setChangeMessage(msg);
|
||||||
|
@@ -150,7 +150,8 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
|||||||
@Override
|
@Override
|
||||||
public void postUpdate(Context ctx) throws OrmException {
|
public void postUpdate(Context ctx) throws OrmException {
|
||||||
try {
|
try {
|
||||||
ReplyToChangeSender cm = restoredSenderFactory.create(change.getId());
|
ReplyToChangeSender cm =
|
||||||
|
restoredSenderFactory.create(ctx.getProject(), change.getId());
|
||||||
cm.setFrom(caller.getAccountId());
|
cm.setFrom(caller.getAccountId());
|
||||||
cm.setChangeMessage(message);
|
cm.setChangeMessage(message);
|
||||||
cm.send();
|
cm.send();
|
||||||
|
@@ -615,7 +615,7 @@ public class BatchUpdate implements AutoCloseable {
|
|||||||
bmdu.commit();
|
bmdu.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indexFutures.add(indexer.indexAsync(id));
|
indexFutures.add(indexer.indexAsync(ctx.getProject(), id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.git;
|
|||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.mail.MergedSender;
|
import com.google.gerrit.server.mail.MergedSender;
|
||||||
@@ -39,7 +40,8 @@ public class EmailMerge implements Runnable, RequestContext {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(EmailMerge.class);
|
private static final Logger log = LoggerFactory.getLogger(EmailMerge.class);
|
||||||
|
|
||||||
public interface Factory {
|
public interface Factory {
|
||||||
EmailMerge create(Change.Id changeId, Account.Id submitter);
|
EmailMerge create(Project.NameKey project, Change.Id changeId,
|
||||||
|
Account.Id submitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ExecutorService sendEmailsExecutor;
|
private final ExecutorService sendEmailsExecutor;
|
||||||
@@ -47,6 +49,7 @@ public class EmailMerge implements Runnable, RequestContext {
|
|||||||
private final SchemaFactory<ReviewDb> schemaFactory;
|
private final SchemaFactory<ReviewDb> schemaFactory;
|
||||||
private final ThreadLocalRequestContext requestContext;
|
private final ThreadLocalRequestContext requestContext;
|
||||||
|
|
||||||
|
private final Project.NameKey project;
|
||||||
private final Change.Id changeId;
|
private final Change.Id changeId;
|
||||||
private final Account.Id submitter;
|
private final Account.Id submitter;
|
||||||
private ReviewDb db;
|
private ReviewDb db;
|
||||||
@@ -56,12 +59,14 @@ public class EmailMerge implements Runnable, RequestContext {
|
|||||||
MergedSender.Factory mergedSenderFactory,
|
MergedSender.Factory mergedSenderFactory,
|
||||||
SchemaFactory<ReviewDb> schemaFactory,
|
SchemaFactory<ReviewDb> schemaFactory,
|
||||||
ThreadLocalRequestContext requestContext,
|
ThreadLocalRequestContext requestContext,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
@Assisted Change.Id changeId,
|
@Assisted Change.Id changeId,
|
||||||
@Assisted @Nullable Account.Id submitter) {
|
@Assisted @Nullable Account.Id submitter) {
|
||||||
this.sendEmailsExecutor = executor;
|
this.sendEmailsExecutor = executor;
|
||||||
this.mergedSenderFactory = mergedSenderFactory;
|
this.mergedSenderFactory = mergedSenderFactory;
|
||||||
this.schemaFactory = schemaFactory;
|
this.schemaFactory = schemaFactory;
|
||||||
this.requestContext = requestContext;
|
this.requestContext = requestContext;
|
||||||
|
this.project = project;
|
||||||
this.changeId = changeId;
|
this.changeId = changeId;
|
||||||
this.submitter = submitter;
|
this.submitter = submitter;
|
||||||
}
|
}
|
||||||
@@ -74,7 +79,7 @@ public class EmailMerge implements Runnable, RequestContext {
|
|||||||
public void run() {
|
public void run() {
|
||||||
RequestContext old = requestContext.setContext(this);
|
RequestContext old = requestContext.setContext(this);
|
||||||
try {
|
try {
|
||||||
MergedSender cm = mergedSenderFactory.create(changeId);
|
MergedSender cm = mergedSenderFactory.create(project, changeId);
|
||||||
if (submitter != null) {
|
if (submitter != null) {
|
||||||
cm.setFrom(submitter);
|
cm.setFrom(submitter);
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,8 @@ public class MergeSuperSet {
|
|||||||
public ChangeSet completeChangeSet(ReviewDb db, Change change)
|
public ChangeSet completeChangeSet(ReviewDb db, Change change)
|
||||||
throws MissingObjectException, IncorrectObjectTypeException, IOException,
|
throws MissingObjectException, IncorrectObjectTypeException, IOException,
|
||||||
OrmException {
|
OrmException {
|
||||||
ChangeData cd = changeDataFactory.create(db, change.getId());
|
ChangeData cd =
|
||||||
|
changeDataFactory.create(db, change.getProject(), change.getId());
|
||||||
if (Submit.wholeTopicEnabled(cfg)) {
|
if (Submit.wholeTopicEnabled(cfg)) {
|
||||||
return completeChangeSetIncludingTopics(db, new ChangeSet(cd));
|
return completeChangeSetIncludingTopics(db, new ChangeSet(cd));
|
||||||
} else {
|
} else {
|
||||||
@@ -101,7 +102,7 @@ public class MergeSuperSet {
|
|||||||
try (Repository repo = repoManager.openRepository(project);
|
try (Repository repo = repoManager.openRepository(project);
|
||||||
RevWalk rw = CodeReviewCommit.newRevWalk(repo)) {
|
RevWalk rw = CodeReviewCommit.newRevWalk(repo)) {
|
||||||
for (Change.Id cId : pc.get(project)) {
|
for (Change.Id cId : pc.get(project)) {
|
||||||
ChangeData cd = changeDataFactory.create(db, cId);
|
ChangeData cd = changeDataFactory.create(db, project, cId);
|
||||||
|
|
||||||
SubmitTypeRecord str = cd.submitTypeRecord();
|
SubmitTypeRecord str = cd.submitTypeRecord();
|
||||||
if (!str.isOk()) {
|
if (!str.isOk()) {
|
||||||
|
@@ -2379,8 +2379,8 @@ public class ReceiveCommits {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
ReplacePatchSetSender cm =
|
ReplacePatchSetSender cm = replacePatchSetFactory
|
||||||
replacePatchSetFactory.create(change.getId());
|
.create(project.getNameKey(), change.getId());
|
||||||
cm.setFrom(me);
|
cm.setFrom(me);
|
||||||
cm.setPatchSet(newPatchSet, info);
|
cm.setPatchSet(newPatchSet, info);
|
||||||
cm.setChangeMessage(msg);
|
cm.setChangeMessage(msg);
|
||||||
@@ -2819,8 +2819,8 @@ public class ReceiveCommits {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
MergedSender cm =
|
MergedSender cm = mergedSenderFactory.create(project.getNameKey(),
|
||||||
mergedSenderFactory.create(ps.getId().getParentKey());
|
ps.getId().getParentKey());
|
||||||
cm.setFrom(user.getAccountId());
|
cm.setFrom(user.getAccountId());
|
||||||
cm.setPatchSet(ps, info);
|
cm.setPatchSet(ps, info);
|
||||||
cm.send();
|
cm.send();
|
||||||
|
@@ -481,7 +481,8 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
|
|||||||
// Assume the change must have been merged at this point, otherwise we would
|
// Assume the change must have been merged at this point, otherwise we would
|
||||||
// have failed fast in one of the other steps.
|
// have failed fast in one of the other steps.
|
||||||
try {
|
try {
|
||||||
args.mergedSenderFactory.create(getId(), submitter.getAccountId())
|
args.mergedSenderFactory
|
||||||
|
.create(ctx.getProject(), getId(), submitter.getAccountId())
|
||||||
.sendAsync();
|
.sendAsync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Cannot email merged notification for " + getId(), e);
|
log.error("Cannot email merged notification for " + getId(), e);
|
||||||
|
@@ -21,6 +21,7 @@ import com.google.common.util.concurrent.Futures;
|
|||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
@@ -128,9 +129,10 @@ public class ChangeIndexer {
|
|||||||
* @param id change to index.
|
* @param id change to index.
|
||||||
* @return future for the indexing task.
|
* @return future for the indexing task.
|
||||||
*/
|
*/
|
||||||
public CheckedFuture<?, IOException> indexAsync(Change.Id id) {
|
public CheckedFuture<?, IOException> indexAsync(Project.NameKey project,
|
||||||
|
Change.Id id) {
|
||||||
return executor != null
|
return executor != null
|
||||||
? submit(new IndexTask(id))
|
? submit(new IndexTask(project, id))
|
||||||
: Futures.<Object, IOException> immediateCheckedFuture(null);
|
: Futures.<Object, IOException> immediateCheckedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,10 +142,11 @@ public class ChangeIndexer {
|
|||||||
* @param ids changes to index.
|
* @param ids changes to index.
|
||||||
* @return future for completing indexing of all changes.
|
* @return future for completing indexing of all changes.
|
||||||
*/
|
*/
|
||||||
public CheckedFuture<?, IOException> indexAsync(Collection<Change.Id> ids) {
|
public CheckedFuture<?, IOException> indexAsync(Project.NameKey project,
|
||||||
|
Collection<Change.Id> ids) {
|
||||||
List<ListenableFuture<?>> futures = new ArrayList<>(ids.size());
|
List<ListenableFuture<?>> futures = new ArrayList<>(ids.size());
|
||||||
for (Change.Id id : ids) {
|
for (Change.Id id : ids) {
|
||||||
futures.add(indexAsync(id));
|
futures.add(indexAsync(project, id));
|
||||||
}
|
}
|
||||||
return allAsList(futures);
|
return allAsList(futures);
|
||||||
}
|
}
|
||||||
@@ -201,9 +204,11 @@ public class ChangeIndexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class IndexTask implements Callable<Void> {
|
private class IndexTask implements Callable<Void> {
|
||||||
|
private final Project.NameKey project;
|
||||||
private final Change.Id id;
|
private final Change.Id id;
|
||||||
|
|
||||||
private IndexTask(Change.Id id) {
|
private IndexTask(Project.NameKey project, Change.Id id) {
|
||||||
|
this.project = project;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,8 +242,8 @@ public class ChangeIndexer {
|
|||||||
};
|
};
|
||||||
RequestContext oldCtx = context.setContext(newCtx);
|
RequestContext oldCtx = context.setContext(newCtx);
|
||||||
try {
|
try {
|
||||||
ChangeData cd = changeDataFactory.create(
|
ChangeData cd = changeDataFactory
|
||||||
newCtx.getReviewDbProvider().get(), id);
|
.create(newCtx.getReviewDbProvider().get(), project, id);
|
||||||
index(cd);
|
index(cd);
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.mail;
|
|||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -26,13 +27,15 @@ public class AbandonedSender extends ReplyToChangeSender {
|
|||||||
public static interface Factory extends
|
public static interface Factory extends
|
||||||
ReplyToChangeSender.Factory<AbandonedSender> {
|
ReplyToChangeSender.Factory<AbandonedSender> {
|
||||||
@Override
|
@Override
|
||||||
AbandonedSender create(Change.Id change);
|
AbandonedSender create(Project.NameKey project, Change.Id change);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AbandonedSender(EmailArguments ea, @Assisted Change.Id id)
|
public AbandonedSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, "abandon", newChangeData(ea, id));
|
super(ea, "abandon", newChangeData(ea, project, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.mail;
|
|||||||
|
|
||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -23,13 +24,15 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
/** Asks a user to review a change. */
|
/** Asks a user to review a change. */
|
||||||
public class AddReviewerSender extends NewChangeSender {
|
public class AddReviewerSender extends NewChangeSender {
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
AddReviewerSender create(Change.Id id);
|
AddReviewerSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AddReviewerSender(EmailArguments ea, @Assisted Change.Id id)
|
public AddReviewerSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, newChangeData(ea, id));
|
super(ea, newChangeData(ea, project, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.client.ChangeMessage;
|
|||||||
import com.google.gerrit.reviewdb.client.Patch;
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSetInfo;
|
import com.google.gerrit.reviewdb.client.PatchSetInfo;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.mail.ProjectWatch.Watchers;
|
import com.google.gerrit.server.mail.ProjectWatch.Watchers;
|
||||||
import com.google.gerrit.server.patch.PatchList;
|
import com.google.gerrit.server.patch.PatchList;
|
||||||
@@ -56,8 +57,9 @@ import java.util.TreeSet;
|
|||||||
public abstract class ChangeEmail extends NotificationEmail {
|
public abstract class ChangeEmail extends NotificationEmail {
|
||||||
private static final Logger log = LoggerFactory.getLogger(ChangeEmail.class);
|
private static final Logger log = LoggerFactory.getLogger(ChangeEmail.class);
|
||||||
|
|
||||||
protected static ChangeData newChangeData(EmailArguments ea, Change.Id id) {
|
protected static ChangeData newChangeData(EmailArguments ea,
|
||||||
return ea.changeDataFactory.create(ea.db.get(), id);
|
Project.NameKey project, Change.Id id) {
|
||||||
|
return ea.changeDataFactory.create(ea.db.get(), project, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Change change;
|
protected final Change change;
|
||||||
|
@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.client.CommentRange;
|
|||||||
import com.google.gerrit.reviewdb.client.Patch;
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||||
import com.google.gerrit.server.patch.PatchFile;
|
import com.google.gerrit.server.patch.PatchFile;
|
||||||
import com.google.gerrit.server.patch.PatchList;
|
import com.google.gerrit.server.patch.PatchList;
|
||||||
@@ -52,7 +53,7 @@ public class CommentSender extends ReplyToChangeSender {
|
|||||||
.getLogger(CommentSender.class);
|
.getLogger(CommentSender.class);
|
||||||
|
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
CommentSender create(Change.Id id);
|
CommentSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PatchLineComment> inlineComments = Collections.emptyList();
|
private List<PatchLineComment> inlineComments = Collections.emptyList();
|
||||||
@@ -61,8 +62,9 @@ public class CommentSender extends ReplyToChangeSender {
|
|||||||
@Inject
|
@Inject
|
||||||
public CommentSender(EmailArguments ea,
|
public CommentSender(EmailArguments ea,
|
||||||
PatchLineCommentsUtil plcUtil,
|
PatchLineCommentsUtil plcUtil,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
@Assisted Change.Id id) throws OrmException {
|
@Assisted Change.Id id) throws OrmException {
|
||||||
super(ea, "comment", newChangeData(ea, id));
|
super(ea, "comment", newChangeData(ea, project, id));
|
||||||
this.plcUtil = plcUtil;
|
this.plcUtil = plcUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.common.errors.EmailException;
|
|||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.mail.ProjectWatch.Watchers;
|
import com.google.gerrit.server.mail.ProjectWatch.Watchers;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -33,13 +34,15 @@ public class CreateChangeSender extends NewChangeSender {
|
|||||||
LoggerFactory.getLogger(CreateChangeSender.class);
|
LoggerFactory.getLogger(CreateChangeSender.class);
|
||||||
|
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
CreateChangeSender create(Change.Id id);
|
CreateChangeSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CreateChangeSender(EmailArguments ea, @Assisted Change.Id id)
|
public CreateChangeSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, newChangeData(ea, id));
|
super(ea, newChangeData(ea, project, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.mail;
|
|||||||
|
|
||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -23,13 +24,15 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
/** Send notice about a change failing to merged. */
|
/** Send notice about a change failing to merged. */
|
||||||
public class MergeFailSender extends ReplyToChangeSender {
|
public class MergeFailSender extends ReplyToChangeSender {
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
MergeFailSender create(Change.Id id);
|
MergeFailSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MergeFailSender(EmailArguments ea, @Assisted Change.Id id)
|
public MergeFailSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, "merge-failed", newChangeData(ea, id));
|
super(ea, "merge-failed", newChangeData(ea, project, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.client.Account;
|
|||||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -31,15 +32,17 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
/** Send notice about a change successfully merged. */
|
/** Send notice about a change successfully merged. */
|
||||||
public class MergedSender extends ReplyToChangeSender {
|
public class MergedSender extends ReplyToChangeSender {
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
MergedSender create(Change.Id id);
|
MergedSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final LabelTypes labelTypes;
|
private final LabelTypes labelTypes;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MergedSender(EmailArguments ea, @Assisted Change.Id id)
|
public MergedSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, "merged", newChangeData(ea, id));
|
super(ea, "merged", newChangeData(ea, project, id));
|
||||||
labelTypes = changeData.changeControl().getLabelTypes();
|
labelTypes = changeData.changeControl().getLabelTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ import com.google.gerrit.common.errors.EmailException;
|
|||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -31,16 +32,18 @@ import java.util.Set;
|
|||||||
/** Send notice of new patch sets for reviewers. */
|
/** Send notice of new patch sets for reviewers. */
|
||||||
public class ReplacePatchSetSender extends ReplyToChangeSender {
|
public class ReplacePatchSetSender extends ReplyToChangeSender {
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
ReplacePatchSetSender create(Change.Id id);
|
ReplacePatchSetSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Set<Account.Id> reviewers = new HashSet<>();
|
private final Set<Account.Id> reviewers = new HashSet<>();
|
||||||
private final Set<Account.Id> extraCC = new HashSet<>();
|
private final Set<Account.Id> extraCC = new HashSet<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ReplacePatchSetSender(EmailArguments ea, @Assisted Change.Id id)
|
public ReplacePatchSetSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, "newpatchset", newChangeData(ea, id));
|
super(ea, "newpatchset", newChangeData(ea, project, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addReviewers(final Collection<Account.Id> cc) {
|
public void addReviewers(final Collection<Account.Id> cc) {
|
||||||
|
@@ -16,13 +16,14 @@ package com.google.gerrit.server.mail;
|
|||||||
|
|
||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
|
||||||
/** Alert a user to a reply to a change, usually commentary made during review. */
|
/** Alert a user to a reply to a change, usually commentary made during review. */
|
||||||
public abstract class ReplyToChangeSender extends ChangeEmail {
|
public abstract class ReplyToChangeSender extends ChangeEmail {
|
||||||
public static interface Factory<T extends ReplyToChangeSender> {
|
public static interface Factory<T extends ReplyToChangeSender> {
|
||||||
T create(Change.Id id);
|
T create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ReplyToChangeSender(EmailArguments ea, String mc, ChangeData cd)
|
protected ReplyToChangeSender(EmailArguments ea, String mc, ChangeData cd)
|
||||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.mail;
|
|||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -26,13 +27,15 @@ public class RestoredSender extends ReplyToChangeSender {
|
|||||||
public static interface Factory extends
|
public static interface Factory extends
|
||||||
ReplyToChangeSender.Factory<RestoredSender> {
|
ReplyToChangeSender.Factory<RestoredSender> {
|
||||||
@Override
|
@Override
|
||||||
RestoredSender create(Change.Id id);
|
RestoredSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestoredSender(EmailArguments ea, @Assisted Change.Id id)
|
public RestoredSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, "restore", newChangeData(ea, id));
|
super(ea, "restore", newChangeData(ea, project, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.mail;
|
|||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
@@ -24,13 +25,15 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
/** Send notice about a change being reverted. */
|
/** Send notice about a change being reverted. */
|
||||||
public class RevertedSender extends ReplyToChangeSender {
|
public class RevertedSender extends ReplyToChangeSender {
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
RevertedSender create(Change.Id id);
|
RevertedSender create(Project.NameKey project, Change.Id id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RevertedSender(EmailArguments ea, @Assisted Change.Id id)
|
public RevertedSender(EmailArguments ea,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
|
@Assisted Change.Id id)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, "revert", newChangeData(ea, id));
|
super(ea, "revert", newChangeData(ea, project, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -33,6 +33,7 @@ import com.google.gerrit.reviewdb.client.Patch;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.client.RefNames;
|
import com.google.gerrit.reviewdb.client.RefNames;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.ApprovalsUtil;
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
@@ -269,7 +270,7 @@ public class ChangeData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface Factory {
|
public interface Factory {
|
||||||
ChangeData create(ReviewDb db, Change.Id id);
|
ChangeData create(ReviewDb db, Project.NameKey project, Change.Id id);
|
||||||
ChangeData create(ReviewDb db, Change c);
|
ChangeData create(ReviewDb db, Change c);
|
||||||
ChangeData create(ReviewDb db, ChangeControl c);
|
ChangeData create(ReviewDb db, ChangeControl c);
|
||||||
}
|
}
|
||||||
@@ -283,9 +284,10 @@ public class ChangeData {
|
|||||||
* @param id change ID
|
* @param id change ID
|
||||||
* @return instance for testing.
|
* @return instance for testing.
|
||||||
*/
|
*/
|
||||||
public static ChangeData createForTest(Change.Id id, int currentPatchSetId) {
|
public static ChangeData createForTest(Project.NameKey project, Change.Id id,
|
||||||
|
int currentPatchSetId) {
|
||||||
ChangeData cd = new ChangeData(null, null, null, null, null, null, null,
|
ChangeData cd = new ChangeData(null, null, null, null, null, null, null,
|
||||||
null, null, null, null, null, null, null, id);
|
null, null, null, null, null, null, null, project, id);
|
||||||
cd.currentPatchSet = new PatchSet(new PatchSet.Id(id, currentPatchSetId));
|
cd.currentPatchSet = new PatchSet(new PatchSet.Id(id, currentPatchSetId));
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
@@ -305,6 +307,7 @@ public class ChangeData {
|
|||||||
private final NotesMigration notesMigration;
|
private final NotesMigration notesMigration;
|
||||||
private final MergeabilityCache mergeabilityCache;
|
private final MergeabilityCache mergeabilityCache;
|
||||||
private final Change.Id legacyId;
|
private final Change.Id legacyId;
|
||||||
|
private final Project.NameKey project;
|
||||||
private ChangeDataSource returnedBySource;
|
private ChangeDataSource returnedBySource;
|
||||||
private Change change;
|
private Change change;
|
||||||
private ChangeNotes notes;
|
private ChangeNotes notes;
|
||||||
@@ -345,6 +348,7 @@ public class ChangeData {
|
|||||||
NotesMigration notesMigration,
|
NotesMigration notesMigration,
|
||||||
MergeabilityCache mergeabilityCache,
|
MergeabilityCache mergeabilityCache,
|
||||||
@Assisted ReviewDb db,
|
@Assisted ReviewDb db,
|
||||||
|
@Assisted Project.NameKey project,
|
||||||
@Assisted Change.Id id) {
|
@Assisted Change.Id id) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.repoManager = repoManager;
|
this.repoManager = repoManager;
|
||||||
@@ -360,7 +364,8 @@ public class ChangeData {
|
|||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.notesMigration = notesMigration;
|
this.notesMigration = notesMigration;
|
||||||
this.mergeabilityCache = mergeabilityCache;
|
this.mergeabilityCache = mergeabilityCache;
|
||||||
legacyId = id;
|
this.project = project;
|
||||||
|
this.legacyId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
@@ -396,6 +401,7 @@ public class ChangeData {
|
|||||||
this.mergeabilityCache = mergeabilityCache;
|
this.mergeabilityCache = mergeabilityCache;
|
||||||
legacyId = c.getId();
|
legacyId = c.getId();
|
||||||
change = c;
|
change = c;
|
||||||
|
project = c.getProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
@@ -433,6 +439,7 @@ public class ChangeData {
|
|||||||
change = c.getChange();
|
change = c.getChange();
|
||||||
changeControl = c;
|
changeControl = c;
|
||||||
notes = c.getNotes();
|
notes = c.getNotes();
|
||||||
|
project = notes.getProjectName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReviewDb db() {
|
public ReviewDb db() {
|
||||||
@@ -536,6 +543,10 @@ public class ChangeData {
|
|||||||
return legacyId;
|
return legacyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Project.NameKey getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
boolean fastIsVisibleTo(CurrentUser user) {
|
boolean fastIsVisibleTo(CurrentUser user) {
|
||||||
return visibleTo == user;
|
return visibleTo == user;
|
||||||
}
|
}
|
||||||
@@ -591,14 +602,17 @@ public class ChangeData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Change reloadChange() throws OrmException {
|
public Change reloadChange() throws OrmException {
|
||||||
change = db.changes().get(legacyId);
|
notes = notesFactory.create(db, project, legacyId);
|
||||||
|
change = notes.getChange();
|
||||||
|
if (change == null) {
|
||||||
|
throw new OrmException("Unable to load change " + legacyId);
|
||||||
|
}
|
||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeNotes notes() throws OrmException {
|
public ChangeNotes notes() throws OrmException {
|
||||||
if (notes == null) {
|
if (notes == null) {
|
||||||
Change c = change();
|
notes = notesFactory.create(db, project, legacyId);
|
||||||
notes = notesFactory.create(db, c.getProject(), c.getId());
|
|
||||||
}
|
}
|
||||||
return notes;
|
return notes;
|
||||||
}
|
}
|
||||||
@@ -681,7 +695,7 @@ public class ChangeData {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String sha1 = ps.getRevision().get();
|
String sha1 = ps.getRevision().get();
|
||||||
try (Repository repo = repoManager.openRepository(change().getProject());
|
try (Repository repo = repoManager.openRepository(project);
|
||||||
RevWalk walk = new RevWalk(repo)) {
|
RevWalk walk = new RevWalk(repo)) {
|
||||||
RevCommit c = walk.parseCommit(ObjectId.fromString(sha1));
|
RevCommit c = walk.parseCommit(ObjectId.fromString(sha1));
|
||||||
commitMessage = c.getFullMessage();
|
commitMessage = c.getFullMessage();
|
||||||
@@ -790,7 +804,7 @@ public class ChangeData {
|
|||||||
if (ps == null || !changeControl().isPatchVisible(ps, db)) {
|
if (ps == null || !changeControl().isPatchVisible(ps, db)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try (Repository repo = repoManager.openRepository(c.getProject())) {
|
try (Repository repo = repoManager.openRepository(project)) {
|
||||||
Ref ref = repo.getRefDatabase().exactRef(c.getDest().get());
|
Ref ref = repo.getRefDatabase().exactRef(c.getDest().get());
|
||||||
SubmitTypeRecord str = submitTypeRecord();
|
SubmitTypeRecord str = submitTypeRecord();
|
||||||
if (!str.isOk()) {
|
if (!str.isOk()) {
|
||||||
@@ -799,7 +813,7 @@ public class ChangeData {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String mergeStrategy = mergeUtilFactory
|
String mergeStrategy = mergeUtilFactory
|
||||||
.create(projectCache.get(c.getProject()))
|
.create(projectCache.get(project))
|
||||||
.mergeStrategyName();
|
.mergeStrategyName();
|
||||||
mergeable = mergeabilityCache.get(
|
mergeable = mergeabilityCache.get(
|
||||||
ObjectId.fromString(ps.getRevision().get()),
|
ObjectId.fromString(ps.getRevision().get()),
|
||||||
@@ -820,7 +834,7 @@ public class ChangeData {
|
|||||||
}
|
}
|
||||||
editsByUser = new HashSet<>();
|
editsByUser = new HashSet<>();
|
||||||
Change.Id id = change.getId();
|
Change.Id id = change.getId();
|
||||||
try (Repository repo = repoManager.openRepository(change.getProject())) {
|
try (Repository repo = repoManager.openRepository(project)) {
|
||||||
for (String ref
|
for (String ref
|
||||||
: repo.getRefDatabase().getRefs(RefNames.REFS_USERS).keySet()) {
|
: repo.getRefDatabase().getRefs(RefNames.REFS_USERS).keySet()) {
|
||||||
if (Change.Id.fromEditRefPart(ref).equals(id)) {
|
if (Change.Id.fromEditRefPart(ref).equals(id)) {
|
||||||
|
@@ -57,8 +57,10 @@ class HasDraftByLegacyPredicate extends OperatorPredicate<ChangeData> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<ChangeData> r = new ArrayList<>(ids.size());
|
List<ChangeData> r = new ArrayList<>(ids.size());
|
||||||
for (Change.Id id : ids) {
|
// TODO Don't load the changes directly from the database, but provide
|
||||||
r.add(args.changeDataFactory.create(args.db.get(), id));
|
// project name + change ID to changeDataFactory, or delete this predicate.
|
||||||
|
for (Change c : args.db.get().changes().get(ids)) {
|
||||||
|
r.add(args.changeDataFactory.create(args.db.get(), c));
|
||||||
}
|
}
|
||||||
return new ListResultSet<>(r);
|
return new ListResultSet<>(r);
|
||||||
}
|
}
|
||||||
|
@@ -355,7 +355,7 @@ public class WalkSorterTest {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
Project.NameKey project = tr.getRepository().getDescription().getProject();
|
Project.NameKey project = tr.getRepository().getDescription().getProject();
|
||||||
Change c = TestChanges.newChange(project, userId);
|
Change c = TestChanges.newChange(project, userId);
|
||||||
ChangeData cd = ChangeData.createForTest(c.getId(), 1);
|
ChangeData cd = ChangeData.createForTest(project, c.getId(), 1);
|
||||||
cd.setChange(c);
|
cd.setChange(c);
|
||||||
cd.currentPatchSet().setRevision(new RevId(id.name()));
|
cd.currentPatchSet().setRevision(new RevId(id.name()));
|
||||||
cd.setPatchSets(ImmutableList.of(cd.currentPatchSet()));
|
cd.setPatchSets(ImmutableList.of(cd.currentPatchSet()));
|
||||||
|
@@ -28,9 +28,9 @@ import org.junit.Test;
|
|||||||
public class ChangeDataTest {
|
public class ChangeDataTest {
|
||||||
@Test
|
@Test
|
||||||
public void setPatchSetsClearsCurrentPatchSet() throws Exception {
|
public void setPatchSetsClearsCurrentPatchSet() throws Exception {
|
||||||
ChangeData cd = ChangeData.createForTest(new Change.Id(1), 1);
|
Project.NameKey project = new Project.NameKey("project");
|
||||||
cd.setChange(TestChanges.newChange(
|
ChangeData cd = ChangeData.createForTest(project, new Change.Id(1), 1);
|
||||||
new Project.NameKey("project"), new Account.Id(1000)));
|
cd.setChange(TestChanges.newChange(project, new Account.Id(1000)));
|
||||||
PatchSet curr1 = cd.currentPatchSet();
|
PatchSet curr1 = cd.currentPatchSet();
|
||||||
int currId = curr1.getId().get();
|
int currId = curr1.getId().get();
|
||||||
PatchSet ps1 = new PatchSet(new PatchSet.Id(cd.getId(), currId + 1));
|
PatchSet ps1 = new PatchSet(new PatchSet.Id(cd.getId(), currId + 1));
|
||||||
|
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -84,7 +85,8 @@ public class RegexPathPredicateTest {
|
|||||||
|
|
||||||
private static ChangeData change(String... files) throws OrmException {
|
private static ChangeData change(String... files) throws OrmException {
|
||||||
Arrays.sort(files);
|
Arrays.sort(files);
|
||||||
ChangeData cd = ChangeData.createForTest(new Change.Id(1), 1);
|
ChangeData cd = ChangeData.createForTest(new Project.NameKey("project"),
|
||||||
|
new Change.Id(1), 1);
|
||||||
cd.setCurrentFilePaths(Arrays.asList(files));
|
cd.setCurrentFilePaths(Arrays.asList(files));
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user