import org.eclipse.jgit.revwalk.RevSort;\r
import org.eclipse.jgit.revwalk.RevTree;\r
import org.eclipse.jgit.revwalk.RevWalk;\r
+import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter;\r
import org.eclipse.jgit.revwalk.filter.RevFilter;\r
import org.eclipse.jgit.storage.file.FileRepository;\r
import org.eclipse.jgit.transport.CredentialsProvider;\r
return "missing";\r
}\r
\r
+ /**\r
+ * Returns a list of commits since the minimum date starting from the\r
+ * specified object id.\r
+ * \r
+ * @param repository\r
+ * @param objectId\r
+ * if unspecified, HEAD is assumed.\r
+ * @param minimumDate\r
+ * @return list of commits\r
+ */\r
+ public static List<RevCommit> getRevLog(Repository repository, String objectId, Date minimumDate) {\r
+ List<RevCommit> list = new ArrayList<RevCommit>();\r
+ if (!hasCommits(repository)) {\r
+ return list;\r
+ }\r
+ try {\r
+ // resolve branch\r
+ ObjectId branchObject;\r
+ if (StringUtils.isEmpty(objectId)) {\r
+ branchObject = getDefaultBranch(repository);\r
+ } else {\r
+ branchObject = repository.resolve(objectId);\r
+ }\r
+\r
+ RevWalk rw = new RevWalk(repository);\r
+ rw.markStart(rw.parseCommit(branchObject));\r
+ rw.setRevFilter(CommitTimeRevFilter.after(minimumDate));\r
+ Iterable<RevCommit> revlog = rw;\r
+ for (RevCommit rev : revlog) {\r
+ list.add(rev);\r
+ }\r
+ rw.dispose();\r
+ } catch (Throwable t) {\r
+ error(t, repository, "{0} failed to get {1} revlog for minimum date {2}", objectId,\r
+ minimumDate);\r
+ }\r
+ return list;\r
+ }\r
+\r
/**\r
* Returns a list of commits starting from HEAD and working backwards.\r
* \r
\r
import java.io.File;\r
import java.io.FileOutputStream;\r
+import java.text.SimpleDateFormat;\r
import java.util.Arrays;\r
import java.util.Date;\r
import java.util.List;\r
public void testRevlog() throws Exception {\r
assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);\r
List<RevCommit> commits = JGitUtils.getRevLog(null, 10);\r
- assertTrue(commits.size() == 0);\r
+ assertEquals(0, commits.size());\r
\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
// get most recent 10 commits\r
commits = JGitUtils.getRevLog(repository, 10);\r
- assertTrue(commits.size() == 10);\r
+ assertEquals(10, commits.size());\r
\r
// test paging and offset by getting the 10th most recent commit\r
RevCommit lastCommit = JGitUtils.getRevLog(repository, null, 9, 1).get(0);\r
- assertTrue(commits.get(9).equals(lastCommit));\r
+ assertEquals(lastCommit, commits.get(9));\r
\r
// grab the two most recent commits to java.java\r
commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);\r
- assertTrue(commits.size() == 2);\r
+ assertEquals(2, commits.size());\r
+ \r
+ // grab the commits since 2008-07-15\r
+ commits = JGitUtils.getRevLog(repository, null, new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));\r
+ assertEquals(12, commits.size());\r
repository.close();\r
}\r
\r