commit e06005c30f1d0d15f3b6596ed8c7bc0d4df4469b from: Stefan Sperling via: Thomas Adam date: Sat Mar 30 17:21:23 2024 UTC remove GOT_ERR_ITER_BUSY from got_commit_graph_iter_start() Just clear any left-over iteration state and begin a fresh iteration instead of returning GOT_ERR_ITER_BUSY if the caller did not loop through the entire graph. This change currently doesn't matter much since all existing callers only do a single pass over the graph. But it frees up an error code and makes this API more flexible. commit - 90b9fd92079e3976d99c73d2e2164b8e114ea963 commit + e06005c30f1d0d15f3b6596ed8c7bc0d4df4469b blob - 60384f611195c8632002438feac20a8570779eae blob + 591ee66b8e3d659624ea402adc5cac155bfd6e21 --- include/got_error.h +++ include/got_error.h @@ -59,7 +59,7 @@ #define GOT_ERR_PACK_OFFSET 42 #define GOT_ERR_OBJ_EXISTS 43 #define GOT_ERR_BAD_OBJ_ID 44 -#define GOT_ERR_ITER_BUSY 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 */ blob - a8261cdc230343efc102643019fd4922ebc775f5 blob + c493c1ab56b08e42a322d21b6cdc3c76f5d72a50 --- lib/commit_graph.c +++ lib/commit_graph.c @@ -558,15 +558,29 @@ got_commit_graph_close(struct got_commit_graph *graph) free(graph); } +static const struct got_error * +remove_branch_tip(struct got_object_id *commit_id, void *data, void *arg) +{ + struct got_object_idset *open_branches = arg; + + return got_object_idset_remove(NULL, open_branches, commit_id); +} + const struct got_error * got_commit_graph_iter_start(struct got_commit_graph *graph, struct got_object_id *id, struct got_repository *repo, got_cancel_cb cancel_cb, void *cancel_arg) { const struct got_error *err = NULL; + struct got_commit_graph_node *node; - if (!TAILQ_EMPTY(&graph->iter_list)) - return got_error(GOT_ERR_ITER_BUSY); + /* Clear left-over state from previous iteration attempts. */ + while ((node = TAILQ_FIRST(&graph->iter_list))) + TAILQ_REMOVE(&graph->iter_list, node, entry); + err = got_object_idset_for_each(graph->open_branches, + remove_branch_tip, graph->open_branches); + if (err) + return err; err = got_object_idset_add(graph->open_branches, id, NULL); if (err) blob - 459648b8fe518ba753898cc1da588ca57ea26e19 blob + 8c70089b5c77c029b00e5f88e34d44bb64f6e5e2 --- lib/error.c +++ lib/error.c @@ -91,7 +91,6 @@ static const struct got_error got_errors[] = { { 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_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" },