ChangeNotesParser: Don't open the repository
This was left over from long before passing in a previously opened RevWalk; the repo that is opened is never used. With this change, ChangeNotesParser no longer needs to be AutoCloseable either. Change-Id: I46f2ddb6e81105635b7384012e33479ae4a2fd24
This commit is contained in:
@@ -548,9 +548,8 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
loadDefaults();
|
||||
return;
|
||||
}
|
||||
try (ChangeNotesParser parser = new ChangeNotesParser(
|
||||
project, change.getId(), rev, handle.walk(), args.repoManager,
|
||||
args.noteUtil, args.metrics)) {
|
||||
ChangeNotesParser parser = new ChangeNotesParser(
|
||||
change.getId(), rev, handle.walk(), args.noteUtil, args.metrics);
|
||||
parser.parseAll();
|
||||
|
||||
if (parser.status != null) {
|
||||
@@ -575,8 +574,8 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
change.setCurrentPatchSet(
|
||||
parser.currentPatchSetId, parser.subject, parser.originalSubject);
|
||||
} else {
|
||||
// TODO(dborowitz): This should be an error, but for now it's required
|
||||
// for some tests to pass.
|
||||
// TODO(dborowitz): This should be an error, but for now it's required for
|
||||
// some tests to pass.
|
||||
change.clearCurrentPatchSet();
|
||||
}
|
||||
|
||||
@@ -596,7 +595,6 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
||||
|
||||
submitRecords = ImmutableList.copyOf(parser.submitRecords);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDefaults() {
|
||||
|
||||
@@ -57,21 +57,17 @@ import com.google.gerrit.reviewdb.client.LabelId;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk;
|
||||
import com.google.gerrit.server.util.LabelVote;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.InvalidObjectIdException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.ObjectReader;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.notes.NoteMap;
|
||||
import org.eclipse.jgit.revwalk.FooterKey;
|
||||
import org.eclipse.jgit.util.RawParseUtils;
|
||||
@@ -92,7 +88,7 @@ import java.util.NavigableSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
class ChangeNotesParser implements AutoCloseable {
|
||||
class ChangeNotesParser {
|
||||
// Sentinel RevId indicating a mutable field on a patch set was parsed, but
|
||||
// the parser does not yet know its commit SHA-1.
|
||||
private static final RevId PARTIAL_PATCH_SET =
|
||||
@@ -125,20 +121,16 @@ class ChangeNotesParser implements AutoCloseable {
|
||||
private final Change.Id id;
|
||||
private final ObjectId tip;
|
||||
private final ChangeNotesRevWalk walk;
|
||||
private final Repository repo;
|
||||
private final Map<PatchSet.Id,
|
||||
Table<Account.Id, Entry<String, String>, Optional<PatchSetApproval>>> approvals;
|
||||
private final List<ChangeMessage> allChangeMessages;
|
||||
private final Multimap<PatchSet.Id, ChangeMessage> changeMessagesByPatchSet;
|
||||
|
||||
ChangeNotesParser(Project.NameKey project, Change.Id changeId, ObjectId tip,
|
||||
ChangeNotesRevWalk walk, GitRepositoryManager repoManager,
|
||||
ChangeNoteUtil noteUtil, NoteDbMetrics metrics)
|
||||
throws RepositoryNotFoundException, IOException {
|
||||
ChangeNotesParser(Change.Id changeId, ObjectId tip, ChangeNotesRevWalk walk,
|
||||
ChangeNoteUtil noteUtil, NoteDbMetrics metrics) {
|
||||
this.id = changeId;
|
||||
this.tip = tip;
|
||||
this.walk = walk;
|
||||
this.repo = repoManager.openRepository(project);
|
||||
this.noteUtil = noteUtil;
|
||||
this.metrics = metrics;
|
||||
approvals = new HashMap<>();
|
||||
@@ -152,11 +144,6 @@ class ChangeNotesParser implements AutoCloseable {
|
||||
patchSetStates = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
repo.close();
|
||||
}
|
||||
|
||||
void parseAll() throws ConfigInvalidException, IOException {
|
||||
// Don't include initial parse in timer, as this might do more I/O to page
|
||||
// in the block containing most commits. Later reads are not guaranteed to
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.notedb;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
@@ -482,9 +481,7 @@ public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||
}
|
||||
|
||||
private void assertParseSucceeds(RevCommit commit) throws Exception {
|
||||
try (ChangeNotesParser parser = newParser(commit)) {
|
||||
parser.parseAll();
|
||||
}
|
||||
newParser(commit).parseAll();
|
||||
}
|
||||
|
||||
private void assertParseFails(String body) throws Exception {
|
||||
@@ -492,8 +489,8 @@ public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||
}
|
||||
|
||||
private void assertParseFails(RevCommit commit) throws Exception {
|
||||
try (ChangeNotesParser parser = newParser(commit)) {
|
||||
parser.parseAll();
|
||||
try {
|
||||
newParser(commit).parseAll();
|
||||
fail("Expected parse to fail:\n" + commit.getFullMessage());
|
||||
} catch (ConfigInvalidException e) {
|
||||
// Expected
|
||||
@@ -501,8 +498,7 @@ public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||
}
|
||||
|
||||
private ChangeNotesParser newParser(ObjectId tip) throws Exception {
|
||||
Change c = newChange();
|
||||
return new ChangeNotesParser(c.getProject(), c.getId(), tip, walk,
|
||||
repoManager, noteUtil, args.metrics);
|
||||
return new ChangeNotesParser(
|
||||
newChange().getId(), tip, walk, noteUtil, args.metrics);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1018,21 +1018,18 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
assertThat(commitWithComments).isNotNull();
|
||||
|
||||
try (ChangeNotesRevWalk rw = ChangeNotesCommit.newRevWalk(repo)) {
|
||||
try (ChangeNotesParser notesWithComments = new ChangeNotesParser(
|
||||
project, c.getId(), commitWithComments.copy(), rw, repoManager,
|
||||
noteUtil, args.metrics)) {
|
||||
ChangeNotesParser notesWithComments = new ChangeNotesParser(
|
||||
c.getId(), commitWithComments.copy(), rw, noteUtil, args.metrics);
|
||||
notesWithComments.parseAll();
|
||||
ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals1 =
|
||||
notesWithComments.buildApprovals();
|
||||
assertThat(approvals1).isEmpty();
|
||||
assertThat(notesWithComments.comments).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
try (ChangeNotesRevWalk rw = ChangeNotesCommit.newRevWalk(repo)) {
|
||||
try (ChangeNotesParser notesWithApprovals = new ChangeNotesParser(project,
|
||||
c.getId(), commitWithApprovals.copy(), rw, repoManager,
|
||||
noteUtil, args.metrics)) {
|
||||
ChangeNotesParser notesWithApprovals = new ChangeNotesParser(c.getId(),
|
||||
commitWithApprovals.copy(), rw, noteUtil, args.metrics);
|
||||
notesWithApprovals.parseAll();
|
||||
ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals2 =
|
||||
notesWithApprovals.buildApprovals();
|
||||
@@ -1040,7 +1037,6 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
|
||||
assertThat(notesWithApprovals.comments).hasSize(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleUpdatesAcrossRefs() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user