Search in sources :

Example 66 with ChangeNotes

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();
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 67 with ChangeNotes

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();
        }
    };
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ChangeData(com.google.gerrit.server.query.change.ChangeData) Callable(java.util.concurrent.Callable) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 68 with ChangeNotes

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");
}
Also used : InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) Project(com.google.gerrit.reviewdb.client.Project) ArrayList(java.util.ArrayList) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 69 with ChangeNotes

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")));
}
Also used : ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 70 with ChangeNotes

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);
        }
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ObjectId(org.eclipse.jgit.lib.ObjectId) Patch(com.google.gerrit.reviewdb.client.Patch)

Aggregations

ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)134 Test (org.junit.Test)54 Change (com.google.gerrit.entities.Change)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 PatchSet (com.google.gerrit.entities.PatchSet)42 ObjectId (org.eclipse.jgit.lib.ObjectId)33 StorageException (com.google.gerrit.exceptions.StorageException)22 Change (com.google.gerrit.reviewdb.client.Change)21 Project (com.google.gerrit.entities.Project)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 FixInput (com.google.gerrit.extensions.api.changes.FixInput)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 HumanComment (com.google.gerrit.entities.HumanComment)13 TestChanges.newPatchSet (com.google.gerrit.testing.TestChanges.newPatchSet)12 IOException (java.io.IOException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)9