Search in sources :

Example 16 with Edit

use of org.eclipse.jgit.diff.Edit in project gerrit by GerritCodeReview.

the class PatchScriptBuilder method ensureCommentsVisible.

private void ensureCommentsVisible(final CommentDetail comments) {
    if (comments.getCommentsA().isEmpty() && comments.getCommentsB().isEmpty()) {
        //
        return;
    }
    // Construct empty Edit blocks around each location where a comment is.
    // This will force the later packContent method to include the regions
    // containing comments, potentially combining those regions together if
    // they have overlapping contexts. UI renders will also be able to make
    // correct hunks from this, but because the Edit is empty they will not
    // style it specially.
    //
    final List<Edit> empty = new ArrayList<>();
    int lastLine;
    lastLine = -1;
    for (Comment c : comments.getCommentsA()) {
        final int a = c.lineNbr;
        if (lastLine != a) {
            final int b = mapA2B(a - 1);
            if (0 <= b) {
                safeAdd(empty, new Edit(a - 1, b));
            }
            lastLine = a;
        }
    }
    lastLine = -1;
    for (Comment c : comments.getCommentsB()) {
        int b = c.lineNbr;
        if (lastLine != b) {
            final int a = mapB2A(b - 1);
            if (0 <= a) {
                safeAdd(empty, new Edit(a, b - 1));
            }
            lastLine = b;
        }
    }
    // Sort the final list by the index in A, so packContent can combine
    // them correctly later.
    //
    edits.addAll(empty);
    Collections.sort(edits, EDIT_SORT);
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) ArrayList(java.util.ArrayList) Edit(org.eclipse.jgit.diff.Edit)

Aggregations

Edit (org.eclipse.jgit.diff.Edit)16 ReplaceEdit (org.eclipse.jgit.diff.ReplaceEdit)6 ArrayList (java.util.ArrayList)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Test (org.junit.Test)3 PatchScript (com.google.gerrit.common.data.PatchScript)2 Text (com.google.gerrit.server.patch.Text)2 RawText (org.eclipse.jgit.diff.RawText)2 FileHeader (org.eclipse.jgit.patch.FileHeader)2 Patch (org.eclipse.jgit.patch.Patch)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)1 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)1 FileMeta (com.google.gerrit.extensions.common.DiffInfo.FileMeta)1 DiffWebLinkInfo (com.google.gerrit.extensions.common.DiffWebLinkInfo)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 SparseFileContent (com.google.gerrit.prettify.common.SparseFileContent)1 Comment (com.google.gerrit.reviewdb.client.Comment)1