introduce got_commit_graph_fetch_commits_up_to()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
diff --git a/include/.got_commit_graph.h.swp b/include/.got_commit_graph.h.swp
new file mode 100644
index 0000000..b410fea
Binary files /dev/null and b/include/.got_commit_graph.h.swp differ
diff --git a/include/got_commit_graph.h b/include/got_commit_graph.h
index c97734f..66ff219 100644
--- a/include/got_commit_graph.h
+++ b/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 **,
diff --git a/lib/.commit_graph.c.swp b/lib/.commit_graph.c.swp
new file mode 100644
index 0000000..d7431b4
Binary files /dev/null and b/lib/.commit_graph.c.swp differ
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 50d6b35..cebac9e 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -312,9 +312,10 @@ gather_branches(struct got_object_id *id, void *data, void *arg)
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,20 +376,42 @@ got_commit_graph_fetch_commits(int *nfetched, struct got_commit_graph *graph,
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;
+ }
+
+ 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;
}
- *nfetched = total;
return NULL;
}