Fix NPE on commit in empty Repository
NPE occured when committing in an empty repository. Bug: 321858 Change-Id: Ibddb056c32c14c1444785501c43b95fdf64884b1 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
This commit is contained in:
parent
09130b8731
commit
9a6a433576
|
@ -53,6 +53,7 @@
|
||||||
import org.eclipse.jgit.revwalk.RevTree;
|
import org.eclipse.jgit.revwalk.RevTree;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
|
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
|
||||||
|
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||||
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
|
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
|
||||||
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
import org.eclipse.jgit.treewalk.filter.TreeFilter;
|
||||||
|
@ -100,6 +101,7 @@ public class IndexDiff {
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param revstr
|
* @param revstr
|
||||||
* symbolic name e.g. HEAD
|
* symbolic name e.g. HEAD
|
||||||
|
* An EmptyTreeIterator is used if <code>revstr</code> cannot be resolved.
|
||||||
* @param workingTreeIterator
|
* @param workingTreeIterator
|
||||||
* iterator for working directory
|
* iterator for working directory
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
@ -108,7 +110,10 @@ public IndexDiff(Repository repository, String revstr,
|
||||||
WorkingTreeIterator workingTreeIterator) throws IOException {
|
WorkingTreeIterator workingTreeIterator) throws IOException {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
ObjectId objectId = repository.resolve(revstr);
|
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;
|
this.initialWorkingTreeIterator = workingTreeIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +122,7 @@ public IndexDiff(Repository repository, String revstr,
|
||||||
*
|
*
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param objectId
|
* @param objectId
|
||||||
* tree id
|
* tree id. If null, an EmptyTreeIterator is used.
|
||||||
* @param workingTreeIterator
|
* @param workingTreeIterator
|
||||||
* iterator for working directory
|
* iterator for working directory
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
@ -125,10 +130,14 @@ public IndexDiff(Repository repository, String revstr,
|
||||||
public IndexDiff(Repository repository, ObjectId objectId,
|
public IndexDiff(Repository repository, ObjectId objectId,
|
||||||
WorkingTreeIterator workingTreeIterator) throws IOException {
|
WorkingTreeIterator workingTreeIterator) throws IOException {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
tree = new RevWalk(repository).parseTree(objectId);
|
if (objectId != null)
|
||||||
|
tree = new RevWalk(repository).parseTree(objectId);
|
||||||
|
else
|
||||||
|
tree = null;
|
||||||
this.initialWorkingTreeIterator = workingTreeIterator;
|
this.initialWorkingTreeIterator = workingTreeIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the diff operation. Until this is called, all lists will be empty
|
* Run the diff operation. Until this is called, all lists will be empty
|
||||||
*
|
*
|
||||||
|
@ -142,7 +151,10 @@ public boolean diff() throws IOException {
|
||||||
treeWalk.reset();
|
treeWalk.reset();
|
||||||
treeWalk.setRecursive(true);
|
treeWalk.setRecursive(true);
|
||||||
// add the trees (tree, dirchache, workdir)
|
// 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(new DirCacheIterator(dirCache));
|
||||||
treeWalk.addTree(initialWorkingTreeIterator);
|
treeWalk.addTree(initialWorkingTreeIterator);
|
||||||
treeWalk.setFilter(TreeFilter.ANY_DIFF);
|
treeWalk.setFilter(TreeFilter.ANY_DIFF);
|
||||||
|
|
Loading…
Reference in New Issue