RepoContext: Add convenience method for addRefUpdate
Most callers are immediately constructing a ReceiveCommand, so this variant reduces boilerplate. A few callers want to maintain a reference to the ReceiveCommand, so keep the other variant around. Change-Id: Ia6cb0f7fc63eba380a225c671def41db3caffc44
This commit is contained in:
@@ -341,7 +341,7 @@ public class ChangeInserter implements InsertChangeOp {
|
||||
return;
|
||||
}
|
||||
if (updateRefCommand == null) {
|
||||
ctx.addRefUpdate(new ReceiveCommand(ObjectId.zeroId(), commitId, psId.toRefName()));
|
||||
ctx.addRefUpdate(ObjectId.zeroId(), commitId, psId.toRefName());
|
||||
} else {
|
||||
ctx.addRefUpdate(updateRefCommand);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ import org.eclipse.jgit.lib.RefUpdate;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -504,8 +503,7 @@ public class ConsistencyChecker {
|
||||
new BatchUpdateOp() {
|
||||
@Override
|
||||
public void updateRepo(RepoContext ctx) throws IOException {
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(commit, ObjectId.zeroId(), psIdToDelete.toRefName()));
|
||||
ctx.addRefUpdate(commit, ObjectId.zeroId(), psIdToDelete.toRefName());
|
||||
}
|
||||
});
|
||||
if (!reuseOldPsId) {
|
||||
|
||||
@@ -43,7 +43,6 @@ import java.util.Optional;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
|
||||
class DeleteChangeOp implements BatchUpdateOp {
|
||||
static boolean allowDrafts(Config cfg) {
|
||||
@@ -173,7 +172,7 @@ class DeleteChangeOp implements BatchUpdateOp {
|
||||
String prefix = new PatchSet.Id(id, 1).toRefName();
|
||||
prefix = prefix.substring(0, prefix.length() - 1);
|
||||
for (Map.Entry<String, ObjectId> e : ctx.getRepoView().getRefs(prefix).entrySet()) {
|
||||
ctx.addRefUpdate(new ReceiveCommand(e.getValue(), ObjectId.zeroId(), prefix + e.getKey()));
|
||||
ctx.addRefUpdate(e.getValue(), ObjectId.zeroId(), prefix + e.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
|
||||
@Singleton
|
||||
public class DeleteDraftPatchSet
|
||||
@@ -133,10 +132,9 @@ public class DeleteDraftPatchSet
|
||||
return;
|
||||
}
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(
|
||||
ObjectId.fromString(patchSet.getRevision().get()),
|
||||
ObjectId.zeroId(),
|
||||
patchSet.getRefName()));
|
||||
ObjectId.fromString(patchSet.getRevision().get()),
|
||||
ObjectId.zeroId(),
|
||||
patchSet.getRefName());
|
||||
}
|
||||
|
||||
private void deleteDraftPatchSet(PatchSet patchSet, ChangeContext ctx) throws OrmException {
|
||||
|
||||
@@ -207,9 +207,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
public void updateRepo(RepoContext ctx)
|
||||
throws AuthException, ResourceConflictException, IOException, OrmException {
|
||||
validate(ctx);
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(
|
||||
ObjectId.zeroId(), commitId, getPatchSetId().toRefName(), ReceiveCommand.Type.CREATE));
|
||||
ctx.addRefUpdate(ObjectId.zeroId(), commitId, getPatchSetId().toRefName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,7 +59,6 @@ import org.eclipse.jgit.lib.RefUpdate;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
|
||||
/**
|
||||
* Utility functions to manipulate change edits.
|
||||
@@ -223,9 +222,7 @@ public class ChangeEditUtil {
|
||||
new BatchUpdateOp() {
|
||||
@Override
|
||||
public void updateRepo(RepoContext ctx) throws Exception {
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(
|
||||
edit.getEditCommit().copy(), ObjectId.zeroId(), edit.getRefName()));
|
||||
ctx.addRefUpdate(edit.getEditCommit().copy(), ObjectId.zeroId(), edit.getRefName());
|
||||
}
|
||||
});
|
||||
bu.execute();
|
||||
|
||||
@@ -71,7 +71,6 @@ import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.PushCertificate;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -211,7 +210,7 @@ public class ReplaceOp implements BatchUpdateOp {
|
||||
}
|
||||
|
||||
if (updateRef) {
|
||||
ctx.addRefUpdate(new ReceiveCommand(ObjectId.zeroId(), commitId, patchSetId.toRefName()));
|
||||
ctx.addRefUpdate(ObjectId.zeroId(), commitId, patchSetId.toRefName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
import org.eclipse.jgit.transport.RefSpec;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -82,7 +81,7 @@ public class SubmoduleOp {
|
||||
public void updateRepo(RepoContext ctx) throws Exception {
|
||||
CodeReviewCommit c = composeGitlinksCommit(branch);
|
||||
if (c != null) {
|
||||
ctx.addRefUpdate(new ReceiveCommand(c.getParent(0), c, branch.get()));
|
||||
ctx.addRefUpdate(c.getParent(0), c, branch.get());
|
||||
addBranchTip(branch, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import java.util.List;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
|
||||
public class CherryPick extends SubmitStrategy {
|
||||
|
||||
@@ -135,7 +134,7 @@ public class CherryPick extends SubmitStrategy {
|
||||
args.mergeTip.moveTipTo(newCommit, newCommit);
|
||||
args.commitStatus.put(newCommit);
|
||||
|
||||
ctx.addRefUpdate(new ReceiveCommand(ObjectId.zeroId(), newCommit, psId.toRefName()));
|
||||
ctx.addRefUpdate(ObjectId.zeroId(), newCommit, psId.toRefName());
|
||||
patchSetInfo = args.patchSetInfoFactory.get(ctx.getRevWalk(), newCommit, psId);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
|
||||
/** This strategy covers RebaseAlways and RebaseIfNecessary ones. */
|
||||
public class RebaseSubmitStrategy extends SubmitStrategy {
|
||||
@@ -156,8 +155,7 @@ public class RebaseSubmitStrategy extends SubmitStrategy {
|
||||
toMerge.setStatusCode(SKIPPED_IDENTICAL_TREE);
|
||||
return;
|
||||
}
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(ObjectId.zeroId(), newCommit, newPatchSetId.toRefName()));
|
||||
ctx.addRefUpdate(ObjectId.zeroId(), newCommit, newPatchSetId.toRefName());
|
||||
} else {
|
||||
// Stale read of patch set is ok; see comments in RebaseChangeOp.
|
||||
PatchSet origPs =
|
||||
|
||||
@@ -14,10 +14,12 @@
|
||||
|
||||
package com.google.gerrit.server.update;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.ObjectInserter;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/** Context for performing the {@link BatchUpdateOp#updateRepo} phase. */
|
||||
public interface RepoContext extends Context {
|
||||
/**
|
||||
@@ -31,10 +33,28 @@ public interface RepoContext extends Context {
|
||||
/**
|
||||
* Add a command to the pending list of commands.
|
||||
*
|
||||
* <p>This method is the only way of updating refs in the repository from a {@link BatchUpdateOp}.
|
||||
* <p>Adding commands to the {@code RepoContext} is the only way of updating refs in the
|
||||
* repository from a {@link BatchUpdateOp}.
|
||||
*
|
||||
* @param cmd ref update command.
|
||||
* @throws IOException if an error occurred opening the repo.
|
||||
*/
|
||||
void addRefUpdate(ReceiveCommand cmd) throws IOException;
|
||||
|
||||
/**
|
||||
* Add a command to the pending list of commands.
|
||||
*
|
||||
* <p>Adding commands to the {@code RepoContext} is the only way of updating refs in the
|
||||
* repository from a {@link BatchUpdateOp}.
|
||||
*
|
||||
* @param oldId the old object ID; must not be null. Use {@link ObjectId#zeroId()} for ref
|
||||
* creation.
|
||||
* @param newId the new object ID; must not be null. Use {@link ObjectId#zeroId()} for ref
|
||||
* deletion.
|
||||
* @param refName the ref name.
|
||||
* @throws IOException if an error occurred opening the repo.
|
||||
*/
|
||||
default void addRefUpdate(ObjectId oldId, ObjectId newId, String refName) throws IOException {
|
||||
addRefUpdate(new ReceiveCommand(oldId, newId, refName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.google.inject.util.Providers;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -122,9 +121,7 @@ public class BatchUpdateTest {
|
||||
new RepoOnlyOp() {
|
||||
@Override
|
||||
public void updateRepo(RepoContext ctx) throws Exception {
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(
|
||||
masterCommit.getId(), branchCommit.getId(), "refs/heads/master"));
|
||||
ctx.addRefUpdate(masterCommit.getId(), branchCommit.getId(), "refs/heads/master");
|
||||
}
|
||||
});
|
||||
bu.execute();
|
||||
|
||||
Reference in New Issue
Block a user