Browse Source

Merge "LogCommand.all(): filter out refs that do not refer to commit objects"

stable-3.0
Robin Rosenberg 12 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
8272f65730
  1. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
  2. 15
      org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java

@ -100,11 +100,17 @@ public class LogCommandTest extends RepositoryTestCase {
commits.add(git.commit().setMessage("initial commit").call());
TagCommand tagCmd = git.tag();
tagCmd.setName("tagname");
tagCmd.setName("tagcommit");
tagCmd.setObjectId(commits.get(0));
tagCmd.setTagger(new PersonIdent(db));
Ref tag = tagCmd.call();
tagCmd = git.tag();
tagCmd.setName("tagtree");
tagCmd.setObjectId(commits.get(0).getTree());
tagCmd.setTagger(new PersonIdent(db));
tagCmd.call();
Iterator<RevCommit> log = git.log().all().call().iterator();
assertTrue(log.hasNext());
RevCommit commit = log.next();

15
org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java

@ -241,10 +241,23 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
for (Ref ref : getRepository().getAllRefs().values()) {
if(!ref.isPeeled())
ref = getRepository().peel(ref);
ObjectId objectId = ref.getPeeledObjectId();
if (objectId == null)
objectId = ref.getObjectId();
add(objectId);
RevCommit commit = null;
try {
commit = walk.parseCommit(objectId);
} catch (MissingObjectException e) {
// ignore: the ref points to an object that does not exist;
// it should be ignored as traversal starting point.
} catch (IncorrectObjectTypeException e) {
// ignore: the ref points to an object that is not a commit
// (e.g. a tree or a blob);
// it should be ignored as traversal starting point.
}
if (commit != null)
add(commit);
}
return this;
}

Loading…
Cancel
Save