Commit Diff


commit - 6a4c18905deaa2e3c0663558d5016e475e5f64c6
commit + 1142eae973ea98f41f38c35b80b1ed921aebf56d
blob - c97734f128a3241b6703a2527f97435adb065fee
blob + 66ff21914d95378799637e273fbee6d186886c7b
--- include/got_commit_graph.h
+++ include/got_commit_graph.h
@@ -23,6 +23,8 @@ void got_commit_graph_close(struct got_commit_graph *)
 const struct got_error *
 got_commit_graph_fetch_commits(int *, struct got_commit_graph *, int,
     struct got_repository *);
+const struct got_error *got_commit_graph_fetch_commits_up_to(int *,
+    struct got_commit_graph *, struct got_object_id *, struct got_repository *);
 const struct got_error *got_commit_graph_iter_start(
     struct got_commit_graph *, struct got_object_id *);
 const struct got_error *got_commit_graph_iter_next(struct got_object_id **,
blob - /dev/null
blob + b410fea9051f88ef1434c51d24c4ab294354b2c3 (mode 644)
Binary files /dev/null and include/.got_commit_graph.h.swp differ
blob - 50d6b3525980bc150e9543c63e08fcc549b7cd03
blob + cebac9ef1e0aa411ce1ae56ca5f9b2c8689bb56e
--- lib/commit_graph.c
+++ lib/commit_graph.c
@@ -312,9 +312,10 @@ gather_branches(struct got_object_id *id, void *data, 
 	a->nbranches++;
 }
 
-const struct got_error *
-fetch_commits_from_open_branches(int *ncommits,
-    struct got_commit_graph *graph, struct got_repository *repo)
+static const struct got_error *
+fetch_commits_from_open_branches(int *ncommits, int *wanted_id_added,
+    struct got_commit_graph *graph, struct got_repository *repo,
+    struct got_object_id *wanted_id)
 {
 	const struct got_error *err;
 	struct got_commit_graph_branch *branches;
@@ -322,6 +323,8 @@ fetch_commits_from_open_branches(int *ncommits,
 	int i;
 
 	*ncommits = 0;
+	if (wanted_id_added)
+		*wanted_id_added = 0;
 
 	arg.nbranches = got_object_idset_num_elements(graph->open_branches);
 	if (arg.nbranches == 0)
@@ -360,6 +363,8 @@ fetch_commits_from_open_branches(int *ncommits,
 		}
 		if (new_node)
 			(*ncommits)++;
+		if (wanted_id && got_object_id_cmp(commit_id, wanted_id) == 0)
+			*wanted_id_added = 1;
 	}
 
 	free(branches);
@@ -371,23 +376,45 @@ got_commit_graph_fetch_commits(int *nfetched, struct g
     int limit, struct got_repository *repo)
 {
 	const struct got_error *err;
-	int total = 0, ncommits;
+	int ncommits;
 
 	*nfetched = 0;
 
-	while (total < limit) {
-		err = fetch_commits_from_open_branches(&ncommits, graph, repo);
+	while (*nfetched < limit) {
+		err = fetch_commits_from_open_branches(&ncommits, NULL,
+		    graph, repo, NULL);
 		if (err)
 			return err;
 		if (ncommits == 0)
 			break;
-		total += ncommits;
+		*nfetched += ncommits;
 	}
 
-	*nfetched = total;
 	return NULL;
 }
 
+const struct got_error *
+got_commit_graph_fetch_commits_up_to(int *nfetched,
+    struct got_commit_graph *graph, struct got_object_id *wanted_id,
+    struct got_repository *repo)
+{
+	const struct got_error *err;
+	int ncommits, wanted_id_added = 0;
+
+	*nfetched = 0;
+	while (!wanted_id_added) {
+		err = fetch_commits_from_open_branches(&ncommits,
+		    &wanted_id_added, graph, repo, wanted_id);
+		if (err)
+			return err;
+		if (ncommits == 0)
+			return NULL;
+		*nfetched += ncommits;
+	}
+
+	return NULL;
+}
+
 static void
 free_graph_node(struct got_object_id *id, void *data, void *arg)
 {
blob - /dev/null
blob + d7431b42a15a9504a37ffed1d09bf4fc3c984377 (mode 644)
Binary files /dev/null and lib/.commit_graph.c.swp differ