Factor parser class out of DraftCommentNotes

Change-Id: Ib7b1eee4ff6aca706dd7b9b301fd6e7882f40431
This commit is contained in:
Dave Borowitz
2014-08-07 17:12:27 -07:00
parent bac28cbfe2
commit 799aa808ed
2 changed files with 74 additions and 44 deletions

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.notedb;
import static com.google.gerrit.server.notedb.CommentsInNotesUtil.getCommentPsId;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Multimap;
import com.google.common.collect.Table;
@@ -25,7 +24,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.PatchLineComment.Status;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.config.AllUsersName;
@@ -35,10 +33,8 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.notes.NoteMap;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -68,44 +64,6 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
}
}
private static class Parser implements AutoCloseable {
private final Change.Id changeId;
private final ObjectId tip;
private final RevWalk walk;
private final Repository repo;
private final Account.Id author;
private final Multimap<PatchSet.Id, PatchLineComment> draftBaseComments;
private final Multimap<PatchSet.Id, PatchLineComment> draftPsComments;
private NoteMap noteMap;
private Parser(Change.Id changeId, RevWalk walk, ObjectId tip,
GitRepositoryManager repoManager, AllUsersName draftsProject,
Account.Id author) throws RepositoryNotFoundException, IOException {
this.changeId = changeId;
this.walk = walk;
this.tip = tip;
this.repo = repoManager.openRepository(draftsProject);
this.author = author;
draftBaseComments = ArrayListMultimap.create();
draftPsComments = ArrayListMultimap.create();
}
@Override
public void close() {
repo.close();
}
private void parseDraftComments() throws IOException, ConfigInvalidException {
walk.markStart(walk.parseCommit(tip));
noteMap = CommentsInNotesUtil.parseCommentsFromNotes(repo,
RefNames.refsDraftComments(author, changeId),
walk, changeId, draftBaseComments,
draftPsComments, Status.DRAFT);
}
}
private final AllUsersName draftsProject;
private final Account.Id author;
@@ -172,8 +130,8 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
}
RevWalk walk = new RevWalk(reader);
try (Parser parser = new Parser(getChangeId(), walk, rev, repoManager,
draftsProject, author)) {
try (DraftCommentNotesParser parser = new DraftCommentNotesParser(
getChangeId(), walk, rev, repoManager, draftsProject, author)) {
parser.parseDraftComments();
buildCommentTable(draftBaseComments, parser.draftBaseComments);

View File

@@ -0,0 +1,72 @@
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.notedb;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.git.GitRepositoryManager;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.notes.NoteMap;
import org.eclipse.jgit.revwalk.RevWalk;
import java.io.IOException;
class DraftCommentNotesParser implements AutoCloseable {
final Multimap<PatchSet.Id, PatchLineComment> draftBaseComments;
final Multimap<PatchSet.Id, PatchLineComment> draftPsComments;
NoteMap noteMap;
private final Change.Id changeId;
private final ObjectId tip;
private final RevWalk walk;
private final Repository repo;
private final Account.Id author;
DraftCommentNotesParser(Change.Id changeId, RevWalk walk, ObjectId tip,
GitRepositoryManager repoManager, AllUsersName draftsProject,
Account.Id author) throws RepositoryNotFoundException, IOException {
this.changeId = changeId;
this.walk = walk;
this.tip = tip;
this.repo = repoManager.openRepository(draftsProject);
this.author = author;
draftBaseComments = ArrayListMultimap.create();
draftPsComments = ArrayListMultimap.create();
}
@Override
public void close() {
repo.close();
}
void parseDraftComments() throws IOException, ConfigInvalidException {
walk.markStart(walk.parseCommit(tip));
noteMap = CommentsInNotesUtil.parseCommentsFromNotes(repo,
RefNames.refsDraftComments(author, changeId),
walk, changeId, draftBaseComments,
draftPsComments, PatchLineComment.Status.DRAFT);
}
}