Clean up dead code in NoteDbUpdateManager
Remove completely unused methods. This includes methods to set some booleans to non-default values, so also clean up conditionals involving those booleans. Change-Id: Ifd46b5f4f2a868056af723527c223a2dbee0c98c
This commit is contained in:
@@ -73,8 +73,6 @@ import org.eclipse.jgit.transport.ReceiveCommand;
|
|||||||
* {@link #stage()}.
|
* {@link #stage()}.
|
||||||
*/
|
*/
|
||||||
public class NoteDbUpdateManager implements AutoCloseable {
|
public class NoteDbUpdateManager implements AutoCloseable {
|
||||||
public static final String CHANGES_READ_ONLY = "NoteDb changes are read-only";
|
|
||||||
|
|
||||||
private static final ImmutableList<String> PACKAGE_PREFIXES =
|
private static final ImmutableList<String> PACKAGE_PREFIXES =
|
||||||
ImmutableList.of("com.google.gerrit.server.", "com.google.gerrit.");
|
ImmutableList.of("com.google.gerrit.server.", "com.google.gerrit.");
|
||||||
private static final ImmutableSet<String> SERVLET_NAMES =
|
private static final ImmutableSet<String> SERVLET_NAMES =
|
||||||
@@ -95,15 +93,13 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
@Nullable private final ObjectInserter finalIns;
|
@Nullable private final ObjectInserter finalIns;
|
||||||
|
|
||||||
private final boolean close;
|
private final boolean close;
|
||||||
private final boolean saveObjects;
|
|
||||||
|
|
||||||
private OpenRepo(
|
private OpenRepo(
|
||||||
Repository repo,
|
Repository repo,
|
||||||
RevWalk rw,
|
RevWalk rw,
|
||||||
@Nullable ObjectInserter ins,
|
@Nullable ObjectInserter ins,
|
||||||
ChainedReceiveCommands cmds,
|
ChainedReceiveCommands cmds,
|
||||||
boolean close,
|
boolean close) {
|
||||||
boolean saveObjects) {
|
|
||||||
ObjectReader reader = rw.getObjectReader();
|
ObjectReader reader = rw.getObjectReader();
|
||||||
checkArgument(
|
checkArgument(
|
||||||
ins == null || reader.getCreatedFromInserter() == ins,
|
ins == null || reader.getCreatedFromInserter() == ins,
|
||||||
@@ -112,40 +108,25 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
reader.getCreatedFromInserter());
|
reader.getCreatedFromInserter());
|
||||||
this.repo = requireNonNull(repo);
|
this.repo = requireNonNull(repo);
|
||||||
|
|
||||||
if (saveObjects) {
|
|
||||||
this.inMemIns = new InMemoryInserter(rw.getObjectReader());
|
this.inMemIns = new InMemoryInserter(rw.getObjectReader());
|
||||||
this.tempIns = inMemIns;
|
this.tempIns = inMemIns;
|
||||||
} else {
|
|
||||||
checkArgument(ins != null);
|
|
||||||
this.inMemIns = null;
|
|
||||||
this.tempIns = ins;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rw = new RevWalk(tempIns.newReader());
|
this.rw = new RevWalk(tempIns.newReader());
|
||||||
this.finalIns = ins;
|
this.finalIns = ins;
|
||||||
this.cmds = requireNonNull(cmds);
|
this.cmds = requireNonNull(cmds);
|
||||||
this.close = close;
|
this.close = close;
|
||||||
this.saveObjects = saveObjects;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ObjectId> getObjectId(String refName) throws IOException {
|
public Optional<ObjectId> getObjectId(String refName) throws IOException {
|
||||||
return cmds.get(refName);
|
return cmds.get(refName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
ImmutableList<InsertedObject> getInsertedObjects() {
|
|
||||||
return saveObjects ? inMemIns.getInsertedObjects() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void flush() throws IOException {
|
void flush() throws IOException {
|
||||||
flushToFinalInserter();
|
flushToFinalInserter();
|
||||||
finalIns.flush();
|
finalIns.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void flushToFinalInserter() throws IOException {
|
void flushToFinalInserter() throws IOException {
|
||||||
if (!saveObjects) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
checkState(finalIns != null);
|
checkState(finalIns != null);
|
||||||
for (InsertedObject obj : inMemIns.getInsertedObjects()) {
|
for (InsertedObject obj : inMemIns.getInsertedObjects()) {
|
||||||
finalIns.insert(obj.type(), obj.data().toByteArray());
|
finalIns.insert(obj.type(), obj.data().toByteArray());
|
||||||
@@ -180,9 +161,6 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
private OpenRepo changeRepo;
|
private OpenRepo changeRepo;
|
||||||
private OpenRepo allUsersRepo;
|
private OpenRepo allUsersRepo;
|
||||||
private boolean executed;
|
private boolean executed;
|
||||||
private boolean checkExpectedState = true;
|
|
||||||
private boolean saveObjects = true;
|
|
||||||
private boolean atomicRefUpdates = true;
|
|
||||||
private String refLogMessage;
|
private String refLogMessage;
|
||||||
private PersonIdent refLogIdent;
|
private PersonIdent refLogIdent;
|
||||||
private PushCertificate pushCert;
|
private PushCertificate pushCert;
|
||||||
@@ -226,33 +204,7 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
public NoteDbUpdateManager setChangeRepo(
|
public NoteDbUpdateManager setChangeRepo(
|
||||||
Repository repo, RevWalk rw, @Nullable ObjectInserter ins, ChainedReceiveCommands cmds) {
|
Repository repo, RevWalk rw, @Nullable ObjectInserter ins, ChainedReceiveCommands cmds) {
|
||||||
checkState(changeRepo == null, "change repo already initialized");
|
checkState(changeRepo == null, "change repo already initialized");
|
||||||
changeRepo = new OpenRepo(repo, rw, ins, cmds, false, saveObjects);
|
changeRepo = new OpenRepo(repo, rw, ins, cmds, false);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoteDbUpdateManager setAllUsersRepo(
|
|
||||||
Repository repo, RevWalk rw, @Nullable ObjectInserter ins, ChainedReceiveCommands cmds) {
|
|
||||||
checkState(allUsersRepo == null, "All-Users repo already initialized");
|
|
||||||
allUsersRepo = new OpenRepo(repo, rw, ins, cmds, false, saveObjects);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoteDbUpdateManager setCheckExpectedState(boolean checkExpectedState) {
|
|
||||||
this.checkExpectedState = checkExpectedState;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether to use atomic ref updates.
|
|
||||||
*
|
|
||||||
* <p>Can be set to false when the change updates represented by this manager aren't logically
|
|
||||||
* related, e.g. when the updater is only used to group objects together with a single inserter.
|
|
||||||
*
|
|
||||||
* @param atomicRefUpdates whether to use atomic ref updates; defaults to true.
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public NoteDbUpdateManager setAtomicRefUpdates(boolean atomicRefUpdates) {
|
|
||||||
this.atomicRefUpdates = atomicRefUpdates;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,16 +237,6 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenRepo getChangeRepo() throws IOException {
|
|
||||||
initChangeRepo();
|
|
||||||
return changeRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OpenRepo getAllUsersRepo() throws IOException {
|
|
||||||
initAllUsersRepo();
|
|
||||||
return allUsersRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initChangeRepo() throws IOException {
|
private void initChangeRepo() throws IOException {
|
||||||
if (changeRepo == null) {
|
if (changeRepo == null) {
|
||||||
changeRepo = openRepo(projectName);
|
changeRepo = openRepo(projectName);
|
||||||
@@ -312,7 +254,7 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
ObjectInserter ins = repo.newObjectInserter(); // Closed by OpenRepo#close.
|
ObjectInserter ins = repo.newObjectInserter(); // Closed by OpenRepo#close.
|
||||||
ObjectReader reader = ins.newReader(); // Not closed by OpenRepo#close.
|
ObjectReader reader = ins.newReader(); // Not closed by OpenRepo#close.
|
||||||
try (RevWalk rw = new RevWalk(reader)) { // Doesn't escape OpenRepo constructor.
|
try (RevWalk rw = new RevWalk(reader)) { // Doesn't escape OpenRepo constructor.
|
||||||
return new OpenRepo(repo, rw, ins, new ChainedReceiveCommands(repo), true, saveObjects) {
|
return new OpenRepo(repo, rw, ins, new ChainedReceiveCommands(repo), true) {
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
reader.close();
|
reader.close();
|
||||||
@@ -489,7 +431,7 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
bru.setRefLogMessage(firstNonNull(guessRestApiHandler(), "Update NoteDb refs"), false);
|
bru.setRefLogMessage(firstNonNull(guessRestApiHandler(), "Update NoteDb refs"), false);
|
||||||
}
|
}
|
||||||
bru.setRefLogIdent(refLogIdent != null ? refLogIdent : serverIdent.get());
|
bru.setRefLogIdent(refLogIdent != null ? refLogIdent : serverIdent.get());
|
||||||
bru.setAtomic(atomicRefUpdates);
|
bru.setAtomic(true);
|
||||||
or.cmds.addTo(bru);
|
or.cmds.addTo(bru);
|
||||||
bru.setAllowNonFastForwards(true);
|
bru.setAllowNonFastForwards(true);
|
||||||
|
|
||||||
@@ -596,10 +538,6 @@ public class NoteDbUpdateManager implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkExpectedState() throws OrmException, IOException {
|
private void checkExpectedState() throws OrmException, IOException {
|
||||||
if (!checkExpectedState) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refuse to apply an update unless the state in NoteDb matches the state
|
// Refuse to apply an update unless the state in NoteDb matches the state
|
||||||
// claimed in the ref. This means we may have failed a NoteDb ref update,
|
// claimed in the ref. This means we may have failed a NoteDb ref update,
|
||||||
// and it would be incorrect to claim that the ref is up to date after this
|
// and it would be incorrect to claim that the ref is up to date after this
|
||||||
|
|||||||
Reference in New Issue
Block a user