コード例 #1
0
 public Edition(Edit edit, RawText a, RawText b) {
   this.beginA = edit.getBeginA();
   this.beginB = edit.getBeginB();
   this.type = typeof(edit.getType());
   this.ca = new ArrayList<String>();
   this.cb = new ArrayList<String>();
   for (int i = beginA; i < edit.getEndA(); ++i) {
     ca.add(a.getString(i) + '\n');
   }
   for (int i = beginB; i < edit.getEndB(); ++i) {
     cb.add(b.getString(i) + '\n');
   }
 }
コード例 #2
0
ファイル: PatchListEntry.java プロジェクト: web1992/gerrit
  PatchListEntry(FileHeader hdr, List<Edit> editList, long size, long sizeDelta) {
    changeType = toChangeType(hdr);
    patchType = toPatchType(hdr);

    switch (changeType) {
      case DELETED:
        oldName = null;
        newName = hdr.getOldPath();
        break;

      case ADDED:
      case MODIFIED:
        oldName = null;
        newName = hdr.getNewPath();
        break;

      case COPIED:
      case RENAMED:
        oldName = hdr.getOldPath();
        newName = hdr.getNewPath();
        break;

      default:
        throw new IllegalArgumentException("Unsupported type " + changeType);
    }

    header = compact(hdr);

    if (hdr instanceof CombinedFileHeader
        || hdr.getHunks().isEmpty() //
        || hdr.getOldMode() == FileMode.GITLINK
        || hdr.getNewMode() == FileMode.GITLINK) {
      edits = Collections.emptyList();
    } else {
      edits = Collections.unmodifiableList(editList);
    }

    int ins = 0;
    int del = 0;
    for (Edit e : editList) {
      del += e.getEndA() - e.getBeginA();
      ins += e.getEndB() - e.getBeginB();
    }
    insertions = ins;
    deletions = del;
    this.size = size;
    this.sizeDelta = sizeDelta;
  }
コード例 #3
0
ファイル: FileDiff.java プロジェクト: joonhochoi/yobi
  /**
   * Get list of hunks
   *
   * @throws java.io.IOException
   */
  public List<Hunk> getHunks() throws IOException {

    List<Hunk> hunks = new ArrayList<>();

    for (int curIdx = 0; curIdx < editList.size(); ) {
      Hunk hunk = new Hunk();
      Edit curEdit = editList.get(curIdx);
      final int endIdx = findCombinedEnd(editList, curIdx);
      final Edit endEdit = editList.get(endIdx);

      int aCur = Math.max(0, curEdit.getBeginA() - context);
      int bCur = Math.max(0, curEdit.getBeginB() - context);
      final int aEnd = Math.min(a.size(), endEdit.getEndA() + context);
      final int bEnd = Math.min(b.size(), endEdit.getEndB() + context);

      hunk.beginA = aCur;
      hunk.endA = aEnd;
      hunk.beginB = bCur;
      hunk.endB = bEnd;

      while (aCur < aEnd || bCur < bEnd) {
        if (aCur < curEdit.getBeginA() || endIdx + 1 < curIdx) {
          hunk.lines.add(new DiffLine(this, DiffLineType.CONTEXT, aCur, bCur, a.getString(aCur)));
          isEndOfLineMissing = checkEndOfLineMissing(a, aCur);
          aCur++;
          bCur++;
        } else if (aCur < curEdit.getEndA()) {
          hunk.lines.add(new DiffLine(this, DiffLineType.REMOVE, aCur, bCur, a.getString(aCur)));
          isEndOfLineMissing = checkEndOfLineMissing(a, aCur);
          aCur++;
        } else if (bCur < curEdit.getEndB()) {
          hunk.lines.add(new DiffLine(this, DiffLineType.ADD, aCur, bCur, b.getString(bCur)));
          isEndOfLineMissing = checkEndOfLineMissing(a, aCur);
          bCur++;
        }

        if (end(curEdit, aCur, bCur) && ++curIdx < editList.size()) curEdit = editList.get(curIdx);
      }

      hunks.add(hunk);
    }

    return hunks;
  }
コード例 #4
0
ファイル: FileDiff.java プロジェクト: joonhochoi/yobi
  /**
   * 주어진 줄 번호와 관련된 diff만 남기고 나머지는 모두 버린다.
   *
   * <p>null인 줄 번호는 무시한다.
   *
   * @param lineA
   * @param lineB
   */
  public void updateRange(Integer lineA, Integer lineB) {
    EditList newEditList = new EditList();

    for (Edit edit : editList) {
      if (lineA != null) {
        if ((lineA >= edit.getBeginA() - context) && (lineA <= edit.getEndA() + context)) {
          newEditList.add(edit);
        }
      }

      if (lineB != null) {
        if ((lineB >= edit.getBeginB() - context) && (lineB <= edit.getEndB() + context)) {
          newEditList.add(edit);
        }
      }
    }

    editList = newEditList;
  }
コード例 #5
0
ファイル: PatchListEntry.java プロジェクト: web1992/gerrit
  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());
    }
  }