summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJens Baumgart2010-08-09 05:14:38 (EDT)
committer Jens Baumgart2010-08-09 05:14:38 (EDT)
commit9a6a433576c8b1cedb5f3aff9cfecb8217881ddf (patch)
tree8c6b6053cca76ed62049471afff76a44b69c5a52
parent09130b8731cf17d24c4b0a77c8faf532bf22db2c (diff)
downloadjgit-9a6a433576c8b1cedb5f3aff9cfecb8217881ddf.zip
jgit-9a6a433576c8b1cedb5f3aff9cfecb8217881ddf.tar.gz
jgit-9a6a433576c8b1cedb5f3aff9cfecb8217881ddf.tar.bz2
Fix NPE on commit in empty Repositoryrefs/changes/67/1267/1
NPE occured when committing in an empty repository. Bug: 321858 Change-Id: Ibddb056c32c14c1444785501c43b95fdf64884b1 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index d4e6ac9..a721f4b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -53,6 +53,7 @@ import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
+import org.eclipse.jgit.treewalk.EmptyTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
@@ -100,6 +101,7 @@ public class IndexDiff {
* @param repository
* @param revstr
* symbolic name e.g. HEAD
+ * An EmptyTreeIterator is used if <code>revstr</code> cannot be resolved.
* @param workingTreeIterator
* iterator for working directory
* @throws IOException
@@ -108,7 +110,10 @@ public class IndexDiff {
WorkingTreeIterator workingTreeIterator) throws IOException {
this.repository = repository;
ObjectId objectId = repository.resolve(revstr);
- tree = new RevWalk(repository).parseTree(objectId);
+ if (objectId != null)
+ tree = new RevWalk(repository).parseTree(objectId);
+ else
+ tree = null;
this.initialWorkingTreeIterator = workingTreeIterator;
}
@@ -117,7 +122,7 @@ public class IndexDiff {
*
* @param repository
* @param objectId
- * tree id
+ * tree id. If null, an EmptyTreeIterator is used.
* @param workingTreeIterator
* iterator for working directory
* @throws IOException
@@ -125,10 +130,14 @@ public class IndexDiff {
public IndexDiff(Repository repository, ObjectId objectId,
WorkingTreeIterator workingTreeIterator) throws IOException {
this.repository = repository;
- tree = new RevWalk(repository).parseTree(objectId);
+ if (objectId != null)
+ tree = new RevWalk(repository).parseTree(objectId);
+ else
+ tree = null;
this.initialWorkingTreeIterator = workingTreeIterator;
}
+
/**
* Run the diff operation. Until this is called, all lists will be empty
*
@@ -142,7 +151,10 @@ public class IndexDiff {
treeWalk.reset();
treeWalk.setRecursive(true);
// add the trees (tree, dirchache, workdir)
- treeWalk.addTree(tree);
+ if (tree != null)
+ treeWalk.addTree(tree);
+ else
+ treeWalk.addTree(new EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(initialWorkingTreeIterator);
treeWalk.setFilter(TreeFilter.ANY_DIFF);