summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2021-01-06 06:26:09 -0800
committerlhchavez <lhchavez@lhchavez.com>2021-07-27 08:14:08 -0700
commitce5400cdc7cc52ace295a9fbd3cd7a6e7c63be34 (patch)
treefc27f950a3f6547aadcd638a7d3ea638b0aa85b8 /include/git2
parent08c79128be38b6704cfdf01bca037f3fbaabf847 (diff)
downloadlibgit2-ce5400cdc7cc52ace295a9fbd3cd7a6e7c63be34.tar.gz
graph: Create `git_graph_reachable_from_any()`
This change introduces a new API function `git_graph_reachable_from_any()`, that answers the question whether a commit is reachable from any of the provided commits through following parent edges. This function can take advantage of optimizations provided by the existence of a `commit-graph` file, since it makes it faster to know whether, given two commits X and Y, X cannot possibly be an reachable from Y. Part of: #5757
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/graph.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/include/git2/graph.h b/include/git2/graph.h
index 213ae9777..cd4897fef 100644
--- a/include/git2/graph.h
+++ b/include/git2/graph.h
@@ -43,8 +43,9 @@ GIT_EXTERN(int) git_graph_ahead_behind(size_t *ahead, size_t *behind, git_reposi
* Note that a commit is not considered a descendant of itself, in contrast
* to `git merge-base --is-ancestor`.
*
- * @param commit a previously loaded commit.
- * @param ancestor a potential ancestor commit.
+ * @param repo the repository where the commits exist
+ * @param commit a previously loaded commit
+ * @param ancestor a potential ancestor commit
* @return 1 if the given commit is a descendant of the potential ancestor,
* 0 if not, error code otherwise.
*/
@@ -53,6 +54,23 @@ GIT_EXTERN(int) git_graph_descendant_of(
const git_oid *commit,
const git_oid *ancestor);
+/**
+ * Determine if a commit is reachable from any of a list of commits by
+ * following parent edges.
+ *
+ * @param repo the repository where the commits exist
+ * @param commit a previously loaded commit
+ * @param length the number of commits in the provided `descendant_array`
+ * @param descendant_array oids of the commits
+ * @return 1 if the given commit is an ancestor of any of the given potential
+ * descendants, 0 if not, error code otherwise.
+ */
+GIT_EXTERN(int) git_graph_reachable_from_any(
+ git_repository *repo,
+ const git_oid *commit,
+ size_t length,
+ const git_oid descendant_array[]);
+
/** @} */
GIT_END_DECL
#endif