Merge "Fire GitReferenceUpdated from NotesBranchUtil"

This commit is contained in:
Edwin Kempin
2013-02-01 09:47:01 +00:00
committed by Gerrit Code Review
5 changed files with 31 additions and 17 deletions

View File

@@ -171,7 +171,7 @@ public class ExportReviewNotes extends SiteProgram {
return;
}
try {
CreateCodeReviewNotes notes = codeReviewNotesFactory.create(db, git);
CreateCodeReviewNotes notes = codeReviewNotesFactory.create(db, project, git);
notes.create(changes, null,
"Exported prior reviews from Gerrit Code Review\n", monitor);
} finally {

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.git;
import static com.google.gerrit.server.git.GitRepositoryManager.REF_REJECT_COMMITS;
import com.google.gerrit.common.errors.PermissionDeniedException;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.project.ProjectControl;
@@ -74,8 +75,8 @@ public class BanCommit {
final BanCommitResult result = new BanCommitResult();
NoteMap banCommitNotes = NoteMap.newEmptyMap();
// add a note for each banned commit to notes
final Repository repo =
repoManager.openRepository(projectControl.getProject().getNameKey());
final Project.NameKey project = projectControl.getProject().getNameKey();
final Repository repo = repoManager.openRepository(project);
try {
final RevWalk revWalk = new RevWalk(repo);
final ObjectInserter inserter = repo.newObjectInserter();
@@ -92,8 +93,8 @@ public class BanCommit {
banCommitNotes.set(commitToBan, createNoteContent(reason, inserter));
}
inserter.flush();
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(repo,
inserter);
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(project,
repo, inserter);
NoteMap newlyCreated =
notesBranchUtil.commitNewNotes(banCommitNotes, REF_REJECT_COMMITS,
createPersonIdent(), buildCommitMessage(commitsToBan, reason));

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.reviewdb.client.ApprovalCategory;
import com.google.gerrit.reviewdb.client.Change;
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.server.ReviewDb;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.account.AccountCache;
@@ -58,7 +59,8 @@ import javax.annotation.Nullable;
*/
public class CreateCodeReviewNotes {
public interface Factory {
CreateCodeReviewNotes create(ReviewDb reviewDb, Repository db);
CreateCodeReviewNotes create(ReviewDb reviewDb, Project.NameKey project,
Repository db);
}
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
@@ -68,6 +70,7 @@ public class CreateCodeReviewNotes {
private final String canonicalWebUrl;
private final String anonymousCowardName;
private final ReviewDb schema;
private final Project.NameKey project;
private final Repository db;
private PersonIdent author;
@@ -85,8 +88,9 @@ public class CreateCodeReviewNotes {
final @Nullable @CanonicalWebUrl String canonicalWebUrl,
final @AnonymousCowardName String anonymousCowardName,
final NotesBranchUtil.Factory notesBranchUtilFactory,
final @Assisted ReviewDb reviewDb,
final @Assisted Repository db) {
final @Assisted ReviewDb reviewDb,
final @Assisted Project.NameKey project,
final @Assisted Repository db) {
this.author = gerritIdent;
this.accountCache = accountCache;
this.approvalTypes = approvalTypes;
@@ -94,6 +98,7 @@ public class CreateCodeReviewNotes {
this.anonymousCowardName = anonymousCowardName;
this.notesBranchUtilFactory = notesBranchUtilFactory;
schema = reviewDb;
this.project = project;
this.db = db;
}
@@ -114,8 +119,8 @@ public class CreateCodeReviewNotes {
message.append("* ").append(c.getShortMessage()).append("\n");
}
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(db,
inserter);
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(project,
db, inserter);
notesBranchUtil.commitAllNotes(notes, REFS_NOTES_REVIEW, author,
message.toString());
inserter.flush();
@@ -150,8 +155,8 @@ public class CreateCodeReviewNotes {
notes.set(commitId, createNoteContent(c, commitId));
}
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(db,
inserter);
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(project,
db, inserter);
notesBranchUtil.commitAllNotes(notes, REFS_NOTES_REVIEW, author,
commitMessage);
inserter.flush();

View File

@@ -773,7 +773,7 @@ public class MergeOp {
}
CreateCodeReviewNotes codeReviewNotes =
codeReviewNotesFactory.create(db, repo);
codeReviewNotesFactory.create(db, destBranch.getParentKey(), repo);
try {
codeReviewNotes.create(
merged,
@@ -782,8 +782,6 @@ public class MergeOp {
} catch (CodeReviewNoteCreationException e) {
log.error(e.getMessage());
}
replication.fire(destBranch.getParentKey(),
GitRepositoryManager.REFS_NOTES_REVIEW);
}
private void updateSubscriptions(final List<Change> submitted) {

View File

@@ -14,7 +14,9 @@
package com.google.gerrit.server.git;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -47,13 +49,16 @@ import java.io.IOException;
*/
public class NotesBranchUtil {
public interface Factory {
NotesBranchUtil create(Repository db, ObjectInserter inserter);
NotesBranchUtil create(Project.NameKey project, Repository db,
ObjectInserter inserter);
}
private static final int MAX_LOCK_FAILURE_CALLS = 10;
private static final int SLEEP_ON_LOCK_FAILURE_MS = 25;
private PersonIdent gerritIdent;
private final PersonIdent gerritIdent;
private final GitReferenceUpdated gitRefUpdated;
private final Project.NameKey project;
private final Repository db;
private final ObjectInserter inserter;
@@ -71,9 +76,13 @@ public class NotesBranchUtil {
@Inject
public NotesBranchUtil(@GerritPersonIdent final PersonIdent gerritIdent,
final GitReferenceUpdated gitRefUpdated,
@Assisted Project.NameKey project,
@Assisted Repository db,
@Assisted ObjectInserter inserter) {
this.gerritIdent = gerritIdent;
this.gitRefUpdated = gitRefUpdated;
this.project = project;
this.db = db;
this.inserter = inserter;
}
@@ -252,6 +261,7 @@ public class NotesBranchUtil {
throw new IOException("Couldn't update " + notesBranch + ". "
+ result.name());
} else {
gitRefUpdated.fire(project, notesBranch);
break;
}
}