Replace calls of ChangeNotes#getChange()
In future a change from ChangeNotes is only available after the notes have been loaded, but project and change ID are known before. Avoid calling getChange() when only project and change ID are required so that loading the notes is not required in this case. Change-Id: I172d94e9550c28797f0a7a6b20c4b4bc64e9dbfc Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -903,7 +903,7 @@ public class ChangeHookRunner implements ChangeHooks, EventDispatcher,
|
||||
@Override
|
||||
public PatchSetAttribute get() {
|
||||
try (Repository repo =
|
||||
repoManager.openRepository(notes.getChange().getProject());
|
||||
repoManager.openRepository(notes.getProjectName());
|
||||
RevWalk revWalk = new RevWalk(repo)) {
|
||||
return eventFactory.asPatchSetAttribute(
|
||||
revWalk, notes, patchSet);
|
||||
|
||||
@@ -213,7 +213,7 @@ public class ChangeUtil {
|
||||
}
|
||||
Change changeToRevert = db.get().changes().get(changeIdToRevert);
|
||||
|
||||
Project.NameKey project = ctl.getChange().getProject();
|
||||
Project.NameKey project = ctl.getProject().getNameKey();
|
||||
try (Repository git = gitManager.openRepository(project);
|
||||
RevWalk revWalk = new RevWalk(git)) {
|
||||
RevCommit commitToRevert =
|
||||
@@ -309,7 +309,7 @@ public class ChangeUtil {
|
||||
}
|
||||
|
||||
try (Repository git =
|
||||
gitManager.openRepository(notes.getChange().getProject());
|
||||
gitManager.openRepository(notes.getProjectName());
|
||||
RevWalk revWalk = new RevWalk(git)) {
|
||||
RevCommit commit = revWalk.parseCommit(
|
||||
ObjectId.fromString(ps.getRevision().get()));
|
||||
|
||||
@@ -96,10 +96,10 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
||||
final String msgTxt, final Account account)
|
||||
throws RestApiException, UpdateException {
|
||||
Op op = new Op(msgTxt, account);
|
||||
Change c = control.getChange();
|
||||
try (BatchUpdate u = batchUpdateFactory.create(dbProvider.get(),
|
||||
c.getProject(), control.getUser(), TimeUtil.nowTs())) {
|
||||
u.addOp(c.getId(), op).execute();
|
||||
control.getProject().getNameKey(), control.getUser(),
|
||||
TimeUtil.nowTs())) {
|
||||
u.addOp(control.getId(), op).execute();
|
||||
}
|
||||
return op.change;
|
||||
}
|
||||
|
||||
@@ -967,7 +967,7 @@ public class ChangeJson {
|
||||
|
||||
CommitInfo toCommit(ChangeControl ctl, RevWalk rw, RevCommit commit,
|
||||
boolean addLinks) throws IOException {
|
||||
Project.NameKey project = ctl.getChange().getProject();
|
||||
Project.NameKey project = ctl.getProject().getNameKey();
|
||||
CommitInfo info = new CommitInfo();
|
||||
info.parents = new ArrayList<>(commit.getParentCount());
|
||||
info.author = toGitPerson(commit.getAuthorIdent());
|
||||
|
||||
@@ -160,7 +160,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
}
|
||||
|
||||
private static Project.NameKey getProjectName(ChangeControl ctl) {
|
||||
return ctl.getChange().getDest().getParentKey();
|
||||
return ctl.getProject().getNameKey();
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
|
||||
@@ -137,6 +137,7 @@ public class TestChanges {
|
||||
IdentifiedUser user) throws OrmException {
|
||||
ChangeControl ctl = EasyMock.createMock(ChangeControl.class);
|
||||
expect(ctl.getChange()).andStubReturn(c);
|
||||
expect(ctl.getProject()).andStubReturn(new Project(c.getProject()));
|
||||
expect(ctl.getUser()).andStubReturn(user);
|
||||
ChangeNotes notes = new ChangeNotes(repoManager, migration, allUsers, c)
|
||||
.load();
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
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.server.ChangeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
@@ -167,8 +168,7 @@ public class SetReviewersCommand extends SshCommand {
|
||||
changeUtil.findChanges(id, userProvider.get());
|
||||
List<ChangeControl> toAdd = new ArrayList<>(changes.size());
|
||||
for (ChangeControl ctl : matched) {
|
||||
Change c = ctl.getChange();
|
||||
if (!changes.containsKey(c.getId()) && inProject(c)
|
||||
if (!changes.containsKey(ctl.getId()) && inProject(ctl.getProject())
|
||||
&& ctl.isVisible(db)) {
|
||||
toAdd.add(ctl);
|
||||
}
|
||||
@@ -187,9 +187,9 @@ public class SetReviewersCommand extends SshCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inProject(Change change) {
|
||||
private boolean inProject(Project project) {
|
||||
if (projectControl != null) {
|
||||
return projectControl.getProject().getNameKey().equals(change.getProject());
|
||||
return projectControl.getProject().getNameKey().equals(project.getNameKey());
|
||||
} else {
|
||||
// No --project option, so they want every project.
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user