remove GOT_ERR_ITER_NEED_MORE; the commit graph now fetches internally 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 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
diff --git a/got/got.c b/got/got.c
index e658e62..9f9906e 100644
--- a/got/got.c
+++ b/got/got.c
@@ -927,17 +927,12 @@ check_same_branch(struct got_object_id *commit_id,
for (;;) {
struct got_object_id *id;
- err = got_commit_graph_iter_next(&id, graph);
+ err = got_commit_graph_iter_next(&id, graph, repo,
+ check_cancelled, NULL);
if (err) {
- if (err->code == GOT_ERR_ITER_COMPLETED) {
+ if (err->code == GOT_ERR_ITER_COMPLETED)
err = NULL;
- break;
- } else if (err->code != GOT_ERR_ITER_NEED_MORE)
- break;
- err = got_commit_graph_fetch_commits(graph, 1,
- repo, check_cancelled, NULL);
- if (err)
- break;
+ break;
}
if (id) {
@@ -1787,20 +1782,12 @@ print_commits(struct got_object_id *root_id, struct got_repository *repo,
if (sigint_received || sigpipe_received)
break;
- err = got_commit_graph_iter_next(&id, graph);
+ err = got_commit_graph_iter_next(&id, graph, repo,
+ check_cancelled, NULL);
if (err) {
- if (err->code == GOT_ERR_ITER_COMPLETED) {
+ if (err->code == GOT_ERR_ITER_COMPLETED)
err = NULL;
- break;
- }
- if (err->code != GOT_ERR_ITER_NEED_MORE)
- break;
- err = got_commit_graph_fetch_commits(graph, 1, repo,
- check_cancelled, NULL);
- if (err)
- break;
- else
- continue;
+ break;
}
if (id == NULL)
break;
@@ -5375,20 +5362,16 @@ collect_commits(struct got_object_id_queue *commits,
if (err)
goto done;
while (got_object_id_cmp(commit_id, iter_stop_id) != 0) {
- err = got_commit_graph_iter_next(&parent_id, graph);
+ err = got_commit_graph_iter_next(&parent_id, graph, repo,
+ check_cancelled, NULL);
if (err) {
if (err->code == GOT_ERR_ITER_COMPLETED) {
err = got_error_msg(GOT_ERR_ANCESTRY,
"ran out of commits to rebase before "
"youngest common ancestor commit has "
"been reached?!?");
- goto done;
- } else if (err->code != GOT_ERR_ITER_NEED_MORE)
- goto done;
- err = got_commit_graph_fetch_commits(graph, 1, repo,
- check_cancelled, NULL);
- if (err)
- goto done;
+ }
+ goto done;
} else {
err = check_path_prefix(parent_id, commit_id,
path_prefix, path_prefix_errcode, repo);
diff --git a/include/got_commit_graph.h b/include/got_commit_graph.h
index 488763b..e21a530 100644
--- a/include/got_commit_graph.h
+++ b/include/got_commit_graph.h
@@ -21,14 +21,11 @@ const struct got_error *got_commit_graph_open(struct got_commit_graph **,
struct got_repository *repo);
void got_commit_graph_close(struct got_commit_graph *);
-const struct got_error *got_commit_graph_fetch_commits(
- struct got_commit_graph *, int, struct got_repository *,
- got_cancel_cb, void *);
const struct got_error *got_commit_graph_iter_start(
struct got_commit_graph *, struct got_object_id *, struct got_repository *,
got_cancel_cb, void *);
const struct got_error *got_commit_graph_iter_next(struct got_object_id **,
- struct got_commit_graph *);
+ struct got_commit_graph *, struct got_repository *, got_cancel_cb, void *);
const struct got_error *got_commit_graph_intersect(struct got_object_id **,
struct got_commit_graph *, struct got_commit_graph *,
struct got_repository *);
diff --git a/include/got_error.h b/include/got_error.h
index 577bc08..b8f22cf 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
-#define GOT_ERR_ITER_NEED_MORE 45
+/* 45 is currently unused */
#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" },
- { GOT_ERR_ITER_NEED_MORE,"more items needed to continue iteration" },
+ /* 45 is currently unused */
{ 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 a21b3cf..00b8798 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -246,19 +246,12 @@ blame_open(struct got_blame **blamep, const char *path,
goto done;
id = start_commit_id;
for (;;) {
- err = got_commit_graph_iter_next(&pid, graph);
+ err = got_commit_graph_iter_next(&pid, graph, repo,
+ cancel_cb, cancel_arg);
if (err) {
- if (err->code == GOT_ERR_ITER_COMPLETED) {
+ if (err->code == GOT_ERR_ITER_COMPLETED)
err = NULL;
- break;
- }
- if (err->code != GOT_ERR_ITER_NEED_MORE)
- break;
- err = got_commit_graph_fetch_commits(graph, 1, repo,
- cancel_cb, cancel_arg);
- if (err)
- break;
- continue;
+ break;
}
if (pid) {
err = blame_commit(blame, pid, id, path, repo, cb, arg);
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 899ed14..c4649f5 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -537,33 +537,6 @@ done:
return err;
}
-const struct got_error *
-got_commit_graph_fetch_commits(struct got_commit_graph *graph, int limit,
- struct got_repository *repo, got_cancel_cb cancel_cb, void *cancel_arg)
-{
- const struct got_error *err;
- int nfetched = 0, ncommits;
- struct got_object_id *changed_id = NULL;
-
- while (nfetched < limit) {
- if (cancel_cb) {
- err = (*cancel_cb)(cancel_arg);
- if (err)
- return err;
- }
- err = fetch_commits_from_open_branches(&ncommits,
- &changed_id, graph, repo, cancel_cb, cancel_arg);
- if (err)
- return err;
- if (ncommits == 0)
- break;
- if (changed_id)
- nfetched += ncommits;
- }
-
- return NULL;
-}
-
static const struct got_error *
free_node_iter(struct got_object_id *id, void *data, void *arg)
{
@@ -638,8 +611,11 @@ got_commit_graph_iter_start(struct got_commit_graph *graph,
const struct got_error *
got_commit_graph_iter_next(struct got_object_id **id,
- struct got_commit_graph *graph)
+ struct got_commit_graph *graph, struct got_repository *repo,
+ got_cancel_cb cancel_cb, void *cancel_arg)
{
+ const struct got_error *err = NULL;
+
*id = NULL;
if (graph->iter_node == NULL) {
@@ -656,8 +632,15 @@ got_commit_graph_iter_next(struct got_object_id **id,
return NULL;
}
- if (TAILQ_NEXT(graph->iter_node, entry) == NULL)
- return got_error(GOT_ERR_ITER_NEED_MORE);
+ while (TAILQ_NEXT(graph->iter_node, entry) == NULL &&
+ got_object_idset_num_elements(graph->open_branches) > 0) {
+ int ncommits;
+ struct got_object_id *changed_id;
+ err = fetch_commits_from_open_branches(&ncommits,
+ &changed_id, graph, repo, cancel_cb, cancel_arg);
+ if (err)
+ return err;
+ }
*id = &graph->iter_node->id;
graph->iter_node = TAILQ_NEXT(graph->iter_node, entry);
@@ -699,7 +682,7 @@ got_commit_graph_find_youngest_common_ancestor(struct got_object_id **yca_id,
goto done;
for (;;) {
- struct got_object_id *id, *id2;
+ struct got_object_id *id = NULL, *id2 = NULL;
if (cancel_cb) {
err = (*cancel_cb)(cancel_arg);
@@ -708,30 +691,24 @@ got_commit_graph_find_youngest_common_ancestor(struct got_object_id **yca_id,
}
if (!completed) {
- err = got_commit_graph_iter_next(&id, graph);
+ err = got_commit_graph_iter_next(&id, graph, repo,
+ cancel_cb, cancel_arg);
if (err) {
- if (err->code == GOT_ERR_ITER_COMPLETED)
- completed = 1;
- else if (err->code != GOT_ERR_ITER_NEED_MORE)
- break;
- err = got_commit_graph_fetch_commits(graph, 1,
- repo, cancel_cb, cancel_arg);
- if (err)
+ if (err->code != GOT_ERR_ITER_COMPLETED)
break;
+ err = NULL;
+ completed = 1;
}
}
if (!completed2) {
- err = got_commit_graph_iter_next(&id2, graph2);
+ err = got_commit_graph_iter_next(&id2, graph2, repo,
+ cancel_cb, cancel_arg);
if (err) {
- if (err->code == GOT_ERR_ITER_COMPLETED)
- completed2 = 1;
- else if (err->code != GOT_ERR_ITER_NEED_MORE)
- break;
- err = got_commit_graph_fetch_commits(graph2, 1,
- repo, cancel_cb, cancel_arg);
- if (err)
+ if (err->code != GOT_ERR_ITER_COMPLETED)
break;
+ err = NULL;
+ completed2 = 1;
}
}
diff --git a/tog/tog.c b/tog/tog.c
index db28ea8..837e0f9 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1397,18 +1397,8 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
struct commit_queue_entry *entry;
int errcode;
- err = got_commit_graph_iter_next(&id, graph);
- if (err) {
- if (err->code != GOT_ERR_ITER_NEED_MORE)
- break;
- err = got_commit_graph_fetch_commits(graph,
- minqueue, repo, NULL, NULL);
- if (err)
- return err;
- continue;
- }
-
- if (id == NULL)
+ err = got_commit_graph_iter_next(&id, graph, repo, NULL, NULL);
+ if (err || id == NULL)
break;
err = got_object_open_as_commit(&commit, repo, id);