Fix sending of inline comments on commit message for initial change

Email notifications didn't include inline comments on the commit
message for the initial change. For the initial change PatchListLoader
creates an empty tree object for the a side, but PatchFile always
tried to parse the a side as commit. If it's not a commit PatchFile
can assume that this is the initial change and hence using an empty
text for the a side is correct in this case.

This error could be observed by running the LuceneQueryChangesTest in
Eclipse, the console showed a lot of stack traces caused by
IncorrectObjectTypeException in the CommentSender class.

  com.google.gerrit.server.mail.CommentSender :
  Cannot load /COMMIT_MSG from 318f37f6faeeebe601d9a91a7c98d08a6d3f6c3e in repo
  org.eclipse.jgit.errors.IncorrectObjectTypeException:
  Object 4b825dc642 is not a commit.

Full stack trace:
  http://paste.openstack.org/show/482173/

Bug: Issue 2251
Change-Id: I770d35153bd2b526240296a2e1a95ccc755fdfe1
This commit is contained in:
Edwin Kempin
2015-12-17 17:08:58 +01:00
committed by David Pursehouse
parent dc71c4c60d
commit fbb18ecdc2

View File

@@ -26,6 +26,7 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -56,7 +57,11 @@ public class PatchFile {
if (patchList.isAgainstParent()) {
a = Text.EMPTY;
} else {
a = Text.forCommit(reader, patchList.getOldId());
// For the initial commit, we have an empty tree on Side A
RevObject object = rw.parseAny(patchList.getOldId());
a = object instanceof RevCommit
? Text.forCommit(reader, object)
: Text.EMPTY;
}
b = Text.forCommit(reader, bCommit);