@Signature public Memory diff(ArrayMemory settings) throws GitAPIException { DiffCommand command = getWrappedObject().diff(); if (settings != null) { command.setCached(settings.valueOfIndex("cached").toBoolean()); Memory contextLines = settings.valueOfIndex("contextLines"); if (contextLines.isNotNull()) { command.setContextLines(contextLines.toInteger()); } Memory destPrefix = settings.valueOfIndex("destPrefix"); if (destPrefix.isNotNull()) { command.setDestinationPrefix(destPrefix.toString()); } Memory sourcePrefix = settings.valueOfIndex("sourcePrefix"); if (sourcePrefix.isNotNull()) { command.setSourcePrefix(sourcePrefix.toString()); } command.setShowNameAndStatusOnly(settings.valueOfIndex("showNameAndStatusOnly").toBoolean()); Memory pathFilter = settings.valueOfIndex("pathFilter"); if (pathFilter.isNotNull()) { command.setPathFilter(PathFilter.create(pathFilter.toString())); } } List<DiffEntry> call = command.call(); return GitUtils.valueOfDiffEntries(call); }
public DiffScmResult callDiff( Git git, ScmVersion startRevision, ScmVersion endRevision ) throws IOException, GitAPIException, ScmException { AbstractTreeIterator oldTree = null; if ( startRevision != null && StringUtils.isNotEmpty( startRevision.getName().trim() ) ) { String startRev = startRevision.getName().trim(); oldTree = getTreeIterator( git.getRepository(), startRev ); } AbstractTreeIterator newTree = null; if ( endRevision != null && StringUtils.isNotEmpty( endRevision.getName().trim() ) ) { String endRev = endRevision.getName().trim(); newTree = getTreeIterator( git.getRepository(), endRev ); } OutputStream out = new ByteArrayOutputStream(); git.diff().setOutputStream( out ).setOldTree( oldTree ).setNewTree( newTree ).setCached( false ).call(); git.diff().setOutputStream( out ).setOldTree( oldTree ).setNewTree( newTree ).setCached( true ).call(); out.flush(); GitDiffConsumer consumer = new GitDiffConsumer( getLogger(), null ); String fullDiff = out.toString(); out.close(); String[] lines = fullDiff.split( "\n" ); for ( String aLine : lines ) { consumer.consumeLine( aLine ); } return new DiffScmResult( "JGit diff", consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch() ); }
public DiffScmResult callDiff( Git git, ScmVersion startRevision, ScmVersion endRevision ) throws IOException, GitAPIException, ScmException { AbstractTreeIterator oldTree = null; if ( startRevision != null && StringUtils.isNotEmpty( startRevision.getName().trim() ) ) { String startRev = startRevision.getName().trim(); oldTree = getTreeIterator( git.getRepository(), startRev ); } AbstractTreeIterator newTree = null; if ( endRevision != null && StringUtils.isNotEmpty( endRevision.getName().trim() ) ) { String endRev = endRevision.getName().trim(); newTree = getTreeIterator( git.getRepository(), endRev ); } OutputStream out = new ByteArrayOutputStream(); git.diff().setOutputStream( out ).setOldTree( oldTree ).setNewTree( newTree ).setCached( false ).call(); git.diff().setOutputStream( out ).setOldTree( oldTree ).setNewTree( newTree ).setCached( true ).call(); out.flush(); GitDiffConsumer consumer = new GitDiffConsumer( getLogger(), null ); String fullDiff = out.toString(); out.close(); String[] lines = fullDiff.split( "\n" ); for ( String aLine : lines ) { consumer.consumeLine( aLine ); } return new DiffScmResult( "JGit diff", consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch() ); }