/** * Format the differences between two trees. * * The patch is expressed as instructions to modify {@code a} to make it * {@code b}. * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @throws java.io.IOException * trees cannot be read, file contents cannot be read, or the * patch cannot be output. */ public void format(AnyObjectId a, AnyObjectId b) throws IOException { format(scan(a, b)); }
/** * Format the differences between two trees. * * The patch is expressed as instructions to modify {@code a} to make it * {@code b}. * * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @throws java.io.IOException * trees cannot be read, file contents cannot be read, or the * patch cannot be output. */ public void format(RevTree a, RevTree b) throws IOException { format(scan(a, b)); }
/** * Format the differences between two trees. * * The patch is expressed as instructions to modify {@code a} to make it * {@code b}. * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @throws java.io.IOException * trees cannot be read, file contents cannot be read, or the * patch cannot be output. */ public void format(AbstractTreeIterator a, AbstractTreeIterator b) throws IOException { format(scan(a, b)); }
/** * Determine the differences between two trees. * * No output is created, instead only the file paths that are different are * returned. Callers may choose to format these paths themselves, or convert * them into {@link org.eclipse.jgit.patch.FileHeader} instances with a * complete edit list by calling {@link #toFileHeader(DiffEntry)}. * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @return the paths that are different. * @throws java.io.IOException * trees cannot be read or file contents cannot be read. */ public List<DiffEntry> scan(RevTree a, RevTree b) throws IOException { assertHaveReader(); AbstractTreeIterator aIterator = makeIteratorFromTreeOrNull(a); AbstractTreeIterator bIterator = makeIteratorFromTreeOrNull(b); return scan(aIterator, bIterator); }
/** * Determine the differences between two trees. * * No output is created, instead only the file paths that are different are * returned. Callers may choose to format these paths themselves, or convert * them into {@link org.eclipse.jgit.patch.FileHeader} instances with a * complete edit list by calling {@link #toFileHeader(DiffEntry)}. * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @return the paths that are different. * @throws java.io.IOException * trees cannot be read or file contents cannot be read. */ public List<DiffEntry> scan(AnyObjectId a, AnyObjectId b) throws IOException { assertHaveReader(); try (RevWalk rw = new RevWalk(reader)) { RevTree aTree = a != null ? rw.parseTree(a) : null; RevTree bTree = b != null ? rw.parseTree(b) : null; return scan(aTree, bTree); } }
List<DiffEntry> result = diffFmt.scan(oldTree, newTree); if (showNameAndStatusOnly) return result;
/** * Format the differences between two trees. * * The patch is expressed as instructions to modify {@code a} to make it * {@code b}. * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @throws IOException * trees cannot be read, file contents cannot be read, or the * patch cannot be output. */ public void format(AbstractTreeIterator a, AbstractTreeIterator b) throws IOException { format(scan(a, b)); }
/** * Format the differences between two trees. * * The patch is expressed as instructions to modify {@code a} to make it * {@code b}. * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @throws IOException * trees cannot be read, file contents cannot be read, or the * patch cannot be output. */ public void format(AnyObjectId a, AnyObjectId b) throws IOException { format(scan(a, b)); }
@Override public List<DiffEntry> call() throws Exception { return df.scan(parent.getTree(), commit.getTree()); } });
@Override public List<DiffEntry> call() throws Exception { return df.scan(parent.getTree(), commit.getTree()); } });
try( DiffFormatter diffFormatter = new DiffFormatter( DisabledOutputStream.INSTANCE ) ) { diffFormatter.setRepository( git.getRepository() ); List<DiffEntry> diffEntries = diffFormatter.scan( oldTreeIterator, newTreeIterator ); FileHeader fileHeader = diffFormatter.toFileHeader( diffEntries.get( 0 ) ); return fileHeader.toEditList(); }
DiffFormatter formatter = new DiffFormatter( System.out ); formatter.setRepository( git.getRepository() ); AbstractTreeIterator commitTreeIterator = prepareTreeParser( git.getRepository(), Constants.HEAD ); FileTreeIterator workTreeIterator = new FileTreeIterator( git.getRepository() ); List<DiffEntry> diffEntries = formatter.scan( commitTreeIterator, workTreeIterator ); for( DiffEntry entry : diffEntries ) { System.out.println( "Entry: " + entry + ", from: " + entry.getOldId() + ", to: " + entry.getNewId() ); formatter.format( entry ); }
/** * Compares the old tree and the new tree to get the list of the affected files. */ private List<DiffEntry> compareTrees( @Nullable ObjectId prevTreeId, ObjectId nextTreeId, TreeFilter filter) { try (DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) { diffFormatter.setRepository(jGitRepository); diffFormatter.setPathFilter(filter); return diffFormatter.scan(prevTreeId, nextTreeId); } catch (IOException e) { throw new StorageException("failed to compare two trees: " + prevTreeId + " vs. " + nextTreeId, e); } }
/** * Compares the old tree and the new tree to get the list of the affected files. */ private List<DiffEntry> compareTrees( @Nullable ObjectId prevTreeId, ObjectId nextTreeId, TreeFilter filter) { try (DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) { diffFormatter.setRepository(jGitRepository); diffFormatter.setPathFilter(filter); return diffFormatter.scan(prevTreeId, nextTreeId); } catch (IOException e) { throw new StorageException("failed to compare two trees: " + prevTreeId + " vs. " + nextTreeId, e); } }
/** * Compares the old tree and the new tree to get the list of the affected files. */ private List<DiffEntry> compareTrees( @Nullable ObjectId prevTreeId, ObjectId nextTreeId, TreeFilter filter) { try (DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) { diffFormatter.setRepository(jGitRepository); diffFormatter.setPathFilter(filter); return diffFormatter.scan(prevTreeId, nextTreeId); } catch (IOException e) { throw new StorageException("failed to compare two trees: " + prevTreeId + " vs. " + nextTreeId, e); } }
ObjectReader reader = git.getRepository().newObjectReader(); CanonicalTreeParser oldTreeIter = new CanonicalTreeParser(); ObjectId oldTree = git.getRepository().resolve( "HEAD^{tree}" ); oldTreeIter.reset( reader, oldTree ); CanonicalTreeParser newTreeIter = new CanonicalTreeParser(); ObjectId newTree = git.getRepository().resolve( "HEAD~1^{tree}" ); newTreeIter.reset( reader, newTree ); DiffFormatter diffFormatter = new DiffFormatter( DisabledOutputStream.INSTANCE ); diffFormatter.setRepository( git.getRepository() ); List<DiffEntry> entries = diffFormatter.scan( oldTreeIter, newTreeIter ); for( DiffEntry entry : entries ) { System.out.println( entry.getChangeType() ); }
/** * Scans the working dir for active changes and returns a list of differences. * * @return - List of DiffEntry. */ public List<DiffEntry> scanWorkingDiffs() { if (isUndefined()) { return new ArrayList<>(); } val workTreeIterator = new FileTreeIterator(git.getRepository()); val oldTreeIter = new CanonicalTreeParser(); try (ObjectReader reader = git.getRepository().newObjectReader()) { oldTreeIter.reset(reader, git.getRepository().resolve("HEAD^{tree}")); val formatter = new DiffFormatter(new ByteArrayOutputStream()); formatter.setRepository(git.getRepository()); return formatter.scan(oldTreeIter, workTreeIterator); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return new ArrayList<>(); }
private List<DiffEntry> getDiffs(RevCommit commit, RevCommit parent) throws IOException { DiffFormatter formatter = new DiffFormatter(DisabledOutputStream.INSTANCE); formatter.setRepository(repository); formatter.setDiffComparator(RawTextComparator.DEFAULT); formatter.setDetectRenames(true); return formatter.scan(parent.getTree(), commit.getTree()); } }
private void showDiff(RevCommit c) throws IOException { final RevTree a = c.getParent(0).getTree(); final RevTree b = c.getTree(); if (showNameAndStatusOnly) Diff.nameStatus(outw, diffFmt.scan(a, b)); else { outw.flush(); diffFmt.format(a, b); diffFmt.flush(); } outw.println(); } }
private void showDiff(RevCommit c) throws IOException { final RevTree a = c.getParent(0).getTree(); final RevTree b = c.getTree(); if (showNameAndStatusOnly) Diff.nameStatus(outw, diffFmt.scan(a, b)); else { outw.flush(); diffFmt.format(a, b); diffFmt.flush(); } outw.println(); } }