Package org.eclipse.jgit.diff

Examples of org.eclipse.jgit.diff.DiffFormatter


   * of the command. Don't call this method twice on an instance.
   *
   * @return a DiffEntry for each path which is different
   */
  public List<DiffEntry> call() throws GitAPIException, IOException {
    final DiffFormatter diffFmt = new DiffFormatter(
        new BufferedOutputStream(out));
    diffFmt.setRepository(repo);
    diffFmt.setProgressMonitor(monitor);
    try {
      if (cached) {
        if (oldTree == null) {
          ObjectId head = repo.resolve(HEAD + "^{tree}");
          if (head == null)
            throw new NoHeadException(JGitText.get().cannotReadTree);
          CanonicalTreeParser p = new CanonicalTreeParser();
          ObjectReader reader = repo.newObjectReader();
          try {
            p.reset(reader, head);
          } finally {
            reader.release();
          }
          oldTree = p;
        }
        newTree = new DirCacheIterator(repo.readDirCache());
      } else {
        if (oldTree == null)
          oldTree = new DirCacheIterator(repo.readDirCache());
        if (newTree == null)
          newTree = new FileTreeIterator(repo);
      }

      diffFmt.setPathFilter(pathFilter);
      if (contextLines >= 0)
        diffFmt.setContext(contextLines);
      if (destinationPrefix != null)
        diffFmt.setNewPrefix(destinationPrefix);
      if (sourcePrefix != null)
        diffFmt.setOldPrefix(sourcePrefix);

      List<DiffEntry> result = diffFmt.scan(oldTree, newTree);
      if (showNameAndStatusOnly) {
        return result;
      } else {
        diffFmt.format(result);
        diffFmt.flush();
        return result;
      }
    } finally {
      diffFmt.release();
    }
  }
View Full Code Here


    PersonIdent author = commitToPick.getAuthorIdent();
    String authorScript = toAuthorScript(author);
    createFile(rebaseDir, AUTHOR_SCRIPT, authorScript);
    createFile(rebaseDir, MESSAGE, commitToPick.getFullMessage());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DiffFormatter df = new DiffFormatter(bos);
    df.setRepository(repo);
    df.format(commitToPick.getParent(0), commitToPick);
    createFile(rebaseDir, PATCH, new String(bos.toByteArray(),
        Constants.CHARACTER_ENCODING));
    createFile(rebaseDir, STOPPED_SHA, repo.newObjectReader().abbreviate(
        commitToPick).name());
    // Remove cherry pick state file created by CherryPickCommand, it's not
View Full Code Here

    PersonIdent author = commitToPick.getAuthorIdent();
    String authorScript = toAuthorScript(author);
    createFile(rebaseDir, AUTHOR_SCRIPT, authorScript);
    createFile(rebaseDir, MESSAGE, commitToPick.getFullMessage());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DiffFormatter df = new DiffFormatter(bos);
    df.setRepository(repo);
    df.format(commitToPick.getParent(0), commitToPick);
    createFile(rebaseDir, PATCH, new String(bos.toByteArray(),
        Constants.CHARACTER_ENCODING));
    createFile(rebaseDir, STOPPED_SHA, repo.newObjectReader().abbreviate(
        commitToPick).name());
    // Remove cherry pick state file created by CherryPickCommand, it's not
View Full Code Here

    PersonIdent author = commitToPick.getAuthorIdent();
    String authorScript = toAuthorScript(author);
    createFile(rebaseDir, AUTHOR_SCRIPT, authorScript);
    createFile(rebaseDir, MESSAGE, commitToPick.getFullMessage());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DiffFormatter df = new DiffFormatter(bos);
    df.setRepository(repo);
    df.format(commitToPick.getParent(0), commitToPick);
    createFile(rebaseDir, PATCH, new String(bos.toByteArray(),
        Constants.CHARACTER_ENCODING));
    createFile(rebaseDir, STOPPED_SHA, repo.newObjectReader().abbreviate(
        commitToPick).name());
    // Remove cherry pick state file created by CherryPickCommand, it's not
View Full Code Here

      return "";
    }

    TemporaryBuffer.Heap buf =
        new TemporaryBuffer.Heap(args.settings.maximumDiffSize);
    DiffFormatter fmt = new DiffFormatter(buf);
    Repository git;
    try {
      git = args.server.openRepository(change.getProject());
    } catch (IOException e) {
      log.error("Cannot open repository to format patch", e);
      return "";
    }
    try {
      fmt.setRepository(git);
      fmt.setDetectRenames(true);
      fmt.format(patchList.getOldId(), patchList.getNewId());
      return RawParseUtils.decode(buf.toByteArray());
    } catch (IOException e) {
      if (JGitText.get().inMemoryBufferLimitExceeded.equals(e.getMessage())) {
        return "";
      }
      log.error("Cannot format patch", e);
      return "";
    } finally {
      fmt.release();
      git.close();
    }
  }
View Full Code Here

      walk.setRecursive(true);
      walk.addTree(aTree);
      walk.addTree(bTree);
      walk.setFilter(TreeFilter.ANY_DIFF);

      DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
      df.setRepository(repo);
      df.setDiffComparator(cmp);
      df.setDetectRenames(true);
      List<DiffEntry> diffEntries = df.scan(aTree, bTree);

      final int cnt = diffEntries.size();
      final PatchListEntry[] entries = new PatchListEntry[1 + cnt];
      entries[0] = newCommitMessage(cmp, repo, reader, //
          againstParent ? null : aCommit, b);
      for (int i = 0; i < cnt; i++) {
        FileHeader fh = df.toFileHeader(diffEntries.get(i));
        entries[1 + i] = newEntry(aTree, fh);
      }
      return new PatchList(a, b, againstParent, entries);
    } finally {
      reader.release();
View Full Code Here

    private static String parseDiff(Context context, RevWalk walk, RevCommit revCommit) throws Exception {
        if (context.isIndexingDiff() && revCommit.getParentCount() > 0) {
            RevCommit parentCommit = walk.parseCommit(revCommit.getParent(0).getId());
            ByteArrayOutputStream diffOutputStream = new ByteArrayOutputStream();
            DiffFormatter diffFormatter = new DiffFormatter(diffOutputStream);
            diffFormatter.setRepository(context.getRepository());
            diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
            diffFormatter.setDetectRenames(true);
            diffFormatter.format(parentCommit.getTree(),revCommit.getTree());
            return new String(diffOutputStream.toByteArray());
        } else {
            return null;
        }
    }
View Full Code Here

  }

  @Override
  protected void init(final Repository repository, final String gitDir) {
    super.init(repository, gitDir);
    diffFmt = new DiffFormatter(new BufferedOutputStream(outs));
  }
View Full Code Here

    PersonIdent author = commitToPick.getAuthorIdent();
    String authorScript = toAuthorScript(author);
    createFile(rebaseDir, AUTHOR_SCRIPT, authorScript);
    createFile(rebaseDir, MESSAGE, commitToPick.getFullMessage());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DiffFormatter df = new DiffFormatter(bos);
    df.setRepository(repo);
    df.format(commitToPick.getParent(0), commitToPick);
    createFile(rebaseDir, PATCH, new String(bos.toByteArray(),
        Constants.CHARACTER_ENCODING));
    createFile(rebaseDir, STOPPED_SHA, repo.newObjectReader().abbreviate(
        commitToPick).name());
    return new RebaseResult(commitToPick);
View Full Code Here

        if ( JGitUtils.hasCommits( repository ) )
        {
            RevWalk rw = new RevWalk( repository );
            RevCommit realParant = commit.getParentCount() > 0 ? commit.getParent( 0 ) : commit;
            RevCommit parent = rw.parseCommit( realParant.getId() );
            DiffFormatter df = new DiffFormatter( DisabledOutputStream.INSTANCE );
            df.setRepository( repository );
            df.setDiffComparator( RawTextComparator.DEFAULT );
            df.setDetectRenames( true );
            List<DiffEntry> diffs = df.scan( parent.getTree(), commit.getTree() );
            for ( DiffEntry diff : diffs )
            {
                list.add( new ScmFile( diff.getNewPath(), ScmFileStatus.CHECKED_IN ) );
            }
            rw.release();
View Full Code Here

TOP

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

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.