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());
}
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());
}
}
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);
}
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;
}
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();
}
Aggregations