Package org.eclipse.jgit.diff

Examples of org.eclipse.jgit.diff.Edit


    if (editList.isEmpty()) {
      newStartLine = 0;
      newLineCount = 0;
    } else {
      newStartLine = editList.get(0).getBeginB();
      Edit last = editList.get(editList.size() - 1);
      newLineCount = last.getEndB() - newStartLine;
    }
  }
View Full Code Here


      editList = new EditList();
      final byte[] buf = file.buf;
      int c = nextLF(buf, startOffset);
      int oLine = old.startLine;
      int nLine = newStartLine;
      Edit in = null;

      SCAN: for (; c < endOffset; c = nextLF(buf, c)) {
        switch (buf[c]) {
        case ' ':
        case '\n':
          in = null;
          oLine++;
          nLine++;
          continue;

        case '-':
          if (in == null) {
            in = new Edit(oLine - 1, nLine - 1);
            editList.add(in);
          }
          oLine++;
          in.extendA();
          continue;

        case '+':
          if (in == null) {
            in = new Edit(oLine - 1, nLine - 1);
            editList.add(in);
          }
          nLine++;
          in.extendB();
          continue;

        case '\\': // Matches "\ No newline at end of file"
          continue;
View Full Code Here

      // more responsibility for the result. Remaining edits can
      // be safely ignored.
      if (r == null)
        return;

      Edit e = editList.get(eIdx);

      // Edit ends before the next candidate region. Skip the edit.
      if (e.getEndB() <= r.sourceStart) {
        eIdx++;
        continue;
      }

      // Next candidate region starts before the edit. Assign some
      // of the blame onto A, but possibly split and also on B.
      if (r.sourceStart < e.getBeginB()) {
        int d = e.getBeginB() - r.sourceStart;
        if (r.length <= d) {
          // Pass the blame for this region onto A.
          Region next = r.next;
          r.sourceStart = e.getBeginA() - d;
          aTail = add(aTail, a, r);
          r = next;
          continue;
        }

        // Split the region and assign some to A, some to B.
        aTail = add(aTail, a, r.splitFirst(e.getBeginA() - d, d));
        r.slideAndShrink(d);
      }

      // At this point e.getBeginB() <= r.sourceStart.

      // An empty edit on the B side isn't relevant to this split,
      // as it does not overlap any candidate region.
      if (e.getLengthB() == 0) {
        eIdx++;
        continue;
      }

      // If the region ends before the edit, blame on B.
      int rEnd = r.sourceStart + r.length;
      if (rEnd <= e.getEndB()) {
        Region next = r.next;
        bTail = add(bTail, b, r);
        r = next;
        if (rEnd == e.getEndB())
          eIdx++;
        continue;
      }

      // This region extends beyond the edit. Blame the first
      // half of the region on B, and process the rest after.
      int len = e.getEndB() - r.sourceStart;
      bTail = add(bTail, b, r.splitFirst(r.sourceStart, len));
      r.slideAndShrink(len);
      eIdx++;
    }

    if (r == null)
      return;

    // For any remaining region, pass the blame onto A after shifting
    // the source start to account for the difference between the two.
    Edit e = editList.get(editList.size() - 1);
    int endB = e.getEndB();
    int d = endB - e.getEndA();
    if (aTail == null)
      a.regionList = r;
    else
      aTail.next = r;
    do {
View Full Code Here

      end++;
    return end - 1;
  }

  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;
  }
View Full Code Here

    // in the source. That simplifies our loop below because we'll never
    // run off the end of the edit list.
    //
    List<Edit> edits = new ArrayList<Edit>(this.edits.size() + 1);
    edits.addAll(this.edits);
    edits.add(new Edit(src.size(), src.size()));

    SafeHtmlBuilder buf = new SafeHtmlBuilder();

    int curIdx = 0;
    Edit curEdit = edits.get(curIdx);

    ReplaceEdit lastReplace = null;
    List<Edit> charEdits = null;
    int lastPos = 0;
    int lastIdx = 0;

    for (int index = src.first(); index < src.size(); index = src.next(index)) {
      int cmp = compare(index, curEdit);
      while (0 < cmp) {
        // The index is after the edit. Skip to the next edit.
        //
        curEdit = edits.get(curIdx++);
        cmp = compare(index, curEdit);
      }

      if (cmp < 0) {
        // index occurs before the edit. This is a line of context.
        //
        appendShowBareCR(buf, src.get(index), true);
        buf.append('\n');
        continue;
      }

      // index occurs within the edit. The line is a modification.
      //
      if (curEdit instanceof ReplaceEdit) {
        if (lastReplace != curEdit) {
          lastReplace = (ReplaceEdit) curEdit;
          charEdits = lastReplace.getInternalEdits();
          lastPos = 0;
          lastIdx = 0;
        }

        String line = src.get(index) + "\n";
        for (int c = 0; c < line.length();) {
          if (charEdits.size() <= lastIdx) {
            appendShowBareCR(buf, line.substring(c), false);
            break;
          }

          final Edit edit = charEdits.get(lastIdx);
          final int b = side.getBegin(edit) - lastPos;
          final int e = side.getEnd(edit) - lastPos;

          if (c < b) {
            // There is text at the start of this line that is common
View Full Code Here

    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);
  }
View Full Code Here

  private static Edit readEdit(InputStream in) throws IOException {
    int beginA = readVarInt32(in);
    int endA = readVarInt32(in);
    int beginB = readVarInt32(in);
    int endB = readVarInt32(in);
    return new Edit(beginA, endA, beginB, endB);
  }
View Full Code Here

      //
      for (int i = 0; i < a.size(); i++) {
        a.addLine(i);
      }
      edits = new ArrayList<Edit>(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.
View Full Code Here

    for (PatchLineComment plc : comments.getCommentsA()) {
      final int a = plc.getLine();
      if (lastLine != a) {
        final int b = mapA2B(a - 1);
        if (0 <= b) {
          safeAdd(empty, new Edit(a - 1, b));
        }
        lastLine = a;
      }
    }

    lastLine = -1;
    for (PatchLineComment plc : comments.getCommentsB()) {
      final int b = plc.getLine();
      if (lastLine != b) {
        final int a = mapB2A(b - 1);
        if (0 <= a) {
          safeAdd(empty, new Edit(a, b - 1));
        }
        lastLine = b;
      }
    }
View Full Code Here

      //
      return a;
    }

    for (int i = 0; i < edits.size(); i++) {
      final Edit e = edits.get(i);
      if (a < e.getBeginA()) {
        if (i == 0) {
          // Special case of context at start of file.
          //
          return a;
        }
        return e.getBeginB() - (e.getBeginA() - a);
      }
      if (e.getBeginA() <= a && a <= e.getEndA()) {
        return -1;
      }
    }

    final Edit last = edits.get(edits.size() - 1);
    return last.getBeginB() + (a - last.getEndA());
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.diff.Edit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.