commit 3d5092374a96864fbc4c3d2d2e752f588c63ac39 from: Stefan Sperling date: Sat Jan 04 18:25:28 2020 UTC simplify got_commit_graph_open() commit - 11d7587ef5019e3735f6ec20c43f580eb5c8a94e commit + 3d5092374a96864fbc4c3d2d2e752f588c63ac39 blob - 9f9906e1f49348ef40c8d4cc7841bc6fbae5a3c7 blob + 1600fc869822946bf76150e16a141479b9920830 --- got/got.c +++ 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 go 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; blob - e21a5301c9f6ed92c32d078f03478d6f8a79423f blob + 2ad08d326790ee2c3002810b856dc2fce9064196 --- include/got_commit_graph.h +++ 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( blob - b8f22cf154bb9629cdb7274e611319bef1a7031d blob + e1ce795a74206c1e1b511b5a6e38da648a543624 --- include/got_error.h +++ 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" }, blob - 00b87984bbe853e9f667f29f39ff58191c20ca30 blob + 004a114385e43ca9db16c42ae42deef3c0382b60 --- lib/blame.c +++ 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, blob - 3547daee92b9b6e429ebe95b6bfa67382fe47e83 blob + 388504ad5d406257f8345279e079a74e730d8967 --- lib/commit_graph.c +++ lib/commit_graph.c @@ -379,52 +379,15 @@ add_node(struct got_commit_graph_node **new_node, int 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 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); - } - + const char *path, int first_parent_traversal) +{ *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 *g 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 *g } 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 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; blob - 837e0f916a1ff344f792025b8159bb1660fe019e blob + c74a02a1146f0439a627fbf598f75fc0109c1848 --- tog/tog.c +++ tog/tog.c @@ -2153,8 +2153,7 @@ open_log_view(struct tog_view *view, struct got_object 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;