fix NPE in diff command

Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/7ccb6e71
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/7ccb6e71
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/7ccb6e71

Branch: refs/heads/master
Commit: 7ccb6e71207485eb2e91349ae111438f98dddcd3
Parents: d0c2a18
Author: imod <d...@fortysix.ch>
Authored: Tue Jun 18 19:50:24 2013 +0200
Committer: imod <d...@fortysix.ch>
Committed: Tue Jun 18 19:50:24 2013 +0200

----------------------------------------------------------------------
 .../git/jgit/command/diff/JGitDiffCommand.java  | 21 +++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/7ccb6e71/src/main/java/org/apache/maven/scm/provider/git/jgit/command/diff/JGitDiffCommand.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/maven/scm/provider/git/jgit/command/diff/JGitDiffCommand.java
 
b/src/main/java/org/apache/maven/scm/provider/git/jgit/command/diff/JGitDiffCommand.java
index 3feb1b9..db77fe9 100644
--- 
a/src/main/java/org/apache/maven/scm/provider/git/jgit/command/diff/JGitDiffCommand.java
+++ 
b/src/main/java/org/apache/maven/scm/provider/git/jgit/command/diff/JGitDiffCommand.java
@@ -18,6 +18,7 @@ import org.apache.maven.scm.command.diff.AbstractDiffCommand;
 import org.apache.maven.scm.command.diff.DiffScmResult;
 import org.apache.maven.scm.provider.ScmProviderRepository;
 import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.codehaus.plexus.util.StringUtils;
 import org.eclipse.jgit.api.DiffCommand;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.diff.DiffEntry;
@@ -37,12 +38,26 @@ public class JGitDiffCommand extends AbstractDiffCommand 
implements GitCommand {
                try {
                        Git git = Git.open(fileSet.getBasedir());
 
+                       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();
-                       DiffCommand diff = 
git.diff().setOutputStream(out).setOldTree(getTreeIterator(git.getRepository(), 
startRevision.getName())).setNewTree(getTreeIterator(git.getRepository(), 
endRevision.getName()));
+
+                       DiffCommand diff = 
git.diff().setOutputStream(out).setOldTree(oldTree).setNewTree(newTree);
                        List<DiffEntry> entries = diff.call();
                        List<ScmFile> changedFiles = new ArrayList<ScmFile>();
-                       
-                       // TODO get differences 
+
+                       // TODO get differences (but actually these are 
captured in the out
+                       // already...)
                        Map<String, CharSequence> differences = new 
HashMap<String, CharSequence>();
 
                        for (DiffEntry diffEntry : entries) {

Reply via email to