Merge "Remove superfluous/misleading methods from ChangeEdit"

This commit is contained in:
ekempin
2017-03-30 12:10:40 +00:00
committed by Gerrit Code Review
11 changed files with 36 additions and 70 deletions

View File

@@ -35,6 +35,7 @@ import java.util.Optional;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.lib.ObjectId;
/**
* Exports a single version of a patch as a normal file download.
@@ -126,7 +127,7 @@ public class CatServlet extends HttpServlet {
try {
Optional<ChangeEdit> edit = changeEditUtil.byChange(control.getChange());
if (edit.isPresent()) {
revision = edit.get().getRevision().get();
revision = ObjectId.toString(edit.get().getEditCommit());
} else {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;

View File

@@ -16,8 +16,6 @@ package com.google.gerrit.server.change;
import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.edit.ChangeEdit;
import com.google.gerrit.server.project.ChangeControl;
import com.google.inject.TypeLiteral;
@@ -67,12 +65,4 @@ public class ChangeEditResource implements RestResource {
public String getPath() {
return path;
}
Account.Id getAccountId() {
return getUser().getAccountId();
}
IdentifiedUser getUser() {
return edit.getUser();
}
}

View File

@@ -229,7 +229,8 @@ public class ChangeEdits
}
try {
editInfo.files =
fileInfoJson.toFileInfoMap(rsrc.getChange(), edit.get().getRevision(), basePatchSet);
fileInfoJson.toFileInfoMap(
rsrc.getChange(), edit.get().getEditCommit(), basePatchSet);
} catch (PatchListNotAvailableException e) {
throw new ResourceNotFoundException(e.getMessage());
}
@@ -395,7 +396,7 @@ public class ChangeEdits
rsrc.getControl().getProjectControl().getProjectState(),
base
? ObjectId.fromString(edit.getBasePatchSet().getRevision().get())
: ObjectId.fromString(edit.getRevision().get()),
: edit.getEditCommit(),
rsrc.getPath()));
} catch (ResourceNotFoundException rnfe) {
return Response.none();

View File

@@ -48,9 +48,14 @@ public class FileInfoJson {
Map<String, FileInfo> toFileInfoMap(Change change, RevId revision, @Nullable PatchSet base)
throws PatchListNotAvailableException {
ObjectId objectId = ObjectId.fromString(revision.get());
return toFileInfoMap(change, objectId, base);
}
Map<String, FileInfo> toFileInfoMap(Change change, ObjectId objectId, @Nullable PatchSet base)
throws PatchListNotAvailableException {
ObjectId a = (base == null) ? null : ObjectId.fromString(base.getRevision().get());
ObjectId b = ObjectId.fromString(revision.get());
return toFileInfoMap(change, new PatchListKey(a, b, Whitespace.IGNORE_NONE));
return toFileInfoMap(change, new PatchListKey(a, objectId, Whitespace.IGNORE_NONE));
}
Map<String, FileInfo> toFileInfoMap(Change change, RevId revision, int parent)

View File

@@ -96,7 +96,8 @@ public class PublishChangeEdit
if (in == null) {
in = new PublishChangeEditInput();
}
editUtil.publish(edit.get(), in.notify, notifyUtil.resolveAccounts(in.notifyDetails));
editUtil.publish(
rsrc.getControl(), edit.get(), in.notify, notifyUtil.resolveAccounts(in.notifyDetails));
return Response.none();
}
}

View File

@@ -37,6 +37,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
@Singleton
public class Revisions implements ChildCollection<ChangeResource, RevisionResource> {
@@ -143,8 +144,9 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
Optional<ChangeEdit> edit = editUtil.byChange(change.getChange());
if (edit.isPresent()) {
PatchSet ps = new PatchSet(new PatchSet.Id(change.getId(), 0));
ps.setRevision(edit.get().getRevision());
if (revid == null || edit.get().getRevision().equals(revid)) {
RevId editRevId = new RevId(ObjectId.toString(edit.get().getEditCommit()));
ps.setRevision(editRevId);
if (revid == null || editRevId.equals(revid)) {
return Collections.singletonList(new RevisionResource(change, ps, edit));
}
}

View File

@@ -18,11 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.server.IdentifiedUser;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.RevCommit;
/**
@@ -33,44 +28,25 @@ import org.eclipse.jgit.revwalk.RevCommit;
* change number and P is the patch set number it is based on.
*/
public class ChangeEdit {
private final IdentifiedUser user;
private final Change change;
private final Ref ref;
private final String editRefName;
private final RevCommit editCommit;
private final PatchSet basePatchSet;
public ChangeEdit(
IdentifiedUser user, Change change, Ref ref, RevCommit editCommit, PatchSet basePatchSet) {
checkNotNull(user);
checkNotNull(change);
checkNotNull(ref);
checkNotNull(editCommit);
checkNotNull(basePatchSet);
this.user = user;
this.change = change;
this.ref = ref;
this.editCommit = editCommit;
this.basePatchSet = basePatchSet;
Change change, String editRefName, RevCommit editCommit, PatchSet basePatchSet) {
this.change = checkNotNull(change);
this.editRefName = checkNotNull(editRefName);
this.editCommit = checkNotNull(editCommit);
this.basePatchSet = checkNotNull(basePatchSet);
}
public Change getChange() {
return change;
}
public IdentifiedUser getUser() {
return user;
}
public Ref getRef() {
return ref;
}
public RevId getRevision() {
return new RevId(ObjectId.toString(ref.getObjectId()));
}
public String getRefName() {
return RefNames.refsEdit(user.getAccountId(), change.getId(), basePatchSet.getId());
return editRefName;
}
public RevCommit getEditCommit() {

View File

@@ -52,7 +52,6 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.MergeStrategy;
@@ -531,9 +530,7 @@ public class ChangeEditModifier {
reindex(change);
RevCommit newEditCommit = lookupCommit(repository, newEditCommitId);
Ref ref = repository.getRefDatabase().exactRef(editRefName);
return new ChangeEdit(
currentUser.get().asIdentifiedUser(), change, ref, newEditCommit, basePatchSet);
return new ChangeEdit(change, editRefName, newEditCommit, basePatchSet);
}
private String getEditRefName(Change change, PatchSet basePatchSet) {
@@ -551,11 +548,7 @@ public class ChangeEditModifier {
RevCommit newEditCommit = lookupCommit(repository, newEditCommitId);
return new ChangeEdit(
changeEdit.getUser(),
changeEdit.getChange(),
changeEdit.getRef(),
newEditCommit,
changeEdit.getBasePatchSet());
changeEdit.getChange(), editRefName, newEditCommit, changeEdit.getBasePatchSet());
}
private void updateReference(

View File

@@ -149,7 +149,7 @@ public class ChangeEditUtil {
try (RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(ref.getObjectId());
PatchSet basePs = getBasePatchSet(ctl, ref);
return Optional.of(new ChangeEdit(u, change, ref, commit, basePs));
return Optional.of(new ChangeEdit(change, ref.getName(), commit, basePs));
}
}
}
@@ -157,6 +157,7 @@ public class ChangeEditUtil {
/**
* Promote change edit to patch set, by squashing the edit into its parent.
*
* @param ctl the {@code ChangeControl} of the change to which the change edit belongs
* @param edit change edit to publish
* @param notify Notify handling that defines to whom email notifications should be sent after the
* change edit is published.
@@ -167,6 +168,7 @@ public class ChangeEditUtil {
* @throws RestApiException
*/
public void publish(
ChangeControl ctl,
final ChangeEdit edit,
NotifyHandling notify,
ListMultimap<RecipientType, Account.Id> accountsToNotify)
@@ -181,7 +183,6 @@ public class ChangeEditUtil {
}
RevCommit squashed = squashEdit(rw, oi, edit.getEditCommit(), basePatchSet);
ChangeControl ctl = changeControlFactory.controlFor(db.get(), change, edit.getUser());
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
PatchSetInserter inserter =
patchSetInserterFactory
@@ -280,7 +281,7 @@ public class ChangeEditUtil {
private static void deleteRef(Repository repo, ChangeEdit edit) throws IOException {
String refName = edit.getRefName();
RefUpdate ru = repo.updateRef(refName, true);
ru.setExpectedOldObjectId(edit.getRef().getObjectId());
ru.setExpectedOldObjectId(edit.getEditCommit());
ru.setForceUpdate(true);
RefUpdate.Result result = ru.delete();
switch (result) {

View File

@@ -2481,13 +2481,12 @@ public class ReceiveCommits {
if (edit.get().getBasePatchSet().getId().equals(psId)) {
// replace edit
cmd =
new ReceiveCommand(
edit.get().getRef().getObjectId(), newCommitId, edit.get().getRefName());
new ReceiveCommand(edit.get().getEditCommit(), newCommitId, edit.get().getRefName());
} else {
// delete old edit ref on rebase
prev =
new ReceiveCommand(
edit.get().getRef().getObjectId(), ObjectId.zeroId(), edit.get().getRefName());
edit.get().getEditCommit(), ObjectId.zeroId(), edit.get().getRefName());
createEditCommand();
}
} else {

View File

@@ -253,9 +253,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
return b;
}
private ObjectId toObjectId(PatchSet ps)
throws NoSuchChangeException, AuthException, NoSuchChangeException, IOException,
OrmException {
private ObjectId toObjectId(PatchSet ps) throws AuthException, IOException, OrmException {
if (ps.getId().get() == 0) {
return getEditRev();
}
@@ -271,11 +269,10 @@ public class PatchScriptFactory implements Callable<PatchScript> {
}
}
private ObjectId getEditRev()
throws AuthException, NoSuchChangeException, IOException, OrmException {
private ObjectId getEditRev() throws AuthException, IOException, OrmException {
edit = editReader.byChange(change);
if (edit.isPresent()) {
return edit.get().getRef().getObjectId();
return edit.get().getEditCommit();
}
throw new NoSuchChangeException(change.getId());
}