aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Baars2013-03-31 10:28:47 (EDT)
committerArthur Baars2013-03-31 10:36:47 (EDT)
commit35be98fb8ffb2b21144f23efc599505fa3d60dd7 (patch)
treec2378107c859eb08bed9245b7c5aaf04e5764e6b
parent2b9c440fd1a08158b5e69d3a9e1a5bed4a17b286 (diff)
downloadjgit-35be98fb8ffb2b21144f23efc599505fa3d60dd7.zip
jgit-35be98fb8ffb2b21144f23efc599505fa3d60dd7.tar.gz
jgit-35be98fb8ffb2b21144f23efc599505fa3d60dd7.tar.bz2
LogCommand.all(): filter out refs that do not refer to commit objectsrefs/changes/69/11569/1
1. I have authored 100% of the content I'm contributing, 2. I have the rights to donate the content to Eclipse, 3. I contribute the content under the EDL Change-Id: I48b1828e0b1304f76276ec07ebac7ee9f521b194
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java15
2 files changed, 21 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
index c6402e7..34432c5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LogCommandTest.java
+++ b/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();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
index 70b3658..cad2790 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
+++ b/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;
}