Pass RevWalk to PatchSetInfoFactory

Previously #get(RevCommit, PatchSet.Id) would NPE if the body of the
commit was not parsed; callers needed to remember to either parse the
body or ensure that the RevWalk that created the commit had
setRetainBody(true). In all cases, there is already a handy RevWalk;
pass this into get and do the parseBody there, such that it's
impossible for the caller to forget. (In the BatchUpdate.Op cases, we
need to shuffle call order around a bit so the PatchSetInfo gets
populated during updateRepo.)

Change-Id: I2e42ed1cc5c4a50958b6367051065e6bbad5cc54
This commit is contained in:
Dave Borowitz
2015-10-14 15:12:43 -04:00
parent 8408244c21
commit b9805aee6d
7 changed files with 28 additions and 20 deletions

View File

@@ -78,6 +78,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
private static final Logger log =
LoggerFactory.getLogger(ChangeInserter.class);
private final PatchSetInfoFactory patchSetInfoFactory;
private final ChangeHooks hooks;
private final ApprovalsUtil approvalsUtil;
private final ChangeMessagesUtil cmUtil;
@@ -92,7 +93,6 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
private final Change change;
private final PatchSet patchSet;
private final RevCommit commit;
private final PatchSetInfo patchSetInfo;
// Fields exposed as setters.
private String message;
@@ -109,6 +109,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
// Fields set during the insertion process.
private ChangeMessage changeMessage;
private PatchSetInfo patchSetInfo;
@Inject
ChangeInserter(PatchSetInfoFactory patchSetInfoFactory,
@@ -130,6 +131,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
"RefControl for %s,%s does not match change destination %s",
projectName, refName, change.getDest());
this.patchSetInfoFactory = patchSetInfoFactory;
this.hooks = hooks;
this.approvalsUtil = approvalsUtil;
this.cmUtil = cmUtil;
@@ -156,8 +158,6 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
patchSet.setCreatedOn(change.getCreatedOn());
patchSet.setUploader(change.getOwner());
patchSet.setRevision(new RevId(commit.name()));
patchSetInfo = patchSetInfoFactory.get(commit, patchSet.getId());
change.setCurrentPatchSet(patchSetInfo);
}
private static IdentifiedUser checkUser(RefControl ctl) {
@@ -240,10 +240,6 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
return this;
}
public PatchSetInfo getPatchSetInfo() {
return patchSetInfo;
}
public ChangeMessage getChangeMessage() {
if (message == null) {
return null;
@@ -257,6 +253,9 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
public void updateRepo(RepoContext ctx)
throws InvalidChangeOperationException, IOException {
validate(ctx);
patchSetInfo = patchSetInfoFactory.get(
ctx.getRevWalk(), commit, patchSet.getId());
change.setCurrentPatchSet(patchSetInfo);
if (!updateRef) {
return;
}