simplify got_commit_graph_open()
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
diff --git a/got/got.c b/got/got.c
index 9f9906e..1600fc8 100644
--- a/got/got.c
+++ b/got/got.c
@@ -916,7 +916,7 @@ check_same_branch(struct got_object_id *commit_id,
goto done;
}
- err = got_commit_graph_open(&graph, head_commit_id, "/", 1, repo);
+ err = got_commit_graph_open(&graph, "/", 1);
if (err)
goto done;
@@ -1767,8 +1767,7 @@ print_commits(struct got_object_id *root_id, struct got_repository *repo,
regcomp(®ex, search_pattern, REG_EXTENDED | REG_NOSUB | REG_NEWLINE))
return got_error_msg(GOT_ERR_REGEX, search_pattern);
- err = got_commit_graph_open(&graph, root_id, path,
- first_parent_traversal, repo);
+ err = got_commit_graph_open(&graph, path, first_parent_traversal);
if (err)
return err;
err = got_commit_graph_iter_start(graph, root_id, repo,
@@ -5353,7 +5352,7 @@ collect_commits(struct got_object_id_queue *commits,
struct got_object_qid *qid;
struct got_object_id *commit_id = initial_commit_id;
- err = got_commit_graph_open(&graph, initial_commit_id, "/", 1, repo);
+ err = got_commit_graph_open(&graph, "/", 1);
if (err)
return err;
diff --git a/include/got_commit_graph.h b/include/got_commit_graph.h
index e21a530..2ad08d3 100644
--- a/include/got_commit_graph.h
+++ b/include/got_commit_graph.h
@@ -17,8 +17,7 @@
struct got_commit_graph;
const struct got_error *got_commit_graph_open(struct got_commit_graph **,
- struct got_object_id *commit_id, const char *, int,
- struct got_repository *repo);
+ const char *, int);
void got_commit_graph_close(struct got_commit_graph *);
const struct got_error *got_commit_graph_iter_start(
diff --git a/include/got_error.h b/include/got_error.h
index b8f22cf..e1ce795 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -58,7 +58,7 @@
#define GOT_ERR_PACK_OFFSET 42
#define GOT_ERR_OBJ_EXISTS 43
#define GOT_ERR_BAD_OBJ_ID 44
-/* 45 is currently unused */
+#define GOT_ERR_ITER_BUSY 45
#define GOT_ERR_ITER_COMPLETED 46
#define GOT_ERR_RANGE 47
#define GOT_ERR_EXPECTED 48 /* for use in regress tests only */
@@ -176,7 +176,7 @@ static const struct got_error {
{ GOT_ERR_PACK_OFFSET, "bad offset in pack file" },
{ GOT_ERR_OBJ_EXISTS, "object already exists" },
{ GOT_ERR_BAD_OBJ_ID, "bad object id" },
- /* 45 is currently unused */
+ { GOT_ERR_ITER_BUSY, "iteration already in progress" },
{ GOT_ERR_ITER_COMPLETED,"iteration completed" },
{ GOT_ERR_RANGE, "value out of range" },
{ GOT_ERR_EXPECTED, "expected an error but have no error" },
diff --git a/lib/blame.c b/lib/blame.c
index 00b8798..004a114 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -237,7 +237,7 @@ blame_open(struct got_blame **blamep, const char *path,
goto done;
}
- err = got_commit_graph_open(&graph, start_commit_id, path, 1, repo);
+ err = got_commit_graph_open(&graph, path, 1);
if (err)
return err;
err = got_commit_graph_iter_start(graph, start_commit_id, repo,
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 3547dae..388504a 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -379,52 +379,15 @@ add_node(struct got_commit_graph_node **new_node, int *changed,
const struct got_error *
got_commit_graph_open(struct got_commit_graph **graph,
- struct got_object_id *commit_id, const char *path,
- int first_parent_traversal, struct got_repository *repo)
+ const char *path, int first_parent_traversal)
{
- const struct got_error *err = NULL;
- struct got_commit_object *commit;
- int changed, branch_done;
- struct got_commit_graph_node *node;
-
- *graph = NULL;
-
- err = got_object_open_as_commit(&commit, repo, commit_id);
- if (err)
- return err;
-
- /* The path must exist in our initial commit. */
- if (!got_path_is_root_dir(path)) {
- struct got_object_id *obj_id;
- err = got_object_id_by_path(&obj_id, repo, commit_id, path);
- if (err)
- return err;
- free(obj_id);
- }
-
*graph = alloc_graph(path);
- if (*graph == NULL) {
- err = got_error_from_errno("alloc_graph");
- got_object_commit_close(commit);
- return err;
- }
+ if (*graph == NULL)
+ return got_error_from_errno("alloc_graph");
if (first_parent_traversal)
(*graph)->flags |= GOT_COMMIT_GRAPH_FIRST_PARENT_TRAVERSAL;
- err = add_node(&node, &changed, &branch_done, *graph,
- commit_id, commit, NULL, repo);
- if (err == NULL) {
- err = advance_branch(*graph, node, commit_id,
- commit, repo);
- }
- got_object_commit_close(commit);
- if (err) {
- got_commit_graph_close(*graph);
- *graph = NULL;
- return err;
- }
-
return NULL;
}
@@ -562,24 +525,24 @@ got_commit_graph_iter_start(struct got_commit_graph *graph,
const struct got_error *err = NULL;
struct got_commit_graph_node *start_node;
struct got_commit_object *commit;
- int changed;
+ int changed, branch_done;
- start_node = got_object_idset_get(graph->node_ids, id);
- while (start_node == NULL) {
- int ncommits;
- err = fetch_commits_from_open_branches(&ncommits, NULL, graph,
- repo, cancel_cb, cancel_arg);
- if (err)
- return err;
- if (ncommits == 0)
- return got_error_no_obj(id);
- start_node = got_object_idset_get(graph->node_ids, id);
- }
+ if (!TAILQ_EMPTY(&graph->iter_list))
+ return got_error(GOT_ERR_ITER_BUSY);
- err = got_object_open_as_commit(&commit, repo, &start_node->id);
+ err = got_object_open_as_commit(&commit, repo, id);
if (err)
return err;
+ err = add_node(&start_node, &changed, &branch_done, graph, id,
+ commit, NULL, repo);
+ if (err)
+ goto done;
+
+ err = advance_branch(graph, start_node, id, commit, repo);
+ if (err)
+ goto done;
+
err = detect_changed_path(&changed, commit, &start_node->id,
graph->path, repo);
if (err) {
@@ -601,10 +564,11 @@ got_commit_graph_iter_start(struct got_commit_graph *graph,
}
start_node = got_object_idset_get(graph->node_ids, changed_id);
}
+done:
got_object_commit_close(commit);
-
- graph->iter_node = start_node;
- return NULL;
+ if (err == NULL)
+ graph->iter_node = start_node;
+ return err;
}
const struct got_error *
@@ -661,11 +625,11 @@ got_commit_graph_find_youngest_common_ancestor(struct got_object_id **yca_id,
if (commit_ids == NULL)
return got_error_from_errno("got_object_idset_alloc");
- err = got_commit_graph_open(&graph, commit_id, "/", 1, repo);
+ err = got_commit_graph_open(&graph, "/", 1);
if (err)
goto done;
- err = got_commit_graph_open(&graph2, commit_id2, "/", 1, repo);
+ err = got_commit_graph_open(&graph2, "/", 1);
if (err)
goto done;
diff --git a/tog/tog.c b/tog/tog.c
index 837e0f9..c74a02a 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -2153,8 +2153,7 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
err = got_repo_open(&thread_repo, got_repo_get_path(repo), NULL);
if (err)
goto done;
- err = got_commit_graph_open(&thread_graph, start_id, s->in_repo_path,
- 0, thread_repo);
+ err = got_commit_graph_open(&thread_graph, s->in_repo_path, 0);
if (err)
goto done;