use of org.apache.maven.scm.provider.git.command.diff.GitDiffConsumer in project maven-scm by apache.
the class JGitDiffCommand method callDiff.
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());
}
use of org.apache.maven.scm.provider.git.command.diff.GitDiffConsumer in project maven-scm by apache.
the class GitDiffCommand method executeDiffCommand.
/**
* {@inheritDoc}
*/
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion) throws ScmException {
GitDiffConsumer consumer = new GitDiffConsumer(getLogger(), fileSet.getBasedir());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
Commandline clDiff2Index = createCommandLine(fileSet.getBasedir(), startVersion, endVersion, false);
exitCode = GitCommandLineUtils.execute(clDiff2Index, consumer, stderr, getLogger());
if (exitCode != 0) {
return new DiffScmResult(clDiff2Index.toString(), "The git-diff command failed.", stderr.getOutput(), false);
}
Commandline clDiff2Head = createCommandLine(fileSet.getBasedir(), startVersion, endVersion, true);
exitCode = GitCommandLineUtils.execute(clDiff2Head, consumer, stderr, getLogger());
if (exitCode != 0) {
return new DiffScmResult(clDiff2Head.toString(), "The git-diff command failed.", stderr.getOutput(), false);
}
return new DiffScmResult(clDiff2Index.toString(), consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch());
}
Aggregations