Package org.eclipse.jgit.diff

Examples of org.eclipse.jgit.diff.DiffFormatter


        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


    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

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        RawText rt1 = new RawText(string1.getBytes());
        RawText rt2 = new RawText(string2.getBytes());
        EditList diffList = new EditList();
        diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt1, rt2));
        new DiffFormatter(out).format(diffList, rt1, rt2);
        return out.toString();
    }
View Full Code Here

    private 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

   * 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}");
          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);
    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

          new NullProgressMonitor());
    else
      gitMonitor = new EclipseGitProgressTransformer(monitor);

    final StringBuilder sb = new StringBuilder();
    final DiffFormatter diffFmt = new DiffFormatter(
        new ByteArrayOutputStream() {

          @Override
          public synchronized void write(byte[] b, int off, int len) {
            super.write(b, off, len);
            try {
              if (currentEncoding == null)
                sb.append(toString("UTF-8")); //$NON-NLS-1$
              else
                sb.append(toString(currentEncoding));
            } catch (UnsupportedEncodingException e) {
              sb.append(toString());
            }
            reset();
          }
        }) {
      private IProject project;

      @Override
      public void format(DiffEntry ent) throws IOException,
          CorruptObjectException, MissingObjectException {
        // for "workspace patches" add project header each time project changes
        if (DiffHeaderFormat.WORKSPACE == headerFormat) {
          IProject p = getProject(ent);
          if (!p.equals(project)) {
            project = p;
            getOutputStream().write(
                encodeASCII("#P " + project.getName() + "\n")); //$NON-NLS-1$ //$NON-NLS-2$
          }
        }
        super.format(ent);
      }
    };

    diffFmt.setProgressMonitor(gitMonitor);
    diffFmt.setContext(contextLines);

    if (headerFormat != null && headerFormat != DiffHeaderFormat.NONE)
      writeGitPatchHeader(sb);

    diffFmt.setRepository(repository);
    diffFmt.setPathFilter(pathFilter);

    try {
      if (commit != null) {
        RevCommit[] parents = commit.getParents();
        if (parents.length > 1)
          throw new IllegalStateException(
              CoreText.CreatePatchOperation_cannotCreatePatchForMergeCommit);

        ObjectId parentId;
        if (parents.length > 0)
          parentId = parents[0].getId();
        else
          parentId = null;
        List<DiffEntry> diffs = diffFmt.scan(parentId, commit.getId());
        for (DiffEntry ent : diffs) {
          String path;
          if (ChangeType.DELETE.equals(ent.getChangeType()))
            path = ent.getOldPath();
          else
            path = ent.getNewPath();
          currentEncoding = CompareCoreUtils.getResourceEncoding(repository, path);
          diffFmt.format(ent);
        }
      } else
        diffFmt.format(
            new DirCacheIterator(repository.readDirCache()),
            new FileTreeIterator(repository));
    } catch (IOException e) {
      Activator.logError(CoreText.CreatePatchOperation_patchFileCouldNotBeWritten, e);
    }
View Full Code Here

    }

    protected String computePatch( Iterable<DiffEntry> entries,
                                   Repository repository ) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        DiffFormatter formatter = new DiffFormatter(output);
        formatter.setRepository(repository);
        for (DiffEntry entry : entries) {
            formatter.format(entry);
        }
        return output.toString(DIFF_CHARSET_NAME);
    }
View Full Code Here

                    default:
                        // skip
                        break;
                }
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                DiffFormatter formatter = new DiffFormatter(output);
                formatter.setRepository(repository);
                formatter.format(fileDiff);
                String diff = output.toString("UTF-8");
                print(diff);
            }
        } finally {
            walker.dispose();
View Full Code Here

                setNewTree(newTreeParser).
                setPathFilter(PathFilter.create("README.md")).
                call();
        for (DiffEntry entry : diff) {
            System.out.println("Entry: " + entry + ", from: " + entry.getOldId() + ", to: " + entry.getNewId());
            DiffFormatter formatter = new DiffFormatter(System.out);
            formatter.setRepository(repository);
            formatter.format(entry);
        }

        repository.close();
    }
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.