Package org.eclipse.jgit.diff

Examples of org.eclipse.jgit.diff.RawText


        }

        if (RawText.isBinary(raw))
          continue;

        RawText txt = new RawText(raw);
        int[] lines = new int[txt.size()];
        int cnt = 0;
        HashSet<Line> u = new HashSet<Line>();
        for (int i = 0; i < txt.size(); i++) {
          if (u.add(new Line(txt, i)))
            lines[cnt++] = i;
        }

        fileCnt++;
View Full Code Here


        }

        unmergedPaths.add(tw.getPathString());

        // generate a MergeResult for the deleted file
        RawText baseText = base == null ? RawText.EMPTY_TEXT
            : getRawText(base.getEntryObjectId(), db);
        RawText ourText = ours == null ? RawText.EMPTY_TEXT
            : getRawText(ours.getEntryObjectId(), db);
        RawText theirsText = theirs == null ? RawText.EMPTY_TEXT
            : getRawText(theirs.getEntryObjectId(), db);
        MergeResult<RawText> result = mergeAlgorithm.merge(
            RawTextComparator.DEFAULT, baseText, ourText,
            theirsText);
        mergeResults.put(tw.getPathString(), result);
View Full Code Here

  private boolean contentMerge(CanonicalTreeParser base,
      CanonicalTreeParser ours, CanonicalTreeParser theirs)
      throws FileNotFoundException, IllegalStateException, IOException {
    MergeFormatter fmt = new MergeFormatter();

    RawText baseText = base == null ? RawText.EMPTY_TEXT : getRawText(
        base.getEntryObjectId(), db);

    // do the merge
    MergeResult<RawText> result = mergeAlgorithm.merge(
        RawTextComparator.DEFAULT, baseText,
View Full Code Here

  }

  private static RawText getRawText(ObjectId id, Repository db)
      throws IOException {
    if (id.equals(ObjectId.zeroId()))
      return new RawText(new byte[] {});
    return new RawText(db.open(id, Constants.OBJ_BLOB).getCachedBytes());
  }
View Full Code Here

      List<String> seqName, String charsetName) throws IOException {
    String lastConflictingName = null; // is set to non-null whenever we are
    // in a conflict
    boolean threeWayMerge = (res.getSequences().size() == 3);
    for (MergeChunk chunk : res) {
      RawText seq = (RawText) res.getSequences().get(
          chunk.getSequenceIndex());
      if (lastConflictingName != null
          && chunk.getConflictState() != ConflictState.NEXT_CONFLICTING_RANGE) {
        // found the end of an conflict
        out.write((">>>>>>> " + lastConflictingName + "\n").getBytes(charsetName));
        lastConflictingName = null;
      }
      if (chunk.getConflictState() == ConflictState.FIRST_CONFLICTING_RANGE) {
        // found the start of an conflict
        out.write(("<<<<<<< " + seqName.get(chunk.getSequenceIndex()) +
            "\n").getBytes(charsetName));
        lastConflictingName = seqName.get(chunk.getSequenceIndex());
      } else if (chunk.getConflictState() == ConflictState.NEXT_CONFLICTING_RANGE) {
        // found another conflicting chunk

        /*
         * In case of a non-three-way merge I'll add the name of the
         * conflicting chunk behind the equal signs. I also append the
         * name of the last conflicting chunk after the ending
         * greater-than signs. If somebody knows a better notation to
         * present non-three-way merges - feel free to correct here.
         */
        lastConflictingName = seqName.get(chunk.getSequenceIndex());
        out.write((threeWayMerge ? "=======\n" : "======= "
            + lastConflictingName + "\n").getBytes(charsetName));
      }
      // the lines with conflict-metadata are written. Now write the chunk
      for (int i = chunk.getBegin(); i < chunk.getEnd(); i++) {
        seq.writeLine(out, i);
        out.write('\n');
      }
    }
    // one possible leftover: if the merge result ended with a conflict we
    // have to close the last conflict here
View Full Code Here

          if (tw.getFileMode(0).getObjectType() == Constants.OBJ_BLOB)
            oldImage = openBlob(0);
          else
            oldImage = new byte[0];

          EditList edits = new MyersDiff(new RawText(oldImage),
              new RawText(openBlob(1))).getEdits();
          for (Edit e : edits)
            addedLines += e.getEndB() - e.getBeginB();
        }

      } else { // no parents, everything is an addition
View Full Code Here

  public void testConflictAtEnd() throws IOException {
    assertEquals(A+B+C+D+E+F+G+H+I+XXX_0+Z+XXX_1+Y+XXX_2, merge(base, replace_J_by_Z, replace_J_by_Y));
  }

  private String merge(String commonBase, String ours, String theirs) throws IOException {
    MergeResult r=MergeAlgorithm.merge(new RawText(Constants.encode(commonBase)), new RawText(Constants.encode(ours)), new RawText(Constants.encode(theirs)));
    ByteArrayOutputStream bo=new ByteArrayOutputStream(50);
    fmt.formatMerge(bo, r, "B", "O", "T", Constants.CHARACTER_ENCODING);
    return new String(bo.toByteArray(), Constants.CHARACTER_ENCODING);
  }
View Full Code Here

   * @throws IOException
   * @throws PatchApplyException
   */
  private void apply(File f, FileHeader fh)
      throws IOException, PatchApplyException {
    RawText rt = new RawText(f);
    List<String> oldLines = new ArrayList<String>(rt.size());
    for (int i = 0; i < rt.size(); i++)
      oldLines.add(rt.getString(i));
    List<String> newLines = new ArrayList<String>(oldLines);
    for (HunkHeader hh : fh.getHunks()) {
      StringBuilder hunk = new StringBuilder();
      for (int j = hh.getStartOffset(); j < hh.getEndOffset(); j++)
        hunk.append((char) hh.getBuffer()[j]);
      RawText hrt = new RawText(hunk.toString().getBytes());
      List<String> hunkLines = new ArrayList<String>(hrt.size());
      for (int i = 0; i < hrt.size(); i++)
        hunkLines.add(hrt.getString(i));
      int pos = 0;
      for (int j = 1; j < hunkLines.size(); j++) {
        String hunkLine = hunkLines.get(j);
        switch (hunkLine.charAt(0)) {
        case ' ':
View Full Code Here

    return false;
  }

  private boolean isNoNewlineAtEndOfFile(FileHeader fh) {
    HunkHeader lastHunk = fh.getHunks().get(fh.getHunks().size() - 1);
    RawText lhrt = new RawText(lastHunk.getBuffer());
    return lhrt.getString(lhrt.size() - 1).equals(
        "\\ No newline at end of file"); //$NON-NLS-1$
  }
View Full Code Here

   * @throws IOException
   */
  private MergeResult<RawText> contentMerge(CanonicalTreeParser base,
      CanonicalTreeParser ours, CanonicalTreeParser theirs)
      throws IOException {
    RawText baseText = base == null ? RawText.EMPTY_TEXT : getRawText(
        base.getEntryObjectId(), db);
    RawText ourText = ours == null ? RawText.EMPTY_TEXT : getRawText(
        ours.getEntryObjectId(), db);
    RawText theirsText = theirs == null ? RawText.EMPTY_TEXT : getRawText(
        theirs.getEntryObjectId(), db);
    return (mergeAlgorithm.merge(RawTextComparator.DEFAULT, baseText,
        ourText, theirsText));
  }
View Full Code Here

TOP

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

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.