Skip to content

Commit

Permalink
[Fix JENKINS-22343] JGit now shows first revision in repo correctly
Browse files Browse the repository at this point in the history
The first revision in the repository has no parent.  The code assumed
all commits have at least one parent.
  • Loading branch information
MarkEWaite committed May 8, 2014
1 parent 8b7f276 commit ad1622e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 20 additions & 2 deletions src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java
Expand Up @@ -872,7 +872,25 @@ void format(RevCommit commit, @Nullable RevCommit parent, PrintWriter pw) throws
Repository repo = getRepository();
ObjectReader or = repo.newObjectReader();
TreeWalk tw = new TreeWalk(or);
tw.reset(parent!=null ? parent.getTree() : commit.getParent(0).getTree(), commit.getTree());
RevTree revTree = null;
if (parent != null) {
/* Caller provided a parent commit, use it */
tw.reset(parent.getTree(), commit.getTree());
} else {
if (commit.getParentCount() > 0) {
/* Caller failed to provide parent, but a parent
* is available, so use the parent in the walk
*/
tw.reset(commit.getParent(0).getTree(), commit.getTree());
} else {
/* First commit in repo has 0 parent count, but
* the TreeWalk requires exactly two nodes for its
* walk. Use the same node twice to satisfy
* TreeWalk. See JENKINS-22343 for details.
*/
tw.reset(commit.getTree(), commit.getTree());
}
}
tw.setRecursive(true);
tw.setFilter(TreeFilter.ANY_DIFF);

Expand Down Expand Up @@ -1347,7 +1365,7 @@ public List<String> showRevision(ObjectId from, ObjectId to) throws GitException
PrintWriter pw = new PrintWriter(sw);
RawFormatter f = new RawFormatter();
for (RevCommit c : w) {
if (c.getParentCount()==1) {
if (c.getParentCount()<=1) {
f.format(c,null,pw);
} else {
// the effect of the -m option, which makes the diff produce for each parent of a merge commit
Expand Down
Expand Up @@ -2055,12 +2055,7 @@ public boolean apply(String detail) {
assertTrue(commits.contains("commit 51de9eda47ca8dcf03b2af58dfff7355585f0d0c"));
}

/* Is implemented in JGit, but returns no results. Temporarily
* marking this test as not implemented in JGit so that its
* failure does not distract from other development.
*/
@Bug(22343)
@NotImplementedInJGit
public void test_show_revision_for_first_commit() throws Exception {
w.init();
w.touch("a");
Expand Down

0 comments on commit ad1622e

Please sign in to comment.