Package org.eclipse.jgit.diff

Examples of org.eclipse.jgit.diff.DiffFormatter


    List<PathChangeModel> list = new ArrayList<PathChangeModel>();
    if (!hasCommits(repository)) {
      return list;
    }
    try {
      DiffFormatter df = new DiffFormatter(null);
      df.setRepository(repository);
      df.setDiffComparator(RawTextComparator.DEFAULT);
      df.setDetectRenames(true);

      List<DiffEntry> diffEntries = df.scan(startCommit.getTree(), endCommit.getTree());
      for (DiffEntry diff : diffEntries) {
        PathChangeModel pcm = PathChangeModel.from(diff,  endCommit.getName());
        list.add(pcm);
      }
      Collections.sort(list);
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

    List<PathChangeModel> list = new ArrayList<PathChangeModel>();
    if (!hasCommits(repository)) {
      return list;
    }
    try {
      DiffFormatter df = new DiffFormatter(null);
      df.setRepository(repository);
      df.setDiffComparator(RawTextComparator.DEFAULT);
      df.setDetectRenames(true);

      List<DiffEntry> diffEntries = df.scan(startCommit.getTree(), endCommit.getTree());
      for (DiffEntry diff : diffEntries) {
        PathChangeModel pcm = PathChangeModel.from(diff,  endCommit.getName());
        list.add(pcm);
      }
      Collections.sort(list);
View Full Code Here

    DiffStat stat = null;
    String diff = null;
    try {
      final ByteArrayOutputStream os = new ByteArrayOutputStream();
      RawTextComparator cmp = RawTextComparator.DEFAULT;
      DiffFormatter df;
      switch (outputType) {
      case HTML:
        df = new GitBlitDiffFormatter(os, commit.getName());
        break;
      case PLAIN:
      default:
        df = new DiffFormatter(os);
        break;
      }
      df.setRepository(repository);
      df.setDiffComparator(cmp);
      df.setDetectRenames(true);

      RevTree commitTree = commit.getTree();
      RevTree baseTree;
      if (baseCommit == null) {
        if (commit.getParentCount() > 0) {
          final RevWalk rw = new RevWalk(repository);
          RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
          rw.dispose();
          baseTree = parent.getTree();
        } else {
          // FIXME initial commit. no parent?!
          baseTree = commitTree;
        }
      } else {
        baseTree = baseCommit.getTree();
      }

      List<DiffEntry> diffEntries = df.scan(baseTree, commitTree);
      if (path != null && path.length() > 0) {
        for (DiffEntry diffEntry : diffEntries) {
          if (diffEntry.getNewPath().equalsIgnoreCase(path)) {
            df.format(diffEntry);
            break;
          }
        }
      } else {
        df.format(diffEntries);
      }
      if (df instanceof GitBlitDiffFormatter) {
        // workaround for complex private methods in DiffFormatter
        diff = ((GitBlitDiffFormatter) df).getHtml();
        stat = ((GitBlitDiffFormatter) df).getDiffStat();
      } else {
        diff = os.toString();
      }
      df.flush();
    } catch (Throwable t) {
      LOGGER.error("failed to generate commit diff!", t);
    }

    return new DiffOutput(outputType, diff, stat);
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

  // END -- Options shared with Log

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

   * 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 {
    final DiffFormatter diffFmt;
    if (out != null && !showNameAndStatusOnly)
      diffFmt = new DiffFormatter(new BufferedOutputStream(out));
    else
      diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
    diffFmt.setRepository(repo);
    diffFmt.setProgressMonitor(monitor);
    try {
      if (cached) {
        if (oldTree == null) {
          ObjectId head = repo.resolve(HEAD + "^{tree}"); //$NON-NLS-1$
          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);

      List<DiffEntry> result = diffFmt.scan(oldTree, newTree);
      if (showNameAndStatusOnly)
        return result;
      else {
        if (contextLines >= 0)
          diffFmt.setContext(contextLines);
        if (destinationPrefix != null)
          diffFmt.setNewPrefix(destinationPrefix);
        if (sourcePrefix != null)
          diffFmt.setOldPrefix(sourcePrefix);
        diffFmt.format(result);
        diffFmt.flush();
        return result;
      }
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } finally {
      diffFmt.release();
    }
  }
View Full Code Here

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

   *
   * @return a DiffEntry for each path which is different
   */
  @Override
  public List<DiffEntry> call() throws GitAPIException {
    final DiffFormatter diffFmt;
    if (out != null && !showNameAndStatusOnly)
      diffFmt = new DiffFormatter(new BufferedOutputStream(out));
    else
      diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
    if (ignoreWS)
      diffFmt.setDiffComparator(RawTextComparator.WS_IGNORE_ALL);
    diffFmt.setRepository(repo);
    diffFmt.setProgressMonitor(monitor);
    try {
      if (cached) {
        if (oldTree == null) {
          ObjectId head = repo.resolve(HEAD + "^{tree}"); //$NON-NLS-1$
          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);

      List<DiffEntry> result = diffFmt.scan(oldTree, newTree);
      if (showNameAndStatusOnly)
        return result;
      else {
        if (contextLines >= 0)
          diffFmt.setContext(contextLines);
        if (destinationPrefix != null)
          diffFmt.setNewPrefix(destinationPrefix);
        if (sourcePrefix != null)
          diffFmt.setOldPrefix(sourcePrefix);
        diffFmt.format(result);
        diffFmt.flush();
        return result;
      }
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } finally {
      diffFmt.release();
    }
  }
View Full Code Here

        l = DiffEntry.scan(tw);
        fromName = revCommit.getParent(0).getName();
      } else {
        RevWalk rw = null;
        DiffFormatter diffFormat = null;
        try {
          rw = new RevWalk(db);
          diffFormat = new DiffFormatter(NullOutputStream.INSTANCE);
          diffFormat.setRepository(db);
          if (filter != null)
            diffFormat.setPathFilter(filter);
          l = diffFormat.scan(new EmptyTreeIterator(), new CanonicalTreeParser(null, rw.getObjectReader(), revCommit.getTree()));
        } finally {
          diffFormat.release();
          rw.release();
        }
      }

      int pageSize = 100;
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.