Pass only ref name into ChangeInserter, not ref control
ChangeInserter only needs the ref control when validation is done and it can just instantiate it for this purpose. The project and the user are provided by the Context and a provided ref control may have been created for another project or user. By not passing in the ref control we avoid this possible inconsistency. Also remove the getProject() and getUser() methods from ChangeInserter. They were only used by tests and were needed only because the API required to pass in the project and user twice, once through ref control to the ChangeInserter and once to the BatchUpdate. Change-Id: I2c4faf27e3c1183a474fecfa06dbbbc14a3c143f Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -21,7 +21,7 @@ import com.google.gerrit.common.data.ProjectAccess;
|
|||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
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.server.IdentifiedUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
import com.google.gerrit.server.account.GroupBackend;
|
||||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||||
@@ -54,7 +54,6 @@ class ChangeProjectAccess extends ProjectAccessHandler<ProjectAccess> {
|
|||||||
|
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
private final GitReferenceUpdated gitRefUpdated;
|
private final GitReferenceUpdated gitRefUpdated;
|
||||||
private final IdentifiedUser user;
|
|
||||||
private final ProjectAccessFactory.Factory projectAccessFactory;
|
private final ProjectAccessFactory.Factory projectAccessFactory;
|
||||||
private final ProjectCache projectCache;
|
private final ProjectCache projectCache;
|
||||||
|
|
||||||
@@ -67,7 +66,6 @@ class ChangeProjectAccess extends ProjectAccessHandler<ProjectAccess> {
|
|||||||
Provider<SetParent> setParent,
|
Provider<SetParent> setParent,
|
||||||
ChangeHooks hooks,
|
ChangeHooks hooks,
|
||||||
GitReferenceUpdated gitRefUpdated,
|
GitReferenceUpdated gitRefUpdated,
|
||||||
IdentifiedUser user,
|
|
||||||
@Assisted("projectName") Project.NameKey projectName,
|
@Assisted("projectName") Project.NameKey projectName,
|
||||||
@Nullable @Assisted ObjectId base,
|
@Nullable @Assisted ObjectId base,
|
||||||
@Assisted List<AccessSection> sectionList,
|
@Assisted List<AccessSection> sectionList,
|
||||||
@@ -80,11 +78,10 @@ class ChangeProjectAccess extends ProjectAccessHandler<ProjectAccess> {
|
|||||||
this.projectCache = projectCache;
|
this.projectCache = projectCache;
|
||||||
this.hooks = hooks;
|
this.hooks = hooks;
|
||||||
this.gitRefUpdated = gitRefUpdated;
|
this.gitRefUpdated = gitRefUpdated;
|
||||||
this.user = user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ProjectAccess updateProjectConfig(ProjectControl ctl,
|
protected ProjectAccess updateProjectConfig(CurrentUser user,
|
||||||
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
|
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
|
||||||
throws IOException, NoSuchProjectException, ConfigInvalidException {
|
throws IOException, NoSuchProjectException, ConfigInvalidException {
|
||||||
RevCommit commit = config.commit(md);
|
RevCommit commit = config.commit(md);
|
||||||
@@ -93,7 +90,7 @@ class ChangeProjectAccess extends ProjectAccessHandler<ProjectAccess> {
|
|||||||
base, commit.getId());
|
base, commit.getId());
|
||||||
hooks.doRefUpdatedHook(
|
hooks.doRefUpdatedHook(
|
||||||
new Branch.NameKey(config.getProject().getNameKey(), RefNames.REFS_CONFIG),
|
new Branch.NameKey(config.getProject().getNameKey(), RefNames.REFS_CONFIG),
|
||||||
base, commit.getId(), user.getAccount());
|
base, commit.getId(), user.asIdentifiedUser().getAccount());
|
||||||
|
|
||||||
projectCache.evict(config.getProject());
|
projectCache.evict(config.getProject());
|
||||||
return projectAccessFactory.create(projectName).call();
|
return projectAccessFactory.create(projectName).call();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
|||||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||||
import com.google.gerrit.httpd.rpc.Handler;
|
import com.google.gerrit.httpd.rpc.Handler;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
import com.google.gerrit.server.account.GroupBackend;
|
||||||
import com.google.gerrit.server.account.GroupBackends;
|
import com.google.gerrit.server.account.GroupBackends;
|
||||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||||
@@ -155,14 +156,14 @@ public abstract class ProjectAccessHandler<T> extends Handler<T> {
|
|||||||
md.setMessage("Modify access rules\n");
|
md.setMessage("Modify access rules\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateProjectConfig(projectControl, config, md,
|
return updateProjectConfig(projectControl.getUser(), config, md,
|
||||||
parentProjectUpdate);
|
parentProjectUpdate);
|
||||||
} catch (RepositoryNotFoundException notFound) {
|
} catch (RepositoryNotFoundException notFound) {
|
||||||
throw new NoSuchProjectException(projectName);
|
throw new NoSuchProjectException(projectName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract T updateProjectConfig(ProjectControl ctl,
|
protected abstract T updateProjectConfig(CurrentUser user,
|
||||||
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
|
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
|
||||||
throws IOException, NoSuchProjectException, ConfigInvalidException,
|
throws IOException, NoSuchProjectException, ConfigInvalidException,
|
||||||
OrmException;
|
OrmException;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
|||||||
import com.google.gerrit.reviewdb.client.Project;
|
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.CurrentUser;
|
||||||
import com.google.gerrit.server.Sequences;
|
import com.google.gerrit.server.Sequences;
|
||||||
import com.google.gerrit.server.account.GroupBackend;
|
import com.google.gerrit.server.account.GroupBackend;
|
||||||
import com.google.gerrit.server.change.ChangeInserter;
|
import com.google.gerrit.server.change.ChangeInserter;
|
||||||
@@ -105,7 +106,7 @@ public class ReviewProjectAccess extends ProjectAccessHandler<Change.Id> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Change.Id updateProjectConfig(ProjectControl ctl,
|
protected Change.Id updateProjectConfig(CurrentUser user,
|
||||||
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
|
ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
|
||||||
throws IOException, OrmException {
|
throws IOException, OrmException {
|
||||||
md.setInsertChangeId(true);
|
md.setInsertChangeId(true);
|
||||||
@@ -120,12 +121,11 @@ public class ReviewProjectAccess extends ProjectAccessHandler<Change.Id> {
|
|||||||
try (RevWalk rw = new RevWalk(md.getRepository());
|
try (RevWalk rw = new RevWalk(md.getRepository());
|
||||||
ObjectInserter objInserter = md.getRepository().newObjectInserter();
|
ObjectInserter objInserter = md.getRepository().newObjectInserter();
|
||||||
BatchUpdate bu = updateFactory.create(
|
BatchUpdate bu = updateFactory.create(
|
||||||
db, config.getProject().getNameKey(), ctl.getUser(),
|
db, config.getProject().getNameKey(), user,
|
||||||
TimeUtil.nowTs())) {
|
TimeUtil.nowTs())) {
|
||||||
bu.setRepository(md.getRepository(), rw, objInserter);
|
bu.setRepository(md.getRepository(), rw, objInserter);
|
||||||
bu.insertChange(
|
bu.insertChange(
|
||||||
changeInserterFactory.create(
|
changeInserterFactory.create(changeId, commit, RefNames.REFS_CONFIG)
|
||||||
ctl.controlForRef(RefNames.REFS_CONFIG), changeId, commit)
|
|
||||||
.setValidatePolicy(CommitValidators.Policy.NONE)
|
.setValidatePolicy(CommitValidators.Policy.NONE)
|
||||||
.setUpdateRef(false)); // Created by commitToNewRef.
|
.setUpdateRef(false)); // Created by commitToNewRef.
|
||||||
bu.execute();
|
bu.execute();
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import com.google.gerrit.server.mail.RevertedSender;
|
|||||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||||
import com.google.gerrit.server.project.RefControl;
|
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||||
import com.google.gerrit.server.util.IdGenerator;
|
import com.google.gerrit.server.util.IdGenerator;
|
||||||
@@ -252,9 +251,8 @@ public class ChangeUtil {
|
|||||||
oi.flush();
|
oi.flush();
|
||||||
revertCommit = revWalk.parseCommit(id);
|
revertCommit = revWalk.parseCommit(id);
|
||||||
|
|
||||||
RefControl refControl = ctl.getRefControl();
|
|
||||||
ins = changeInserterFactory.create(
|
ins = changeInserterFactory.create(
|
||||||
refControl, changeId, revertCommit)
|
changeId, revertCommit, ctl.getChange().getDest().get())
|
||||||
.setValidatePolicy(CommitValidators.Policy.GERRIT)
|
.setValidatePolicy(CommitValidators.Policy.GERRIT)
|
||||||
.setTopic(changeToRevert.getTopic());
|
.setTopic(changeToRevert.getTopic());
|
||||||
|
|
||||||
@@ -274,7 +272,7 @@ public class ChangeUtil {
|
|||||||
|
|
||||||
ins.setMessage("Uploaded patch set 1.");
|
ins.setMessage("Uploaded patch set 1.");
|
||||||
try (BatchUpdate bu = updateFactory.create(
|
try (BatchUpdate bu = updateFactory.create(
|
||||||
db.get(), project, refControl.getUser(),
|
db.get(), project, ctl.getUser(),
|
||||||
TimeUtil.nowTs())) {
|
TimeUtil.nowTs())) {
|
||||||
bu.setRepository(git, revWalk, oi);
|
bu.setRepository(git, revWalk, oi);
|
||||||
bu.insertChange(ins);
|
bu.insertChange(ins);
|
||||||
|
|||||||
@@ -29,13 +29,11 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
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.reviewdb.client.RevId;
|
import com.google.gerrit.reviewdb.client.RevId;
|
||||||
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;
|
||||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
|
||||||
import com.google.gerrit.server.events.CommitReceivedEvent;
|
import com.google.gerrit.server.events.CommitReceivedEvent;
|
||||||
import com.google.gerrit.server.git.BanCommit;
|
import com.google.gerrit.server.git.BanCommit;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
@@ -50,6 +48,8 @@ import com.google.gerrit.server.mail.CreateChangeSender;
|
|||||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.project.RefControl;
|
import com.google.gerrit.server.project.RefControl;
|
||||||
import com.google.gerrit.server.ssh.NoSshInfo;
|
import com.google.gerrit.server.ssh.NoSshInfo;
|
||||||
import com.google.gerrit.server.util.RequestScopePropagator;
|
import com.google.gerrit.server.util.RequestScopePropagator;
|
||||||
@@ -73,12 +73,13 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
ChangeInserter create(RefControl ctl, Change.Id cid, RevCommit rc);
|
ChangeInserter create(Change.Id cid, RevCommit rc, String refName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Logger log =
|
private static final Logger log =
|
||||||
LoggerFactory.getLogger(ChangeInserter.class);
|
LoggerFactory.getLogger(ChangeInserter.class);
|
||||||
|
|
||||||
|
private final ProjectControl.GenericFactory projectControlFactory;
|
||||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
private final ApprovalsUtil approvalsUtil;
|
private final ApprovalsUtil approvalsUtil;
|
||||||
@@ -87,11 +88,10 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
private final WorkQueue workQueue;
|
private final WorkQueue workQueue;
|
||||||
private final CommitValidators.Factory commitValidatorsFactory;
|
private final CommitValidators.Factory commitValidatorsFactory;
|
||||||
|
|
||||||
private final RefControl refControl;
|
|
||||||
private final IdentifiedUser user;
|
|
||||||
private final PatchSet patchSet;
|
private final PatchSet patchSet;
|
||||||
private final Change.Id changeId;
|
private final Change.Id changeId;
|
||||||
private final RevCommit commit;
|
private final RevCommit commit;
|
||||||
|
private final String refName;
|
||||||
|
|
||||||
// Fields exposed as setters.
|
// Fields exposed as setters.
|
||||||
private Change.Status status;
|
private Change.Status status;
|
||||||
@@ -113,16 +113,18 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
private PatchSetInfo patchSetInfo;
|
private PatchSetInfo patchSetInfo;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ChangeInserter(PatchSetInfoFactory patchSetInfoFactory,
|
ChangeInserter(ProjectControl.GenericFactory projectControlFactory,
|
||||||
|
PatchSetInfoFactory patchSetInfoFactory,
|
||||||
ChangeHooks hooks,
|
ChangeHooks hooks,
|
||||||
ApprovalsUtil approvalsUtil,
|
ApprovalsUtil approvalsUtil,
|
||||||
ChangeMessagesUtil cmUtil,
|
ChangeMessagesUtil cmUtil,
|
||||||
CreateChangeSender.Factory createChangeSenderFactory,
|
CreateChangeSender.Factory createChangeSenderFactory,
|
||||||
WorkQueue workQueue,
|
WorkQueue workQueue,
|
||||||
CommitValidators.Factory commitValidatorsFactory,
|
CommitValidators.Factory commitValidatorsFactory,
|
||||||
@Assisted RefControl refControl,
|
|
||||||
@Assisted Change.Id changeId,
|
@Assisted Change.Id changeId,
|
||||||
@Assisted RevCommit commit) {
|
@Assisted RevCommit commit,
|
||||||
|
@Assisted String refName) {
|
||||||
|
this.projectControlFactory = projectControlFactory;
|
||||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||||
this.hooks = hooks;
|
this.hooks = hooks;
|
||||||
this.approvalsUtil = approvalsUtil;
|
this.approvalsUtil = approvalsUtil;
|
||||||
@@ -131,9 +133,9 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
this.workQueue = workQueue;
|
this.workQueue = workQueue;
|
||||||
this.commitValidatorsFactory = commitValidatorsFactory;
|
this.commitValidatorsFactory = commitValidatorsFactory;
|
||||||
|
|
||||||
this.refControl = refControl;
|
|
||||||
this.changeId = changeId;
|
this.changeId = changeId;
|
||||||
this.commit = commit;
|
this.commit = commit;
|
||||||
|
this.refName = refName;
|
||||||
this.reviewers = Collections.emptySet();
|
this.reviewers = Collections.emptySet();
|
||||||
this.extraCC = Collections.emptySet();
|
this.extraCC = Collections.emptySet();
|
||||||
this.approvals = Collections.emptyMap();
|
this.approvals = Collections.emptyMap();
|
||||||
@@ -141,7 +143,6 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
this.sendMail = true;
|
this.sendMail = true;
|
||||||
this.updateRef = true;
|
this.updateRef = true;
|
||||||
|
|
||||||
user = refControl.getUser().asIdentifiedUser();
|
|
||||||
patchSet =
|
patchSet =
|
||||||
new PatchSet(new PatchSet.Id(changeId, INITIAL_PATCH_SET_ID));
|
new PatchSet(new PatchSet.Id(changeId, INITIAL_PATCH_SET_ID));
|
||||||
patchSet.setRevision(new RevId(commit.name()));
|
patchSet.setRevision(new RevId(commit.name()));
|
||||||
@@ -153,9 +154,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
getChangeKey(commit),
|
getChangeKey(commit),
|
||||||
changeId,
|
changeId,
|
||||||
ctx.getUser().getAccountId(),
|
ctx.getUser().getAccountId(),
|
||||||
new Branch.NameKey(
|
new Branch.NameKey(ctx.getProject(), refName),
|
||||||
refControl.getProjectControl().getProject().getNameKey(),
|
|
||||||
refControl.getRefName()),
|
|
||||||
ctx.getWhen());
|
ctx.getWhen());
|
||||||
change.setStatus(MoreObjects.firstNonNull(status, Change.Status.NEW));
|
change.setStatus(MoreObjects.firstNonNull(status, Change.Status.NEW));
|
||||||
change.setTopic(topic);
|
change.setTopic(topic);
|
||||||
@@ -183,14 +182,6 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentifiedUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Project.NameKey getProject() {
|
|
||||||
return refControl.getProjectControl().getProject().getNameKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChangeInserter setTopic(String topic) {
|
public ChangeInserter setTopic(String topic) {
|
||||||
checkState(change == null, "setTopic(String) only valid before creating change");
|
checkState(change == null, "setTopic(String) only valid before creating change");
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
@@ -323,7 +314,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
if (message != null) {
|
if (message != null) {
|
||||||
changeMessage =
|
changeMessage =
|
||||||
new ChangeMessage(new ChangeMessage.Key(change.getId(),
|
new ChangeMessage(new ChangeMessage.Key(change.getId(),
|
||||||
ChangeUtil.messageUUID(db)), user.getAccountId(),
|
ChangeUtil.messageUUID(db)), ctx.getUser().getAccountId(),
|
||||||
patchSet.getCreatedOn(), patchSet.getId());
|
patchSet.getCreatedOn(), patchSet.getId());
|
||||||
changeMessage.setMessage(message);
|
changeMessage.setMessage(message);
|
||||||
cmUtil.addChangeMessage(db, update, changeMessage);
|
cmUtil.addChangeMessage(db, update, changeMessage);
|
||||||
@@ -365,8 +356,9 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
ReviewDb db = ctx.getDb();
|
ReviewDb db = ctx.getDb();
|
||||||
hooks.doPatchsetCreatedHook(change, patchSet, db);
|
hooks.doPatchsetCreatedHook(change, patchSet, db);
|
||||||
if (approvals != null && !approvals.isEmpty()) {
|
if (approvals != null && !approvals.isEmpty()) {
|
||||||
hooks.doCommentAddedHook(
|
hooks.doCommentAddedHook(change,
|
||||||
change, user.getAccount(), patchSet, null, approvals, db);
|
ctx.getUser().asIdentifiedUser().getAccount(), patchSet, null,
|
||||||
|
approvals, db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,21 +368,24 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
if (validatePolicy == CommitValidators.Policy.NONE) {
|
if (validatePolicy == CommitValidators.Policy.NONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CommitValidators cv = commitValidatorsFactory.create(
|
|
||||||
refControl, new NoSshInfo(), ctx.getRepository());
|
|
||||||
|
|
||||||
String refName = patchSet.getId().toRefName();
|
|
||||||
CommitReceivedEvent event = new CommitReceivedEvent(
|
|
||||||
new ReceiveCommand(
|
|
||||||
ObjectId.zeroId(),
|
|
||||||
commit.getId(),
|
|
||||||
refName),
|
|
||||||
refControl.getProjectControl().getProject(),
|
|
||||||
change.getDest().get(),
|
|
||||||
commit,
|
|
||||||
user);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
RefControl refControl = projectControlFactory
|
||||||
|
.controlFor(ctx.getProject(), ctx.getUser()).controlForRef(refName);
|
||||||
|
CommitValidators cv = commitValidatorsFactory.create(
|
||||||
|
refControl, new NoSshInfo(), ctx.getRepository());
|
||||||
|
|
||||||
|
String refName = patchSet.getId().toRefName();
|
||||||
|
CommitReceivedEvent event = new CommitReceivedEvent(
|
||||||
|
new ReceiveCommand(
|
||||||
|
ObjectId.zeroId(),
|
||||||
|
commit.getId(),
|
||||||
|
refName),
|
||||||
|
refControl.getProjectControl().getProject(),
|
||||||
|
change.getDest().get(),
|
||||||
|
commit,
|
||||||
|
ctx.getUser().asIdentifiedUser());
|
||||||
|
|
||||||
switch (validatePolicy) {
|
switch (validatePolicy) {
|
||||||
case RECEIVE_COMMITS:
|
case RECEIVE_COMMITS:
|
||||||
NoteMap rejectCommits = BanCommit.loadRejectCommitsMap(
|
NoteMap rejectCommits = BanCommit.loadRejectCommitsMap(
|
||||||
@@ -405,6 +400,8 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
|||||||
}
|
}
|
||||||
} catch (CommitValidationException e) {
|
} catch (CommitValidationException e) {
|
||||||
throw new ResourceConflictException(e.getFullMessage());
|
throw new ResourceConflictException(e.getFullMessage());
|
||||||
|
} catch (NoSuchProjectException e) {
|
||||||
|
throw new ResourceConflictException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ public class CherryPickChange {
|
|||||||
}
|
}
|
||||||
Change.Id newChangeId =
|
Change.Id newChangeId =
|
||||||
createNewChange(git, revWalk, oi, project, cherryPickCommit,
|
createNewChange(git, revWalk, oi, project, cherryPickCommit,
|
||||||
refControl, identifiedUser, newTopic, change.getDest());
|
refControl.getRefName(), identifiedUser, newTopic,
|
||||||
|
change.getDest());
|
||||||
|
|
||||||
addMessageToSourceChange(change, patch.getId(), destinationBranch,
|
addMessageToSourceChange(change, patch.getId(), destinationBranch,
|
||||||
cherryPickCommit, identifiedUser, refControl);
|
cherryPickCommit, identifiedUser, refControl);
|
||||||
@@ -233,12 +234,12 @@ public class CherryPickChange {
|
|||||||
|
|
||||||
private Change.Id createNewChange(Repository git, RevWalk revWalk,
|
private Change.Id createNewChange(Repository git, RevWalk revWalk,
|
||||||
ObjectInserter oi, Project.NameKey project,
|
ObjectInserter oi, Project.NameKey project,
|
||||||
CodeReviewCommit cherryPickCommit, RefControl refControl,
|
CodeReviewCommit cherryPickCommit, String refName,
|
||||||
IdentifiedUser identifiedUser, String topic, Branch.NameKey sourceBranch)
|
IdentifiedUser identifiedUser, String topic, Branch.NameKey sourceBranch)
|
||||||
throws RestApiException, UpdateException, OrmException, IOException {
|
throws RestApiException, UpdateException, OrmException, IOException {
|
||||||
Change.Id changeId = new Change.Id(seq.nextChangeId());
|
Change.Id changeId = new Change.Id(seq.nextChangeId());
|
||||||
ChangeInserter ins = changeInserterFactory.create(
|
ChangeInserter ins = changeInserterFactory.create(
|
||||||
refControl, changeId, cherryPickCommit)
|
changeId, cherryPickCommit, refName)
|
||||||
.setValidatePolicy(CommitValidators.Policy.GERRIT)
|
.setValidatePolicy(CommitValidators.Policy.GERRIT)
|
||||||
.setTopic(topic);
|
.setTopic(topic);
|
||||||
|
|
||||||
|
|||||||
@@ -195,8 +195,7 @@ public class CreateChange implements
|
|||||||
RevCommit c = newCommit(oi, rw, author, mergeTip, commitMessage);
|
RevCommit c = newCommit(oi, rw, author, mergeTip, commitMessage);
|
||||||
|
|
||||||
Change.Id changeId = new Change.Id(seq.nextChangeId());
|
Change.Id changeId = new Change.Id(seq.nextChangeId());
|
||||||
ChangeInserter ins = changeInserterFactory
|
ChangeInserter ins = changeInserterFactory.create(changeId, c, refName)
|
||||||
.create(refControl, changeId, c)
|
|
||||||
.setValidatePolicy(CommitValidators.Policy.GERRIT);
|
.setValidatePolicy(CommitValidators.Policy.GERRIT);
|
||||||
ins.setMessage(String.format("Uploaded patch set %s.",
|
ins.setMessage(String.format("Uploaded patch set %s.",
|
||||||
ins.getPatchSet().getPatchSetId()));
|
ins.getPatchSet().getPatchSetId()));
|
||||||
|
|||||||
@@ -1585,7 +1585,7 @@ public class ReceiveCommits {
|
|||||||
|
|
||||||
final List<String> idList = c.getFooterLines(CHANGE_ID);
|
final List<String> idList = c.getFooterLines(CHANGE_ID);
|
||||||
if (idList.isEmpty()) {
|
if (idList.isEmpty()) {
|
||||||
newChanges.add(new CreateRequest(magicBranch.ctl, c));
|
newChanges.add(new CreateRequest(c, magicBranch.dest.get()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1648,7 +1648,7 @@ public class ReceiveCommits {
|
|||||||
|
|
||||||
newChangeIds.add(p.changeKey);
|
newChangeIds.add(p.changeKey);
|
||||||
}
|
}
|
||||||
newChanges.add(new CreateRequest(magicBranch.ctl, p.commit));
|
newChanges.add(new CreateRequest(p.commit, magicBranch.dest.get()));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Should never happen, the core receive process would have
|
// Should never happen, the core receive process would have
|
||||||
@@ -1731,11 +1731,11 @@ public class ReceiveCommits {
|
|||||||
Change change;
|
Change change;
|
||||||
Collection<String> groups;
|
Collection<String> groups;
|
||||||
|
|
||||||
CreateRequest(RefControl ctl, RevCommit c)
|
CreateRequest(RevCommit c, String refName)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
commit = c;
|
commit = c;
|
||||||
changeId = new Change.Id(seq.nextChangeId());
|
changeId = new Change.Id(seq.nextChangeId());
|
||||||
ins = changeInserterFactory.create(ctl, changeId, c)
|
ins = changeInserterFactory.create(changeId, c, refName)
|
||||||
.setDraft(magicBranch.draft)
|
.setDraft(magicBranch.draft)
|
||||||
.setTopic(magicBranch.topic)
|
.setTopic(magicBranch.topic)
|
||||||
// Changes already validated in validateNewCommits.
|
// Changes already validated in validateNewCommits.
|
||||||
|
|||||||
@@ -194,8 +194,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byId() throws Exception {
|
public void byId() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
assertQuery("12345");
|
assertQuery("12345");
|
||||||
assertQuery(change1.getId().get(), change1);
|
assertQuery(change1.getId().get(), change1);
|
||||||
@@ -205,7 +205,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byKey() throws Exception {
|
public void byKey() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change = insert(newChange(repo));
|
Change change = insert(repo, newChange(repo));
|
||||||
String key = change.getKey().get();
|
String key = change.getKey().get();
|
||||||
|
|
||||||
assertQuery("I0000000000000000000000000000000000000000");
|
assertQuery("I0000000000000000000000000000000000000000");
|
||||||
@@ -218,7 +218,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byTriplet() throws Exception {
|
public void byTriplet() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change = insert(newChangeForBranch(repo, "branch"));
|
Change change = insert(repo, newChangeForBranch(repo, "branch"));
|
||||||
String k = change.getKey().get();
|
String k = change.getKey().get();
|
||||||
|
|
||||||
assertQuery("repo~branch~" + k, change);
|
assertQuery("repo~branch~" + k, change);
|
||||||
@@ -242,9 +242,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byStatus() throws Exception {
|
public void byStatus() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
|
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
|
||||||
Change change1 = insert(ins1);
|
Change change1 = insert(repo, ins1);
|
||||||
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.MERGED);
|
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.MERGED);
|
||||||
Change change2 = insert(ins2);
|
Change change2 = insert(repo, ins2);
|
||||||
|
|
||||||
assertQuery("status:new", change1);
|
assertQuery("status:new", change1);
|
||||||
assertQuery("status:NEW", change1);
|
assertQuery("status:NEW", change1);
|
||||||
@@ -257,10 +257,10 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byStatusOpen() throws Exception {
|
public void byStatusOpen() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
|
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
|
||||||
Change change1 = insert(ins1);
|
Change change1 = insert(repo, ins1);
|
||||||
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.DRAFT);
|
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.DRAFT);
|
||||||
Change change2 = insert(ins2);
|
Change change2 = insert(repo, ins2);
|
||||||
insert(newChangeWithStatus(repo, Change.Status.MERGED));
|
insert(repo, newChangeWithStatus(repo, Change.Status.MERGED));
|
||||||
|
|
||||||
Change[] expected = new Change[] {change2, change1};
|
Change[] expected = new Change[] {change2, change1};
|
||||||
assertQuery("status:open", expected);
|
assertQuery("status:open", expected);
|
||||||
@@ -279,9 +279,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byStatusDraft() throws Exception {
|
public void byStatusDraft() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
insert(newChangeWithStatus(repo, Change.Status.NEW));
|
insert(repo, newChangeWithStatus(repo, Change.Status.NEW));
|
||||||
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.DRAFT);
|
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.DRAFT);
|
||||||
Change change2 = insert(ins2);
|
Change change2 = insert(repo, ins2);
|
||||||
|
|
||||||
Change[] expected = new Change[] {change2};
|
Change[] expected = new Change[] {change2};
|
||||||
assertQuery("status:draft", expected);
|
assertQuery("status:draft", expected);
|
||||||
@@ -297,10 +297,10 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byStatusClosed() throws Exception {
|
public void byStatusClosed() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.MERGED);
|
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.MERGED);
|
||||||
Change change1 = insert(ins1);
|
Change change1 = insert(repo, ins1);
|
||||||
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.ABANDONED);
|
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.ABANDONED);
|
||||||
Change change2 = insert(ins2);
|
Change change2 = insert(repo, ins2);
|
||||||
insert(newChangeWithStatus(repo, Change.Status.NEW));
|
insert(repo, newChangeWithStatus(repo, Change.Status.NEW));
|
||||||
|
|
||||||
Change[] expected = new Change[] {change2, change1};
|
Change[] expected = new Change[] {change2, change1};
|
||||||
assertQuery("status:closed", expected);
|
assertQuery("status:closed", expected);
|
||||||
@@ -318,8 +318,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byStatusPrefix() throws Exception {
|
public void byStatusPrefix() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
|
ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
|
||||||
Change change1 = insert(ins1);
|
Change change1 = insert(repo, ins1);
|
||||||
insert(newChangeWithStatus(repo, Change.Status.MERGED));
|
insert(repo, newChangeWithStatus(repo, Change.Status.MERGED));
|
||||||
|
|
||||||
assertQuery("status:n", change1);
|
assertQuery("status:n", change1);
|
||||||
assertQuery("status:ne", change1);
|
assertQuery("status:ne", change1);
|
||||||
@@ -335,7 +335,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byCommit() throws Exception {
|
public void byCommit() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins = newChange(repo);
|
ChangeInserter ins = newChange(repo);
|
||||||
insert(ins);
|
insert(repo, ins);
|
||||||
String sha = ins.getPatchSet().getRevision().get();
|
String sha = ins.getPatchSet().getRevision().get();
|
||||||
|
|
||||||
assertQuery("0000000000000000000000000000000000000000");
|
assertQuery("0000000000000000000000000000000000000000");
|
||||||
@@ -348,10 +348,10 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byOwner() throws Exception {
|
public void byOwner() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChangeForUser(repo, userId));
|
Change change1 = insert(repo, newChange(repo), userId);
|
||||||
Account.Id user2 = accountManager.authenticate(
|
Account.Id user2 = accountManager.authenticate(
|
||||||
AuthRequest.forUser("anotheruser")).getAccountId();
|
AuthRequest.forUser("anotheruser")).getAccountId();
|
||||||
Change change2 = insert(newChangeForUser(repo, user2));
|
Change change2 = insert(repo, newChange(repo), user2);
|
||||||
|
|
||||||
assertQuery("owner:" + userId.get(), change1);
|
assertQuery("owner:" + userId.get(), change1);
|
||||||
assertQuery("owner:" + user2, change2);
|
assertQuery("owner:" + user2, change2);
|
||||||
@@ -360,7 +360,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byAuthor() throws Exception {
|
public void byAuthor() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChangeForUser(repo, userId));
|
Change change1 = insert(repo, newChange(repo), userId);
|
||||||
|
|
||||||
// By exact email address
|
// By exact email address
|
||||||
assertQuery("author:jauthor@example.com", change1);
|
assertQuery("author:jauthor@example.com", change1);
|
||||||
@@ -387,7 +387,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byCommitter() throws Exception {
|
public void byCommitter() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChangeForUser(repo, userId));
|
Change change1 = insert(repo, newChange(repo), userId);
|
||||||
|
|
||||||
// By exact email address
|
// By exact email address
|
||||||
assertQuery("committer:jcommitter@example.com", change1);
|
assertQuery("committer:jcommitter@example.com", change1);
|
||||||
@@ -414,10 +414,10 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byOwnerIn() throws Exception {
|
public void byOwnerIn() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChangeForUser(repo, userId));
|
Change change1 = insert(repo, newChange(repo), userId);
|
||||||
Account.Id user2 = accountManager.authenticate(
|
Account.Id user2 = accountManager.authenticate(
|
||||||
AuthRequest.forUser("anotheruser")).getAccountId();
|
AuthRequest.forUser("anotheruser")).getAccountId();
|
||||||
Change change2 = insert(newChangeForUser(repo, user2));
|
Change change2 = insert(repo, newChange(repo), user2);
|
||||||
|
|
||||||
assertQuery("ownerin:Administrators", change1);
|
assertQuery("ownerin:Administrators", change1);
|
||||||
assertQuery("ownerin:\"Registered Users\"", change2, change1);
|
assertQuery("ownerin:\"Registered Users\"", change2, change1);
|
||||||
@@ -427,8 +427,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byProject() throws Exception {
|
public void byProject() throws Exception {
|
||||||
TestRepository<Repo> repo1 = createProject("repo1");
|
TestRepository<Repo> repo1 = createProject("repo1");
|
||||||
TestRepository<Repo> repo2 = createProject("repo2");
|
TestRepository<Repo> repo2 = createProject("repo2");
|
||||||
Change change1 = insert(newChange(repo1));
|
Change change1 = insert(repo1, newChange(repo1));
|
||||||
Change change2 = insert(newChange(repo2));
|
Change change2 = insert(repo2, newChange(repo2));
|
||||||
|
|
||||||
assertQuery("project:foo");
|
assertQuery("project:foo");
|
||||||
assertQuery("project:repo");
|
assertQuery("project:repo");
|
||||||
@@ -440,8 +440,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byProjectPrefix() throws Exception {
|
public void byProjectPrefix() throws Exception {
|
||||||
TestRepository<Repo> repo1 = createProject("repo1");
|
TestRepository<Repo> repo1 = createProject("repo1");
|
||||||
TestRepository<Repo> repo2 = createProject("repo2");
|
TestRepository<Repo> repo2 = createProject("repo2");
|
||||||
Change change1 = insert(newChange(repo1));
|
Change change1 = insert(repo1, newChange(repo1));
|
||||||
Change change2 = insert(newChange(repo2));
|
Change change2 = insert(repo2, newChange(repo2));
|
||||||
|
|
||||||
assertQuery("projects:foo");
|
assertQuery("projects:foo");
|
||||||
assertQuery("projects:repo1", change1);
|
assertQuery("projects:repo1", change1);
|
||||||
@@ -452,8 +452,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byBranchAndRef() throws Exception {
|
public void byBranchAndRef() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChangeForBranch(repo, "master"));
|
Change change1 = insert(repo, newChangeForBranch(repo, "master"));
|
||||||
Change change2 = insert(newChangeForBranch(repo, "branch"));
|
Change change2 = insert(repo, newChangeForBranch(repo, "branch"));
|
||||||
|
|
||||||
assertQuery("branch:foo");
|
assertQuery("branch:foo");
|
||||||
assertQuery("branch:master", change1);
|
assertQuery("branch:master", change1);
|
||||||
@@ -471,18 +471,18 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byTopic() throws Exception {
|
public void byTopic() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins1 = newChangeWithTopic(repo, "feature1");
|
ChangeInserter ins1 = newChangeWithTopic(repo, "feature1");
|
||||||
Change change1 = insert(ins1);
|
Change change1 = insert(repo, ins1);
|
||||||
|
|
||||||
ChangeInserter ins2 = newChangeWithTopic(repo, "feature2");
|
ChangeInserter ins2 = newChangeWithTopic(repo, "feature2");
|
||||||
Change change2 = insert(ins2);
|
Change change2 = insert(repo, ins2);
|
||||||
|
|
||||||
ChangeInserter ins3 = newChangeWithTopic(repo, "Cherrypick-feature2");
|
ChangeInserter ins3 = newChangeWithTopic(repo, "Cherrypick-feature2");
|
||||||
Change change3 = insert(ins3);
|
Change change3 = insert(repo, ins3);
|
||||||
|
|
||||||
ChangeInserter ins4 = newChangeWithTopic(repo, "feature2-fixup");
|
ChangeInserter ins4 = newChangeWithTopic(repo, "feature2-fixup");
|
||||||
Change change4 = insert(ins4);
|
Change change4 = insert(repo, ins4);
|
||||||
|
|
||||||
Change change5 = insert(newChange(repo));
|
Change change5 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
assertQuery("intopic:foo");
|
assertQuery("intopic:foo");
|
||||||
assertQuery("intopic:feature1", change1);
|
assertQuery("intopic:feature1", change1);
|
||||||
@@ -498,9 +498,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byMessageExact() throws Exception {
|
public void byMessageExact() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
RevCommit commit1 = repo.parseBody(repo.commit().message("one").create());
|
RevCommit commit1 = repo.parseBody(repo.commit().message("one").create());
|
||||||
Change change1 = insert(newChangeForCommit(repo, commit1));
|
Change change1 = insert(repo, newChangeForCommit(repo, commit1));
|
||||||
RevCommit commit2 = repo.parseBody(repo.commit().message("two").create());
|
RevCommit commit2 = repo.parseBody(repo.commit().message("two").create());
|
||||||
Change change2 = insert(newChangeForCommit(repo, commit2));
|
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
|
||||||
|
|
||||||
assertQuery("message:foo");
|
assertQuery("message:foo");
|
||||||
assertQuery("message:one", change1);
|
assertQuery("message:one", change1);
|
||||||
@@ -512,10 +512,10 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
RevCommit commit1 =
|
RevCommit commit1 =
|
||||||
repo.parseBody(repo.commit().message("12345 67890").create());
|
repo.parseBody(repo.commit().message("12345 67890").create());
|
||||||
Change change1 = insert(newChangeForCommit(repo, commit1));
|
Change change1 = insert(repo, newChangeForCommit(repo, commit1));
|
||||||
RevCommit commit2 =
|
RevCommit commit2 =
|
||||||
repo.parseBody(repo.commit().message("12346 67891").create());
|
repo.parseBody(repo.commit().message("12346 67891").create());
|
||||||
Change change2 = insert(newChangeForCommit(repo, commit2));
|
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
|
||||||
|
|
||||||
assertQuery("message:1234");
|
assertQuery("message:1234");
|
||||||
assertQuery("message:12345", change1);
|
assertQuery("message:12345", change1);
|
||||||
@@ -527,7 +527,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
accountManager.authenticate(AuthRequest.forUser("anotheruser"));
|
accountManager.authenticate(AuthRequest.forUser("anotheruser"));
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins = newChange(repo);
|
ChangeInserter ins = newChange(repo);
|
||||||
Change change = insert(ins);
|
Change change = insert(repo, ins);
|
||||||
|
|
||||||
gApi.changes().id(change.getId().get()).current()
|
gApi.changes().id(change.getId().get()).current()
|
||||||
.review(new ReviewInput().label("Code-Review", 1));
|
.review(new ReviewInput().label("Code-Review", 1));
|
||||||
@@ -589,8 +589,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
gApi.groups().id(g2).addMembers("user2");
|
gApi.groups().id(g2).addMembers("user2");
|
||||||
|
|
||||||
// create a change
|
// create a change
|
||||||
ChangeInserter ins = newChangeForUser(repo, user1);
|
Change change1 = insert(repo, newChange(repo), user1);
|
||||||
Change change1 = insert(ins);
|
|
||||||
|
|
||||||
// post a review with user1
|
// post a review with user1
|
||||||
requestContext.setContext(newRequestContext(user1));
|
requestContext.setContext(newRequestContext(user1));
|
||||||
@@ -612,7 +611,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
Change last = null;
|
Change last = null;
|
||||||
int n = 5;
|
int n = 5;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
last = insert(newChange(repo));
|
last = insert(repo, newChange(repo));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i <= n + 2; i++) {
|
for (int i = 1; i <= n + 2; i++) {
|
||||||
@@ -639,7 +638,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
List<Change> changes = Lists.newArrayList();
|
List<Change> changes = Lists.newArrayList();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
changes.add(insert(newChange(repo)));
|
changes.add(insert(repo, newChange(repo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertQuery("status:new", changes.get(1), changes.get(0));
|
assertQuery("status:new", changes.get(1), changes.get(0));
|
||||||
@@ -653,7 +652,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
List<Change> changes = Lists.newArrayList();
|
List<Change> changes = Lists.newArrayList();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
changes.add(insert(newChange(repo)));
|
changes.add(insert(repo, newChange(repo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertQuery("status:new limit:2", changes.get(2), changes.get(1));
|
assertQuery("status:new limit:2", changes.get(2), changes.get(1));
|
||||||
@@ -667,7 +666,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void maxPages() throws Exception {
|
public void maxPages() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change = insert(newChange(repo));
|
Change change = insert(repo, newChange(repo));
|
||||||
|
|
||||||
QueryRequest query = newQuery("status:new").withLimit(10);
|
QueryRequest query = newQuery("status:new").withLimit(10);
|
||||||
assertQuery(query, change);
|
assertQuery(query, change);
|
||||||
@@ -685,7 +684,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
List<Change> changes = Lists.newArrayList();
|
List<Change> changes = Lists.newArrayList();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
inserters.add(newChange(repo));
|
inserters.add(newChange(repo));
|
||||||
changes.add(insert(inserters.get(i)));
|
changes.add(insert(repo, inserters.get(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i : ImmutableList.of(2, 0, 1, 4, 3)) {
|
for (int i : ImmutableList.of(2, 0, 1, 4, 3)) {
|
||||||
@@ -707,8 +706,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
TestTimeUtil.resetWithClockStep(2, MINUTES);
|
TestTimeUtil.resetWithClockStep(2, MINUTES);
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins1 = newChange(repo);
|
ChangeInserter ins1 = newChange(repo);
|
||||||
Change change1 = insert(ins1);
|
Change change1 = insert(repo, ins1);
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
assertThat(lastUpdatedMs(change1)).isLessThan(lastUpdatedMs(change2));
|
assertThat(lastUpdatedMs(change1)).isLessThan(lastUpdatedMs(change2));
|
||||||
assertQuery("status:new", change2, change1);
|
assertQuery("status:new", change2, change1);
|
||||||
@@ -729,8 +728,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void updatedOrderWithSubMinuteResolution() throws Exception {
|
public void updatedOrderWithSubMinuteResolution() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins1 = newChange(repo);
|
ChangeInserter ins1 = newChange(repo);
|
||||||
Change change1 = insert(ins1);
|
Change change1 = insert(repo, ins1);
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
assertThat(lastUpdatedMs(change1)).isLessThan(lastUpdatedMs(change2));
|
assertThat(lastUpdatedMs(change1)).isLessThan(lastUpdatedMs(change2));
|
||||||
|
|
||||||
@@ -751,11 +750,11 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void filterOutMoreThanOnePageOfResults() throws Exception {
|
public void filterOutMoreThanOnePageOfResults() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change = insert(newChangeForUser(repo, userId));
|
Change change = insert(repo, newChange(repo), userId);
|
||||||
Account.Id user2 = accountManager.authenticate(
|
Account.Id user2 = accountManager.authenticate(
|
||||||
AuthRequest.forUser("anotheruser")).getAccountId();
|
AuthRequest.forUser("anotheruser")).getAccountId();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
insert(newChangeForUser(repo, user2));
|
insert(repo, newChange(repo), user2);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertQuery("status:new ownerin:Administrators", change);
|
assertQuery("status:new ownerin:Administrators", change);
|
||||||
@@ -768,7 +767,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
Account.Id user2 = accountManager.authenticate(
|
Account.Id user2 = accountManager.authenticate(
|
||||||
AuthRequest.forUser("anotheruser")).getAccountId();
|
AuthRequest.forUser("anotheruser")).getAccountId();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
insert(newChangeForUser(repo, user2));
|
insert(repo, newChange(repo), user2);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertQuery("status:new ownerin:Administrators");
|
assertQuery("status:new ownerin:Administrators");
|
||||||
@@ -782,7 +781,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
repo.commit().message("one")
|
repo.commit().message("one")
|
||||||
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
||||||
.create());
|
.create());
|
||||||
Change change = insert(newChangeForCommit(repo, commit));
|
Change change = insert(repo, newChangeForCommit(repo, commit));
|
||||||
|
|
||||||
assertQuery("file:file");
|
assertQuery("file:file");
|
||||||
assertQuery("file:dir", change);
|
assertQuery("file:dir", change);
|
||||||
@@ -799,7 +798,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
repo.commit().message("one")
|
repo.commit().message("one")
|
||||||
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
||||||
.create());
|
.create());
|
||||||
Change change = insert(newChangeForCommit(repo, commit));
|
Change change = insert(repo, newChangeForCommit(repo, commit));
|
||||||
|
|
||||||
assertQuery("file:.*file.*");
|
assertQuery("file:.*file.*");
|
||||||
assertQuery("file:^file.*"); // Whole path only.
|
assertQuery("file:^file.*"); // Whole path only.
|
||||||
@@ -813,7 +812,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
repo.commit().message("one")
|
repo.commit().message("one")
|
||||||
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
||||||
.create());
|
.create());
|
||||||
Change change = insert(newChangeForCommit(repo, commit));
|
Change change = insert(repo, newChangeForCommit(repo, commit));
|
||||||
|
|
||||||
assertQuery("path:file");
|
assertQuery("path:file");
|
||||||
assertQuery("path:dir");
|
assertQuery("path:dir");
|
||||||
@@ -830,7 +829,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
repo.commit().message("one")
|
repo.commit().message("one")
|
||||||
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
.add("dir/file1", "contents1").add("dir/file2", "contents2")
|
||||||
.create());
|
.create());
|
||||||
Change change = insert(newChangeForCommit(repo, commit));
|
Change change = insert(repo, newChangeForCommit(repo, commit));
|
||||||
|
|
||||||
assertQuery("path:.*file.*");
|
assertQuery("path:.*file.*");
|
||||||
assertQuery("path:^dir.file.*", change);
|
assertQuery("path:^dir.file.*", change);
|
||||||
@@ -840,7 +839,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byComment() throws Exception {
|
public void byComment() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
ChangeInserter ins = newChange(repo);
|
ChangeInserter ins = newChange(repo);
|
||||||
Change change = insert(ins);
|
Change change = insert(repo, ins);
|
||||||
|
|
||||||
ReviewInput input = new ReviewInput();
|
ReviewInput input = new ReviewInput();
|
||||||
input.message = "toplevel";
|
input.message = "toplevel";
|
||||||
@@ -861,8 +860,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
long thirtyHoursInMs = MILLISECONDS.convert(30, HOURS);
|
long thirtyHoursInMs = MILLISECONDS.convert(30, HOURS);
|
||||||
TestTimeUtil.resetWithClockStep(thirtyHoursInMs, MILLISECONDS);
|
TestTimeUtil.resetWithClockStep(thirtyHoursInMs, MILLISECONDS);
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
// Queried by AgePredicate constructor.
|
// Queried by AgePredicate constructor.
|
||||||
TestTimeUtil.setClockStep(0, MILLISECONDS);
|
TestTimeUtil.setClockStep(0, MILLISECONDS);
|
||||||
long now = TimeUtil.nowMs();
|
long now = TimeUtil.nowMs();
|
||||||
@@ -884,8 +883,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byBefore() throws Exception {
|
public void byBefore() throws Exception {
|
||||||
TestTimeUtil.resetWithClockStep(30, HOURS);
|
TestTimeUtil.resetWithClockStep(30, HOURS);
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
TestTimeUtil.setClockStep(0, MILLISECONDS);
|
TestTimeUtil.setClockStep(0, MILLISECONDS);
|
||||||
|
|
||||||
assertQuery("before:2009-09-29");
|
assertQuery("before:2009-09-29");
|
||||||
@@ -904,8 +903,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byAfter() throws Exception {
|
public void byAfter() throws Exception {
|
||||||
TestTimeUtil.resetWithClockStep(30, HOURS);
|
TestTimeUtil.resetWithClockStep(30, HOURS);
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
TestTimeUtil.setClockStep(0, MILLISECONDS);
|
TestTimeUtil.setClockStep(0, MILLISECONDS);
|
||||||
|
|
||||||
assertQuery("after:2009-10-03");
|
assertQuery("after:2009-10-03");
|
||||||
@@ -926,8 +925,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
RevCommit commit2 = repo.parseBody(
|
RevCommit commit2 = repo.parseBody(
|
||||||
repo.commit().parent(commit1).add("file1", "foo").create());
|
repo.commit().parent(commit1).add("file1", "foo").create());
|
||||||
|
|
||||||
Change change1 = insert(newChangeForCommit(repo, commit1));
|
Change change1 = insert(repo, newChangeForCommit(repo, commit1));
|
||||||
Change change2 = insert(newChangeForCommit(repo, commit2));
|
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
|
||||||
|
|
||||||
assertQuery("added:>4");
|
assertQuery("added:>4");
|
||||||
assertQuery("-added:<=4");
|
assertQuery("-added:<=4");
|
||||||
@@ -976,8 +975,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
|
|
||||||
private List<Change> setUpHashtagChanges() throws Exception {
|
private List<Change> setUpHashtagChanges() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
HashtagsInput in = new HashtagsInput();
|
HashtagsInput in = new HashtagsInput();
|
||||||
in.add = ImmutableSet.of("foo");
|
in.add = ImmutableSet.of("foo");
|
||||||
@@ -1019,29 +1018,29 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void byDefault() throws Exception {
|
public void byDefault() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
|
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
RevCommit commit2 = repo.parseBody(
|
RevCommit commit2 = repo.parseBody(
|
||||||
repo.commit().message("foosubject").create());
|
repo.commit().message("foosubject").create());
|
||||||
Change change2 = insert(newChangeForCommit(repo, commit2));
|
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
|
||||||
|
|
||||||
RevCommit commit3 = repo.parseBody(
|
RevCommit commit3 = repo.parseBody(
|
||||||
repo.commit()
|
repo.commit()
|
||||||
.add("Foo.java", "foo contents")
|
.add("Foo.java", "foo contents")
|
||||||
.create());
|
.create());
|
||||||
Change change3 = insert(newChangeForCommit(repo, commit3));
|
Change change3 = insert(repo, newChangeForCommit(repo, commit3));
|
||||||
|
|
||||||
ChangeInserter ins4 = newChange(repo);
|
ChangeInserter ins4 = newChange(repo);
|
||||||
Change change4 = insert(ins4);
|
Change change4 = insert(repo, ins4);
|
||||||
ReviewInput ri4 = new ReviewInput();
|
ReviewInput ri4 = new ReviewInput();
|
||||||
ri4.message = "toplevel";
|
ri4.message = "toplevel";
|
||||||
ri4.labels = ImmutableMap.<String, Short> of("Code-Review", (short) 1);
|
ri4.labels = ImmutableMap.<String, Short> of("Code-Review", (short) 1);
|
||||||
gApi.changes().id(change4.getId().get()).current().review(ri4);
|
gApi.changes().id(change4.getId().get()).current().review(ri4);
|
||||||
|
|
||||||
ChangeInserter ins5 = newChangeWithTopic(repo, "feature5");
|
ChangeInserter ins5 = newChangeWithTopic(repo, "feature5");
|
||||||
Change change5 = insert(ins5);
|
Change change5 = insert(repo, ins5);
|
||||||
|
|
||||||
Change change6 = insert(newChangeForBranch(repo, "branch6"));
|
Change change6 = insert(repo, newChangeForBranch(repo, "branch6"));
|
||||||
|
|
||||||
assertQuery(change1.getId().get(), change1);
|
assertQuery(change1.getId().get(), change1);
|
||||||
assertQuery(ChangeTriplet.format(change1), change1);
|
assertQuery(ChangeTriplet.format(change1), change1);
|
||||||
@@ -1062,10 +1061,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void implicitVisibleTo() throws Exception {
|
public void implicitVisibleTo() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChangeForUser(repo, userId));
|
Change change1 = insert(repo, newChange(repo), userId);
|
||||||
ChangeInserter ins2 =
|
Change change2 =
|
||||||
newChange(repo, null, userId, null, Change.Status.DRAFT, null);
|
insert(repo, newChangeWithStatus(repo, Change.Status.DRAFT), userId);
|
||||||
Change change2 = insert(ins2);
|
|
||||||
|
|
||||||
String q = "project:repo";
|
String q = "project:repo";
|
||||||
assertQuery(q, change2, change1);
|
assertQuery(q, change2, change1);
|
||||||
@@ -1079,10 +1077,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void explicitVisibleTo() throws Exception {
|
public void explicitVisibleTo() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChangeForUser(repo, userId));
|
Change change1 = insert(repo, newChange(repo), userId);
|
||||||
ChangeInserter ins2 =
|
Change change2 =
|
||||||
newChange(repo, null, userId, null, Change.Status.DRAFT, null);
|
insert(repo, newChangeWithStatus(repo, Change.Status.DRAFT), userId);
|
||||||
Change change2 = insert(ins2);
|
|
||||||
|
|
||||||
String q = "project:repo";
|
String q = "project:repo";
|
||||||
assertQuery(q, change2, change1);
|
assertQuery(q, change2, change1);
|
||||||
@@ -1097,8 +1094,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byCommentBy() throws Exception {
|
public void byCommentBy() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
int user2 = accountManager.authenticate(AuthRequest.forUser("anotheruser"))
|
int user2 = accountManager.authenticate(AuthRequest.forUser("anotheruser"))
|
||||||
.getAccountId().get();
|
.getAccountId().get();
|
||||||
@@ -1123,8 +1120,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byDraftBy() throws Exception {
|
public void byDraftBy() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
DraftInput in = new DraftInput();
|
DraftInput in = new DraftInput();
|
||||||
in.line = 1;
|
in.line = 1;
|
||||||
@@ -1148,12 +1145,11 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
@Test
|
@Test
|
||||||
public void byFrom() throws Exception {
|
public void byFrom() throws Exception {
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
Account.Id user2 = accountManager.authenticate(
|
Account.Id user2 = accountManager.authenticate(
|
||||||
AuthRequest.forUser("anotheruser")).getAccountId();
|
AuthRequest.forUser("anotheruser")).getAccountId();
|
||||||
ChangeInserter ins2 = newChangeForUser(repo, user2);
|
Change change2 = insert(repo, newChange(repo), user2);
|
||||||
Change change2 = insert(ins2);
|
|
||||||
|
|
||||||
ReviewInput input = new ReviewInput();
|
ReviewInput input = new ReviewInput();
|
||||||
input.message = "toplevel";
|
input.message = "toplevel";
|
||||||
@@ -1189,10 +1185,10 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
repo.commit()
|
repo.commit()
|
||||||
.add("file4", "contents4")
|
.add("file4", "contents4")
|
||||||
.create());
|
.create());
|
||||||
Change change1 = insert(newChangeForCommit(repo, commit1));
|
Change change1 = insert(repo, newChangeForCommit(repo, commit1));
|
||||||
Change change2 = insert(newChangeForCommit(repo, commit2));
|
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
|
||||||
Change change3 = insert(newChangeForCommit(repo, commit3));
|
Change change3 = insert(repo, newChangeForCommit(repo, commit3));
|
||||||
Change change4 = insert(newChangeForCommit(repo, commit4));
|
Change change4 = insert(repo, newChangeForCommit(repo, commit4));
|
||||||
|
|
||||||
assertQuery("conflicts:" + change1.getId().get(), change3);
|
assertQuery("conflicts:" + change1.getId().get(), change3);
|
||||||
assertQuery("conflicts:" + change2.getId().get());
|
assertQuery("conflicts:" + change2.getId().get());
|
||||||
@@ -1204,9 +1200,9 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void reviewedBy() throws Exception {
|
public void reviewedBy() throws Exception {
|
||||||
TestTimeUtil.resetWithClockStep(2, MINUTES);
|
TestTimeUtil.resetWithClockStep(2, MINUTES);
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change1 = insert(newChange(repo));
|
Change change1 = insert(repo, newChange(repo));
|
||||||
Change change2 = insert(newChange(repo));
|
Change change2 = insert(repo, newChange(repo));
|
||||||
Change change3 = insert(newChange(repo));
|
Change change3 = insert(repo, newChange(repo));
|
||||||
|
|
||||||
gApi.changes()
|
gApi.changes()
|
||||||
.id(change1.getId().get())
|
.id(change1.getId().get())
|
||||||
@@ -1262,7 +1258,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
Branch.NameKey dest = null;
|
Branch.NameKey dest = null;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
ChangeInserter ins = newChange(repo);
|
ChangeInserter ins = newChange(repo);
|
||||||
insert(ins);
|
insert(repo, ins);
|
||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
dest = ins.getChange().getDest();
|
dest = ins.getChange().getDest();
|
||||||
}
|
}
|
||||||
@@ -1291,7 +1287,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void prepopulatedFields() throws Exception {
|
public void prepopulatedFields() throws Exception {
|
||||||
assume().that(notesMigration.enabled()).isFalse();
|
assume().that(notesMigration.enabled()).isFalse();
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change = insert(newChange(repo));
|
Change change = insert(repo, newChange(repo));
|
||||||
|
|
||||||
db = new DisabledReviewDb();
|
db = new DisabledReviewDb();
|
||||||
requestContext.setContext(newRequestContext(userId));
|
requestContext.setContext(newRequestContext(userId));
|
||||||
@@ -1320,7 +1316,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
public void prepopulateOnlyRequestedFields() throws Exception {
|
public void prepopulateOnlyRequestedFields() throws Exception {
|
||||||
assume().that(notesMigration.enabled()).isFalse();
|
assume().that(notesMigration.enabled()).isFalse();
|
||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
Change change = insert(newChange(repo));
|
Change change = insert(repo, newChange(repo));
|
||||||
|
|
||||||
db = new DisabledReviewDb();
|
db = new DisabledReviewDb();
|
||||||
requestContext.setContext(newRequestContext(userId));
|
requestContext.setContext(newRequestContext(userId));
|
||||||
@@ -1343,63 +1339,62 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
|
|
||||||
protected ChangeInserter newChange(TestRepository<Repo> repo)
|
protected ChangeInserter newChange(TestRepository<Repo> repo)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
return newChange(repo, null, null, null, null, null);
|
return newChange(repo, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ChangeInserter newChangeForCommit(TestRepository<Repo> repo,
|
protected ChangeInserter newChangeForCommit(TestRepository<Repo> repo,
|
||||||
RevCommit commit) throws Exception {
|
RevCommit commit) throws Exception {
|
||||||
return newChange(repo, commit, null, null, null, null);
|
return newChange(repo, commit, null, null, null);
|
||||||
}
|
|
||||||
|
|
||||||
protected ChangeInserter newChangeForUser(TestRepository<Repo> repo,
|
|
||||||
Account.Id owner) throws Exception {
|
|
||||||
return newChange(repo, null, owner, null, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ChangeInserter newChangeForBranch(TestRepository<Repo> repo,
|
protected ChangeInserter newChangeForBranch(TestRepository<Repo> repo,
|
||||||
String branch) throws Exception {
|
String branch) throws Exception {
|
||||||
return newChange(repo, null, null, branch, null, null);
|
return newChange(repo, null, branch, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ChangeInserter newChangeWithStatus(TestRepository<Repo> repo,
|
protected ChangeInserter newChangeWithStatus(TestRepository<Repo> repo,
|
||||||
Change.Status status) throws Exception {
|
Change.Status status) throws Exception {
|
||||||
return newChange(repo, null, null, null, status, null);
|
return newChange(repo, null, null, status, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ChangeInserter newChangeWithTopic(TestRepository<Repo> repo,
|
protected ChangeInserter newChangeWithTopic(TestRepository<Repo> repo,
|
||||||
String topic) throws Exception {
|
String topic) throws Exception {
|
||||||
return newChange(repo, null, null, null, null, topic);
|
return newChange(repo, null, null, null, topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ChangeInserter newChange(TestRepository<Repo> repo,
|
protected ChangeInserter newChange(TestRepository<Repo> repo,
|
||||||
@Nullable RevCommit commit, @Nullable Account.Id owner,
|
@Nullable RevCommit commit, @Nullable String branch,
|
||||||
@Nullable String branch, @Nullable Change.Status status,
|
@Nullable Change.Status status, @Nullable String topic) throws Exception {
|
||||||
@Nullable String topic) throws Exception {
|
|
||||||
if (commit == null) {
|
if (commit == null) {
|
||||||
commit = repo.parseBody(repo.commit().message("message").create());
|
commit = repo.parseBody(repo.commit().message("message").create());
|
||||||
}
|
}
|
||||||
Account.Id ownerId = owner != null ? owner : userId;
|
|
||||||
branch = MoreObjects.firstNonNull(branch, "refs/heads/master");
|
branch = MoreObjects.firstNonNull(branch, "refs/heads/master");
|
||||||
if (!branch.startsWith("refs/heads/")) {
|
if (!branch.startsWith("refs/heads/")) {
|
||||||
branch = "refs/heads/" + branch;
|
branch = "refs/heads/" + branch;
|
||||||
}
|
}
|
||||||
Project.NameKey project = new Project.NameKey(
|
|
||||||
repo.getRepository().getDescription().getRepositoryName());
|
|
||||||
|
|
||||||
Change.Id id = new Change.Id(seq.nextChangeId());
|
Change.Id id = new Change.Id(seq.nextChangeId());
|
||||||
IdentifiedUser user = userFactory.create(Providers.of(db), ownerId);
|
ChangeInserter ins = changeFactory.create(
|
||||||
RefControl refControl = projectControlFactory.controlFor(project, user)
|
id, commit, branch)
|
||||||
.controlForRef(new Branch.NameKey(project, branch));
|
|
||||||
ChangeInserter ins = changeFactory.create(refControl, id, commit)
|
|
||||||
.setValidatePolicy(CommitValidators.Policy.NONE)
|
.setValidatePolicy(CommitValidators.Policy.NONE)
|
||||||
.setStatus(status)
|
.setStatus(status)
|
||||||
.setTopic(topic);
|
.setTopic(topic);
|
||||||
return ins;
|
return ins;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Change insert(ChangeInserter ins) throws Exception {
|
protected Change insert(TestRepository<Repo> repo, ChangeInserter ins) throws Exception {
|
||||||
try (BatchUpdate bu = updateFactory.create(db, ins.getProject(),
|
return insert(repo, ins, null);
|
||||||
ins.getUser(), TimeUtil.nowTs())) {
|
}
|
||||||
|
|
||||||
|
protected Change insert(TestRepository<Repo> repo, ChangeInserter ins,
|
||||||
|
@Nullable Account.Id owner) throws Exception {
|
||||||
|
Project.NameKey project = new Project.NameKey(
|
||||||
|
repo.getRepository().getDescription().getRepositoryName());
|
||||||
|
Account.Id ownerId = owner != null ? owner : userId;
|
||||||
|
IdentifiedUser user = userFactory.create(Providers.of(db), ownerId);
|
||||||
|
try (BatchUpdate bu =
|
||||||
|
updateFactory.create(db, project, user, TimeUtil.nowTs())) {
|
||||||
bu.insertChange(ins);
|
bu.insertChange(ins);
|
||||||
bu.execute();
|
bu.execute();
|
||||||
return ins.getChange();
|
return ins.getChange();
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ public class LuceneQueryChangesTest extends AbstractQueryChangesTest {
|
|||||||
TestRepository<Repo> repo = createProject("repo");
|
TestRepository<Repo> repo = createProject("repo");
|
||||||
RevCommit commit1 =
|
RevCommit commit1 =
|
||||||
repo.parseBody(repo.commit().message("foo_bar_foo").create());
|
repo.parseBody(repo.commit().message("foo_bar_foo").create());
|
||||||
Change change1 = insert(newChangeForCommit(repo, commit1));
|
Change change1 = insert(repo, newChangeForCommit(repo, commit1));
|
||||||
RevCommit commit2 =
|
RevCommit commit2 =
|
||||||
repo.parseBody(repo.commit().message("one.two.three").create());
|
repo.parseBody(repo.commit().message("one.two.three").create());
|
||||||
Change change2 = insert(newChangeForCommit(repo, commit2));
|
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
|
||||||
|
|
||||||
assertQuery("message:foo_ba");
|
assertQuery("message:foo_ba");
|
||||||
assertQuery("message:bar", change1);
|
assertQuery("message:bar", change1);
|
||||||
|
|||||||
Reference in New Issue
Block a user