@@ -84,6 +84,31 @@ static int countCommits(Git git, String tag, String tagPrefix, Iterable<String>
8484 return countCommits (git , GitUtils .getCommitToTagMap (git ), ObjectId .fromString (commitHash ), tagPrefix , includePaths , excludePaths );
8585 }
8686
87+ /**
88+ * Counts commits, for the given Git repository, from the given tag to {@linkplain Constants#HEAD HEAD}. If the
89+ * given tag cannot be found, this method will return {@code -1}.
90+ * <p>
91+ * See {@link #countCommits(Git, Map, ObjectId, String, Iterable, Iterable)} for more information.
92+ *
93+ * @param git The git repository to count commits in
94+ * @param tag The tag name to start counting from
95+ * @param to The object ID (typically a commit or tag reference) to stop counting at, typically HEAD
96+ * @param includePaths The paths to include in the count
97+ * @param excludePaths The paths to exclude from the count
98+ * @return The commit count
99+ * @throws GitAPIException If an error occurs when running the log command (see
100+ * {@link org.eclipse.jgit.api.LogCommand#call() LogCommand.call()}
101+ * @throws IOException If an I/O error occurs when reading the Git repository
102+ * @see #countCommits(Git, Map, ObjectId, String, Iterable, Iterable)
103+ */
104+ static int countCommits (Git git , String tag , ObjectId to , String tagPrefix , Iterable <String > includePaths , Iterable <String > excludePaths ) throws GitAPIException , IOException {
105+ var tags = GitUtils .getTagToCommitMap (git );
106+ var commitHash = tags .get (tag );
107+ if (commitHash == null ) return -1 ;
108+
109+ return countCommits (git , GitUtils .getCommitToTagMap (git ), ObjectId .fromString (commitHash ), to , tagPrefix , includePaths , excludePaths );
110+ }
111+
87112 /**
88113 * Counts commits, for the given Git repository, from the given object ID to {@linkplain Constants#HEAD HEAD}.
89114 * Additional paths can be given to include or exclude from the count.
@@ -108,6 +133,31 @@ static int countCommits(Git git, Map<String, String> commitsToTags, ObjectId fro
108133 return Util .count (getCommitLogFromTo (git , commitsToTags , from , getHead (git ), tagPrefix , includePaths , excludePaths ));
109134 }
110135
136+ /**
137+ * Counts commits, for the given Git repository, from the given object ID to the other given object ID..
138+ * Additional paths can be given to include or exclude from the count.
139+ * <p>
140+ * An important detail to note is that the commit given is <strong>not included</strong> in the count. This means
141+ * that if the given commit is also the HEAD, the returned count will be {@code 0}. Additionally, if there are no
142+ * commits barring the paths given from the object ID, the count will be {@code -1}. Please handle this
143+ * accordingly.
144+ *
145+ * @param git The git repository to count commits in
146+ * @param from The object ID (typically a commit or tag reference) to start counting from
147+ * @param to The object ID (typically a commit or tag reference) to stop counting at, typically HEAD
148+ * @param includePaths The paths to include in the count
149+ * @param excludePaths The paths to exclude from the count
150+ * @return The commit count
151+ * @throws GitAPIException If an error occurs when running the log command (see
152+ * {@link org.eclipse.jgit.api.LogCommand#call() LogCommand.call()}
153+ * @throws IOException If an I/O error occurs when reading the Git repository
154+ * @see org.eclipse.jgit.api.LogCommand LogCommand
155+ * @see <a href="https://git-scm.com/docs/git-log"><code>git-log</code></a>
156+ */
157+ static int countCommits (Git git , Map <String , String > commitsToTags , ObjectId from , ObjectId to , String tagPrefix , Iterable <String > includePaths , Iterable <String > excludePaths ) throws GitAPIException , IOException {
158+ return Util .count (getCommitLogFromTo (git , commitsToTags , from , to , tagPrefix , includePaths , excludePaths ));
159+ }
160+
111161 /**
112162 * Gets the {@linkplain Constants#HEAD HEAD} commit of the given Git repository.
113163 *
0 commit comments