11package org .variantsync .diffdetective .datasets ;
22
33import org .eclipse .jgit .api .Git ;
4- import org .eclipse .jgit .api .errors .GitAPIException ;
54import org .eclipse .jgit .lib .ObjectId ;
65import org .eclipse .jgit .revwalk .RevCommit ;
76import org .tinylog .Logger ;
@@ -44,6 +43,11 @@ public class Repository {
4443 */
4544 private final String repositoryName ;
4645
46+ /**
47+ * A function that extracts the list of commits that are represented by this repository instance.
48+ */
49+ private CommitLister commitLister ;
50+
4751 /**
4852 * Filter determining which files and commits to consider for diffs.
4953 */
@@ -55,14 +59,15 @@ public class Repository {
5559 private PatchDiffParseOptions parseOptions ;
5660
5761 private final Lazy <Git > git = Lazy .of (this ::load );
58-
62+
5963 /**
6064 * Creates a repository.
6165 *
6266 * @param repoLocation {@link RepositoryLocationType} From which location the repository is read from
6367 * @param localPath The local path where the repository can be found or should be cloned to.
6468 * @param remote The remote url of the repository. May be <code>null</code> if local.
6569 * @param repositoryName Name of the cloned repository (<code>null</code> if local)
70+ * @param commitLister extracts the commits from {@link #getGitRepo()} that should be represented.
6671 * @param parseOptions Omit some debug data to save RAM.
6772 * @param diffFilter Filter determining which files and commits to consider for diffs.
6873 */
@@ -71,27 +76,38 @@ public Repository(
7176 final Path localPath ,
7277 final URI remote ,
7378 final String repositoryName ,
79+ final CommitLister commitLister ,
7480 final PatchDiffParseOptions parseOptions ,
7581 final DiffFilter diffFilter ) {
7682 this .repoLocation = repoLocation ;
7783 this .localPath = localPath ;
7884 this .remote = remote ;
7985 this .repositoryName = repositoryName ;
86+ this .commitLister = commitLister ;
8087 this .parseOptions = parseOptions ;
8188 this .diffFilter = diffFilter ;
8289 }
8390
8491 /**
8592 * Creates repository of the given source and with all other settings set to default values.
8693 * @see Repository
94+ * <p>
95+ * Defaults to {@link CommitLister#TraverseHEAD}, {@link PatchDiffParseOptions#Default} and {@link DiffFilter#ALLOW_ALL}.
8796 */
8897 public Repository (
8998 final RepositoryLocationType repoLocation ,
9099 final Path localPath ,
91100 final URI remote ,
92101 final String repositoryName ) {
93- this (repoLocation , localPath , remote , repositoryName ,
94- PatchDiffParseOptions .Default , DiffFilter .ALLOW_ALL );
102+ this (
103+ repoLocation ,
104+ localPath ,
105+ remote ,
106+ repositoryName ,
107+ CommitLister .TraverseHEAD ,
108+ PatchDiffParseOptions .Default ,
109+ DiffFilter .ALLOW_ALL
110+ );
95111 }
96112
97113 /**
@@ -251,12 +267,7 @@ public RevCommit getCommit(String commitHash) throws IOException {
251267 * Returns all commits in the repository's history.
252268 */
253269 public Iterator <RevCommit > getCommits () {
254- try {
255- return getGitRepo ().log ().call ().iterator ();
256- } catch (GitAPIException e ) {
257- Logger .warn ("Could not get log for git repository {}" , getRepositoryName ());
258- throw new RuntimeException (e );
259- }
270+ return commitLister .listCommits (this );
260271 }
261272
262273 /**
0 commit comments