use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method ignorePatchLineCommentsOnPatchSet0.
@Test
public void ignorePatchLineCommentsOnPatchSet0() throws Exception {
PushOneCommit.Result r = createChange();
Change change = r.getChange().change();
Change.Id id = change.getId();
PatchLineComment comment = new PatchLineComment(new PatchLineComment.Key(new Patch.Key(new PatchSet.Id(id, 0), PushOneCommit.FILE_NAME), "uuid"), 0, user.getId(), null, TimeUtil.nowTs());
comment.setSide((short) 1);
comment.setMessage("message");
comment.setStatus(PatchLineComment.Status.PUBLISHED);
db.patchComments().insert(Collections.singleton(comment));
indexer.index(db, change.getProject(), id);
checker.rebuildAndCheckChanges(id);
setNotesMigration(true, true);
ChangeNotes notes = notesFactory.create(db, project, id);
assertThat(notes.getComments()).isEmpty();
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class AllChangesIndexer method reindexProject.
public Callable<Void> reindexProject(final ChangeIndexer indexer, final Project.NameKey project, final Task done, final Task failed, final PrintWriter verboseWriter) {
return new Callable<Void>() {
@Override
public Void call() throws Exception {
ListMultimap<ObjectId, ChangeData> byId = MultimapBuilder.hashKeys().arrayListValues().build();
// with RepositoryCache.close(repo).
try (Repository repo = repoManager.openRepository(project);
ReviewDb db = schemaFactory.open()) {
Map<String, Ref> refs = repo.getRefDatabase().getRefs(ALL);
// change IDs.
for (ChangeNotes cn : notesFactory.scan(repo, db, project)) {
Ref r = refs.get(cn.getChange().currentPatchSetId().toRefName());
if (r != null) {
byId.put(r.getObjectId(), changeDataFactory.create(db, cn));
}
}
new ProjectIndexer(indexer, byId, repo, done, failed, verboseWriter).call();
} catch (RepositoryNotFoundException rnfe) {
log.error(rnfe.getMessage());
}
return null;
}
@Override
public String toString() {
return "Index all changes of project " + project.get();
}
};
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class PatchSetParser method parsePatchSet.
public PatchSet parsePatchSet(String token, ProjectControl projectControl, String branch) throws UnloggedFailure, OrmException {
//
if (token.matches("^([0-9a-fA-F]{4," + RevId.LEN + "})$")) {
InternalChangeQuery query = queryProvider.get();
List<ChangeData> cds;
if (projectControl != null) {
Project.NameKey p = projectControl.getProject().getNameKey();
if (branch != null) {
cds = query.byBranchCommit(p.get(), branch, token);
} else {
cds = query.byProjectCommit(p, token);
}
} else {
cds = query.byCommit(token);
}
List<PatchSet> matches = new ArrayList<>(cds.size());
for (ChangeData cd : cds) {
Change c = cd.change();
if (!(inProject(c, projectControl) && inBranch(c, branch))) {
continue;
}
for (PatchSet ps : cd.patchSets()) {
if (ps.getRevision().matches(token)) {
matches.add(ps);
}
}
}
switch(matches.size()) {
case 1:
return matches.iterator().next();
case 0:
throw error("\"" + token + "\" no such patch set");
default:
throw error("\"" + token + "\" matches multiple patch sets");
}
}
//
if (token.matches("^[1-9][0-9]*,[1-9][0-9]*$")) {
PatchSet.Id patchSetId;
try {
patchSetId = PatchSet.Id.parse(token);
} catch (IllegalArgumentException e) {
throw error("\"" + token + "\" is not a valid patch set");
}
ChangeNotes notes = getNotes(projectControl, patchSetId.getParentKey());
PatchSet patchSet = psUtil.get(db.get(), notes, patchSetId);
if (patchSet == null) {
throw error("\"" + token + "\" no such patch set");
}
if (projectControl != null || branch != null) {
Change change = notes.getChange();
if (!inProject(change, projectControl)) {
throw error("change " + change.getId() + " not in project " + projectControl.getProject().getName());
}
if (!inBranch(change, branch)) {
throw error("change " + change.getId() + " not in branch " + branch);
}
}
return patchSet;
}
throw error("\"" + token + "\" is not a valid patch set");
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class Rebuild method apply.
@Override
public BinaryResult apply(ChangeResource rsrc, Input input) throws ResourceNotFoundException, IOException, OrmException, ConfigInvalidException {
if (!migration.commitChangeWrites()) {
throw new ResourceNotFoundException();
}
if (!migration.readChanges()) {
// ChangeBundle#fromNotes currently doesn't work if reading isn't enabled,
// so don't attempt a diff.
rebuild(rsrc);
return BinaryResult.create("Rebuilt change successfully");
}
// Not the same transaction as the rebuild, so may result in spurious diffs
// in the case of races. This should be easy enough to detect by rerunning.
ChangeBundle reviewDbBundle = bundleReader.fromReviewDb(ReviewDbUtil.unwrapDb(db.get()), rsrc.getId());
rebuild(rsrc);
ChangeNotes notes = notesFactory.create(db.get(), rsrc.getChange().getProject(), rsrc.getId());
ChangeBundle noteDbBundle = ChangeBundle.fromNotes(commentsUtil, notes);
List<String> diffs = reviewDbBundle.differencesFrom(noteDbBundle);
if (diffs.isEmpty()) {
return BinaryResult.create("No differences between ReviewDb and NoteDb");
}
return BinaryResult.create(diffs.stream().collect(joining("\n", "Differences between ReviewDb and NoteDb:\n", "\n")));
}
use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.
the class PatchScriptFactory method loadPublished.
private void loadPublished(Map<Patch.Key, Patch> byKey, String file) throws OrmException {
ChangeNotes notes = control.getNotes();
for (Comment c : commentsUtil.publishedByChangeFile(db, notes, changeId, file)) {
comments.include(change.getId(), c);
PatchSet.Id psId = new PatchSet.Id(change.getId(), c.key.patchSetId);
Patch.Key pKey = new Patch.Key(psId, c.key.filename);
Patch p = byKey.get(pKey);
if (p != null) {
p.setCommentCount(p.getCommentCount() + 1);
}
}
}
Aggregations