if (e.getEndB() <= r.sourceStart) { eIdx++; continue; if (r.sourceStart < e.getBeginB()) { int d = e.getBeginB() - r.sourceStart; if (r.length <= d) { r.sourceStart = e.getBeginA() - d; aTail = add(aTail, a, r); r = next; aTail = add(aTail, a, r.splitFirst(e.getBeginA() - d, d)); r.slideAndShrink(d); if (e.getLengthB() == 0) { eIdx++; continue; if (rEnd <= e.getEndB()) { Region next = r.next; bTail = add(bTail, b, r); r = next; if (rEnd == e.getEndB()) eIdx++; continue; int len = e.getEndB() - r.sourceStart; bTail = add(bTail, b, r.splitFirst(r.sourceStart, len));
private void diff(Edit r) { switch (r.getType()) { case INSERT: case DELETE: edits.add(r); break; case REPLACE: if (r.getLengthA() == 1 && r.getLengthB() == 1) edits.add(r); else diffReplace(r); break; case EMPTY: default: throw new IllegalStateException(); } }
HistogramDiffIndex(int maxChainLength, HashedSequenceComparator<S> cmp, HashedSequence<S> a, HashedSequence<S> b, Edit r) { this.maxChainLength = maxChainLength; this.cmp = cmp; this.a = a; this.b = b; this.region = r; if (region.endA >= MAX_PTR) throw new IllegalArgumentException( JGitText.get().sequenceTooLargeForDiffAlgorithm); final int sz = r.getLengthA(); final int tableBits = tableBits(sz); table = new int[1 << tableBits]; keyShift = 32 - tableBits; ptrShift = r.beginA; recs = new long[Math.max(4, sz >>> 3)]; next = new int[sz]; recIdx = new int[sz]; }
/** * Construct a new edit representing the region after cut. * * @param cut * the cut point. The ending A and B points are used as the * starting points of the returned edit. * @return an edit representing the slice of {@code this} edit that occurs * after {@code cut} ends. */ public final Edit after(Edit cut) { return new Edit(cut.endA, endA, cut.endB, endB); }
private void diffReplace(Edit r) { Edit lcs = new HistogramDiffIndex<>(maxChainLength, cmp, a, b, r) .findLongestCommonSequence(); if (lcs != null) { // If we were given an edit, we can prove a result here. // if (lcs.isEmpty()) { // An empty edit indicates there is nothing in common. // Replace the entire region. // edits.add(r); } else { queue.add(r.after(lcs)); queue.add(r.before(lcs)); } } else if (fallback instanceof LowLevelDiffAlgorithm) { LowLevelDiffAlgorithm fb = (LowLevelDiffAlgorithm) fallback; fb.diffNonCommon(edits, cmp, a, b, r); } else if (fallback != null) { SubsequenceComparator<HashedSequence<S>> cs = subcmp(); Subsequence<HashedSequence<S>> as = Subsequence.a(a, r); Subsequence<HashedSequence<S>> bs = Subsequence.b(b, r); EditList res = fallback.diffNonCommon(cs, as, bs); edits.addAll(Subsequence.toBase(res, as, bs)); } else { edits.add(r); } }
/** {@inheritDoc} */ @SuppressWarnings("nls") @Override public String toString() { final Type t = getType(); return t + "(" + beginA + "-" + endA + "," + beginB + "-" + endB + ")"; } }
HunkHeader(FileHeader fh, EditList editList) { this(fh, fh.buf.length); this.editList = editList; endOffset = startOffset; nContext = 0; if (editList.isEmpty()) { newStartLine = 0; newLineCount = 0; } else { newStartLine = editList.get(0).getBeginB(); Edit last = editList.get(editList.size() - 1); newLineCount = last.getEndB() - newStartLine; } }
int sz = Math.min(recs.length << 1, 1 + region.getLengthA()); long[] n = new long[sz]; System.arraycopy(recs, 0, n, 0, recs.length);
/** * Construct a new edit representing the region before cut. * * @param cut * the cut point. The beginning A and B points are used as the * end points of the returned edit. * @return an edit representing the slice of {@code this} edit that occurs * before {@code cut} starts. */ public final Edit before(Edit cut) { return new Edit(beginA, cut.beginA, beginB, cut.beginB); }
private void diffReplace(Edit r) { Edit lcs = new HistogramDiffIndex<>(maxChainLength, cmp, a, b, r) .findLongestCommonSequence(); if (lcs != null) { // If we were given an edit, we can prove a result here. // if (lcs.isEmpty()) { // An empty edit indicates there is nothing in common. // Replace the entire region. // edits.add(r); } else { queue.add(r.after(lcs)); queue.add(r.before(lcs)); } } else if (fallback instanceof LowLevelDiffAlgorithm) { LowLevelDiffAlgorithm fb = (LowLevelDiffAlgorithm) fallback; fb.diffNonCommon(edits, cmp, a, b, r); } else if (fallback != null) { SubsequenceComparator<HashedSequence<S>> cs = subcmp(); Subsequence<HashedSequence<S>> as = Subsequence.a(a, r); Subsequence<HashedSequence<S>> bs = Subsequence.b(b, r); EditList res = fallback.diffNonCommon(cs, as, bs); edits.addAll(Subsequence.toBase(res, as, bs)); } else { edits.add(r); } }
@SuppressWarnings("nls") @Override public String toString() { final Type t = getType(); return t + "(" + beginA + "-" + endA + "," + beginB + "-" + endB + ")"; } }
final Edit endEdit = edits.get(endIdx); int aCur = (int) Math.max(0, (long) curEdit.getBeginA() - context); int bCur = (int) Math.max(0, (long) curEdit.getBeginB() - context); final int aEnd = (int) Math.min(a.size(), (long) endEdit.getEndA() + context); final int bEnd = (int) Math.min(b.size(), (long) endEdit.getEndB() + context); if (aCur < curEdit.getBeginA() || endIdx + 1 < curIdx) { writeContextLine(a, aCur); if (isEndOfLineMissing(a, aCur)) aCur++; bCur++; } else if (aCur < curEdit.getEndA()) { writeRemovedLine(a, aCur); if (isEndOfLineMissing(a, aCur)) out.write(noNewLine); aCur++; } else if (bCur < curEdit.getEndB()) { writeAddedLine(b, bCur); if (isEndOfLineMissing(b, bCur))