remove commit graph iter_node pointer; use the iter_list head instead
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
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index a205e68..67cc1c5 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -85,10 +85,10 @@ struct got_commit_graph {
/* Path of tree entry of interest to the API user. */
char *path;
- /* The next commit to return when the API user asks for one. */
- struct got_commit_graph_node *iter_node;
-
- /* The graph iteration list contains all nodes in sorted order. */
+ /*
+ * Nodes which will be passed to the API user next, sorted by
+ * commit timestmap.
+ */
struct got_commit_graph_iter_list iter_list;
};
@@ -153,11 +153,10 @@ add_node_to_iter_list(struct got_commit_graph *graph,
if (TAILQ_EMPTY(&graph->iter_list)) {
TAILQ_INSERT_HEAD(&graph->iter_list, node, entry);
- graph->iter_node = node;
return;
}
- n = graph->iter_node;
+ n = TAILQ_FIRST(&graph->iter_list);
/* Ensure that an iteration in progress will see this new commit. */
while (n) {
next = TAILQ_NEXT(n, entry);
@@ -489,7 +488,7 @@ got_commit_graph_iter_start(struct got_commit_graph *graph,
return err;
/* Locate first commit which changed graph->path. */
- while (graph->iter_node == NULL &&
+ while (TAILQ_EMPTY(&graph->iter_list) &&
got_object_idset_num_elements(graph->open_branches) > 0) {
err = fetch_commits_from_open_branches(graph, repo,
cancel_cb, cancel_arg);
@@ -497,7 +496,7 @@ got_commit_graph_iter_start(struct got_commit_graph *graph,
return err;
}
- if (graph->iter_node == NULL) {
+ if (TAILQ_EMPTY(&graph->iter_list)) {
const char *path;
if (got_path_is_root_dir(graph->path))
return got_error_no_obj(id);
@@ -516,24 +515,17 @@ got_commit_graph_iter_next(struct got_object_id **id,
got_cancel_cb cancel_cb, void *cancel_arg)
{
const struct got_error *err = NULL;
+ struct got_commit_graph_node *node;
*id = NULL;
- if (graph->iter_node == NULL) {
+ if (TAILQ_EMPTY(&graph->iter_list)) {
/* We are done iterating, or iteration was not started. */
return got_error(GOT_ERR_ITER_COMPLETED);
}
- if (graph->iter_node ==
- TAILQ_LAST(&graph->iter_list, got_commit_graph_iter_list) &&
- got_object_idset_num_elements(graph->open_branches) == 0) {
- /* We are done iterating. */
- *id = &graph->iter_node->id;
- graph->iter_node = NULL;
- return NULL;
- }
-
- while (TAILQ_NEXT(graph->iter_node, entry) == NULL &&
+ node = TAILQ_FIRST(&graph->iter_list);
+ while (TAILQ_NEXT(node, entry) == NULL &&
got_object_idset_num_elements(graph->open_branches) > 0) {
err = fetch_commits_from_open_branches(graph, repo,
cancel_cb, cancel_arg);
@@ -541,8 +533,8 @@ got_commit_graph_iter_next(struct got_object_id **id,
return err;
}
- *id = &graph->iter_node->id;
- graph->iter_node = TAILQ_NEXT(graph->iter_node, entry);
+ *id = &node->id;
+ TAILQ_REMOVE(&graph->iter_list, node, entry);
return NULL;
}