Search in sources :

Example 6 with Edit

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

the class PatchScriptBuilder method build.

private PatchScript build(final PatchListEntry content, final CommentDetail comments, final List<Patch> history) throws IOException {
    boolean intralineDifferenceIsPossible = true;
    boolean intralineFailure = false;
    boolean intralineTimeout = false;
    a.path = oldName(content);
    b.path = newName(content);
    a.resolve(null, aId);
    b.resolve(a, bId);
    edits = new ArrayList<>(content.getEdits());
    if (!isModify(content)) {
        intralineDifferenceIsPossible = false;
    } else if (diffPrefs.intralineDifference) {
        IntraLineDiff d = patchListCache.getIntraLineDiff(IntraLineDiffKey.create(a.id, b.id, diffPrefs.ignoreWhitespace), IntraLineDiffArgs.create(a.src, b.src, edits, projectKey, bId, b.path));
        if (d != null) {
            switch(d.getStatus()) {
                case EDIT_LIST:
                    edits = new ArrayList<>(d.getEdits());
                    break;
                case DISABLED:
                    intralineDifferenceIsPossible = false;
                    break;
                case ERROR:
                    intralineDifferenceIsPossible = false;
                    intralineFailure = true;
                    break;
                case TIMEOUT:
                    intralineDifferenceIsPossible = false;
                    intralineTimeout = true;
                    break;
            }
        } else {
            intralineDifferenceIsPossible = false;
            intralineFailure = true;
        }
    }
    if (comments != null) {
        ensureCommentsVisible(comments);
    }
    boolean hugeFile = false;
    if (a.src == b.src && a.size() <= context && content.getEdits().isEmpty()) {
        //
        for (int i = 0; i < a.size(); i++) {
            a.addLine(i);
        }
        edits = new ArrayList<>(1);
        edits.add(new Edit(a.size(), a.size()));
    } else {
        if (BIG_FILE < Math.max(a.size(), b.size())) {
            // IF the file is really large, we disable things to avoid choking
            // the browser client.
            //
            hugeFile = true;
        }
        // In order to expand the skipped common lines or syntax highlight the
        // file properly we need to give the client the complete file contents.
        // So force our context temporarily to the complete file size.
        //
        context = MAX_CONTEXT;
        packContent(diffPrefs.ignoreWhitespace != Whitespace.IGNORE_NONE);
    }
    return new PatchScript(change.getKey(), content.getChangeType(), content.getOldName(), content.getNewName(), a.fileMode, b.fileMode, content.getHeaderLines(), diffPrefs, a.dst, b.dst, edits, a.displayMethod, b.displayMethod, a.mimeType.toString(), b.mimeType.toString(), comments, history, hugeFile, intralineDifferenceIsPossible, intralineFailure, intralineTimeout, content.getPatchType() == Patch.PatchType.BINARY, aId == null ? null : aId.getName(), bId == null ? null : bId.getName());
}
Also used : PatchScript(com.google.gerrit.common.data.PatchScript) ArrayList(java.util.ArrayList) Edit(org.eclipse.jgit.diff.Edit)

Example 7 with Edit

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

the class PatchListEntry method writeTo.

void writeTo(OutputStream out) throws IOException {
    writeEnum(out, changeType);
    writeEnum(out, patchType);
    writeString(out, oldName);
    writeString(out, newName);
    writeBytes(out, header);
    writeVarInt32(out, insertions);
    writeVarInt32(out, deletions);
    writeFixInt64(out, size);
    writeFixInt64(out, sizeDelta);
    writeVarInt32(out, edits.size());
    for (final Edit e : edits) {
        writeVarInt32(out, e.getBeginA());
        writeVarInt32(out, e.getEndA());
        writeVarInt32(out, e.getBeginB());
        writeVarInt32(out, e.getEndB());
    }
}
Also used : Edit(org.eclipse.jgit.diff.Edit)

Example 8 with Edit

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

the class PatchListEntry method readFrom.

static PatchListEntry readFrom(InputStream in) throws IOException {
    ChangeType changeType = readEnum(in, ChangeType.values());
    PatchType patchType = readEnum(in, PatchType.values());
    String oldName = readString(in);
    String newName = readString(in);
    byte[] hdr = readBytes(in);
    int ins = readVarInt32(in);
    int del = readVarInt32(in);
    long size = readFixInt64(in);
    long sizeDelta = readFixInt64(in);
    int editCount = readVarInt32(in);
    Edit[] editArray = new Edit[editCount];
    for (int i = 0; i < editCount; i++) {
        int beginA = readVarInt32(in);
        int endA = readVarInt32(in);
        int beginB = readVarInt32(in);
        int endB = readVarInt32(in);
        editArray[i] = new Edit(beginA, endA, beginB, endB);
    }
    return new PatchListEntry(changeType, patchType, oldName, newName, hdr, toList(editArray), ins, del, size, sizeDelta);
}
Also used : ChangeType(com.google.gerrit.reviewdb.client.Patch.ChangeType) PatchType(com.google.gerrit.reviewdb.client.Patch.PatchType) Edit(org.eclipse.jgit.diff.Edit) BasicSerialization.writeString(com.google.gerrit.server.ioutil.BasicSerialization.writeString) BasicSerialization.readString(com.google.gerrit.server.ioutil.BasicSerialization.readString)

Example 9 with Edit

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

the class EditList method combineA.

private boolean combineA(final int i) {
    final Edit s = edits.get(i);
    final Edit e = edits.get(i - 1);
    // + 1 to prevent '... skipping 1 common line ...' messages.
    return s.getBeginA() - e.getEndA() <= 2 * context + 1;
}
Also used : Edit(org.eclipse.jgit.diff.Edit)

Example 10 with Edit

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

the class PRED_commit_edits_2 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Term a2 = arg2.dereference();
    Pattern fileRegex = getRegexParameter(a1);
    Pattern editRegex = getRegexParameter(a2);
    PatchList pl = StoredValues.PATCH_LIST.get(engine);
    Repository repo = StoredValues.REPOSITORY.get(engine);
    try (ObjectReader reader = repo.newObjectReader();
        RevWalk rw = new RevWalk(reader)) {
        final RevTree aTree;
        final RevTree bTree;
        final RevCommit bCommit = rw.parseCommit(pl.getNewId());
        if (pl.getOldId() != null) {
            aTree = rw.parseTree(pl.getOldId());
        } else {
            // web UI returns no files to match against, just fail.
            return engine.fail();
        }
        bTree = bCommit.getTree();
        for (PatchListEntry entry : pl.getPatches()) {
            String newName = entry.getNewName();
            String oldName = entry.getOldName();
            if (newName.equals("/COMMIT_MSG")) {
                continue;
            }
            if (fileRegex.matcher(newName).find() || (oldName != null && fileRegex.matcher(oldName).find())) {
                List<Edit> edits = entry.getEdits();
                if (edits.isEmpty()) {
                    continue;
                }
                Text tA;
                if (oldName != null) {
                    tA = load(aTree, oldName, reader);
                } else {
                    tA = load(aTree, newName, reader);
                }
                Text tB = load(bTree, newName, reader);
                for (Edit edit : edits) {
                    if (tA != Text.EMPTY) {
                        String aDiff = tA.getString(edit.getBeginA(), edit.getEndA(), true);
                        if (editRegex.matcher(aDiff).find()) {
                            return cont;
                        }
                    }
                    if (tB != Text.EMPTY) {
                        String bDiff = tB.getString(edit.getBeginB(), edit.getEndB(), true);
                        if (editRegex.matcher(bDiff).find()) {
                            return cont;
                        }
                    }
                }
            }
        }
    } catch (IOException err) {
        throw new JavaException(this, 1, err);
    }
    return engine.fail();
}
Also used : Pattern(java.util.regex.Pattern) JavaException(com.googlecode.prolog_cafe.exceptions.JavaException) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) Edit(org.eclipse.jgit.diff.Edit) Text(com.google.gerrit.server.patch.Text) Term(com.googlecode.prolog_cafe.lang.Term) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) PatchList(com.google.gerrit.server.patch.PatchList) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

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