Package org.eclipse.jgit.diff

Examples of org.eclipse.jgit.diff.RawText$Factory


      DiffEntry diffEntry = CompareCoreUtils.getChangeDiffEntry(
          repository, sourcePath, commit, parentCommit, reader);
      if (diffEntry == null)
        return null;

      RawText oldText = readText(diffEntry.getOldId(), reader);
      RawText newText = readText(diffEntry.getNewId(), reader);

      StoredConfig config = repository.getConfig();
      DiffAlgorithm diffAlgorithm = DiffAlgorithm.getAlgorithm(config
          .getEnum(ConfigConstants.CONFIG_DIFF_SECTION, null,
              ConfigConstants.CONFIG_KEY_ALGORITHM,
View Full Code Here


  private static RawText readText(AbbreviatedObjectId blobId,
      ObjectReader reader) throws IOException {
    ObjectLoader oldLoader = reader.open(blobId.toObjectId(),
        Constants.OBJ_BLOB);
    return new RawText(oldLoader.getCachedBytes());
  }
View Full Code Here

      d.append("+++ "); //$NON-NLS-1$
      d.append(getProjectRelativePath(db, getNewPath()));
      d.append("\n"); //$NON-NLS-1$
    }

    final RawText a = getRawText(id1, reader);
    final RawText b = getRawText(id2, reader);
    EditList editList = MyersDiff.INSTANCE
        .diff(RawTextComparator.DEFAULT, a, b);
    diffFmt.format(editList, a, b);
  }
View Full Code Here

  }

  private RawText getRawText(ObjectId id, ObjectReader reader)
      throws IOException {
    if (id.equals(ObjectId.zeroId()))
      return new RawText(new byte[] {});
    ObjectLoader ldr = reader.open(id, Constants.OBJ_BLOB);
    return new RawText(ldr.getCachedBytes(Integer.MAX_VALUE));
  }
View Full Code Here

   *
   * @param sb
   * @param diffFmt
   */
  public void updateWorkspacePatchPrefixes(StringBuilder sb, DiffFormatter diffFmt) {
    RawText rt;
    try {
      rt = new RawText(sb.toString().getBytes("UTF-8")); //$NON-NLS-1$
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }

    final String oldPrefix = diffFmt.getOldPrefix();
    final String newPrefix = diffFmt.getNewPrefix();

    StringBuilder newSb = new StringBuilder();
    final Pattern diffPattern = Pattern
        .compile("^diff --git (" + oldPrefix + "(.+)) (" + newPrefix + "(.+))$"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    final Pattern oldPattern = Pattern
        .compile("^--- (" + oldPrefix + "(.+))$"); //$NON-NLS-1$ //$NON-NLS-2$
    final Pattern newPattern = Pattern
        .compile("^\\+\\+\\+ (" + newPrefix + "(.+))$"); //$NON-NLS-1$ //$NON-NLS-2$

    int i = 0;
    while (i < rt.size()) {
      String line = rt.getString(i);

      Matcher diffMatcher = diffPattern.matcher(line);
      Matcher oldMatcher = oldPattern.matcher(line);
      Matcher newMatcher = newPattern.matcher(line);
      if (diffMatcher.find()) {
        String group = diffMatcher.group(2); // old path
        IProject project = getProject(group);
        IPath newPath = computeWorkspacePath(new Path(group), project);
        line = line.replaceAll(diffMatcher.group(1), newPath.toString());
        group = diffMatcher.group(4); // new path
        newPath = computeWorkspacePath(new Path(group), project);
        line = line.replaceAll(diffMatcher.group(3), newPath.toString());
      } else if (oldMatcher.find()) {
        String group = oldMatcher.group(2);
        IProject project = getProject(group);
        IPath newPath = computeWorkspacePath(new Path(group), project);
        line = line.replaceAll(oldMatcher.group(1), newPath.toString());
      } else if (newMatcher.find()) {
        String group = newMatcher.group(2);
        IProject project = getProject(group);
        IPath newPath = computeWorkspacePath(new Path(group), project);
        line = line.replaceAll(newMatcher.group(1), newPath.toString());
      }
      newSb.append(line);

      i++;
      if (i < rt.size() || !rt.isMissingNewlineAtEnd())
        newSb.append(rt.getLineDelimiter());
    }
    // reset sb to newSb
    sb.setLength(0);
    sb.append(newSb);
  }
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

  }

  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

   * @throws IOException
   *             the repository cannot be read.
   */
  public static BlameResult create(BlameGenerator gen) throws IOException {
    String path = gen.getResultPath();
    RawText contents = gen.getResultContents();
    if (contents == null) {
      gen.release();
      return null;
    }
    return new BlameResult(gen, path, contents);
View Full Code Here

          if (0 <= entry)
            gen.push(null, dc.getEntry(entry).getObjectId());

          File inTree = new File(repo.getWorkTree(), path);
          if (inTree.isFile())
            gen.push(null, new RawText(inTree));
        }
      }
      return gen.computeBlameResult();
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
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 = 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)); //$NON-NLS-1$ //$NON-NLS-2$
        lastConflictingName = null;
      }
      if (chunk.getConflictState() == ConflictState.FIRST_CONFLICTING_RANGE) {
        // found the start of an conflict
        out.write(("<<<<<<< " + seqName.get(chunk.getSequenceIndex()) + //$NON-NLS-1$
            "\n").getBytes(charsetName)); //$NON-NLS-1$
        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" : "======= " //$NON-NLS-1$ //$NON-NLS-2$
            + lastConflictingName + "\n").getBytes(charsetName)); //$NON-NLS-1$
      }
      // 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

TOP

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

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.