Blame


1 372ccdbb 2018-06-10 stsp /*
2 5aa81393 2020-01-06 stsp * Copyright (c) 2018, 2019, 2020 Stefan Sperling <stsp@openbsd.org>
3 372ccdbb 2018-06-10 stsp *
4 372ccdbb 2018-06-10 stsp * Permission to use, copy, modify, and distribute this software for any
5 372ccdbb 2018-06-10 stsp * purpose with or without fee is hereby granted, provided that the above
6 372ccdbb 2018-06-10 stsp * copyright notice and this permission notice appear in all copies.
7 372ccdbb 2018-06-10 stsp *
8 372ccdbb 2018-06-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 372ccdbb 2018-06-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 372ccdbb 2018-06-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 372ccdbb 2018-06-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 372ccdbb 2018-06-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 372ccdbb 2018-06-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 372ccdbb 2018-06-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 372ccdbb 2018-06-10 stsp */
16 372ccdbb 2018-06-10 stsp
17 372ccdbb 2018-06-10 stsp #include <sys/types.h>
18 372ccdbb 2018-06-10 stsp #include <sys/stat.h>
19 372ccdbb 2018-06-10 stsp
20 56e0773d 2019-11-28 stsp #include <limits.h>
21 372ccdbb 2018-06-10 stsp #include <stdio.h>
22 372ccdbb 2018-06-10 stsp #include <stdlib.h>
23 372ccdbb 2018-06-10 stsp #include <string.h>
24 372ccdbb 2018-06-10 stsp #include <zlib.h>
25 372ccdbb 2018-06-10 stsp #include <ctype.h>
26 dd038bc6 2021-09-21 thomas.ad
27 dd038bc6 2021-09-21 thomas.ad #include "got_compat.h"
28 372ccdbb 2018-06-10 stsp
29 372ccdbb 2018-06-10 stsp #include "got_error.h"
30 372ccdbb 2018-06-10 stsp #include "got_object.h"
31 6fb7cd11 2019-08-22 stsp #include "got_cancel.h"
32 372ccdbb 2018-06-10 stsp #include "got_commit_graph.h"
33 324d37e7 2019-05-11 stsp #include "got_path.h"
34 372ccdbb 2018-06-10 stsp
35 372ccdbb 2018-06-10 stsp #include "got_lib_delta.h"
36 63581804 2018-07-09 stsp #include "got_lib_inflate.h"
37 372ccdbb 2018-06-10 stsp #include "got_lib_object.h"
38 372ccdbb 2018-06-10 stsp #include "got_lib_object_idset.h"
39 372ccdbb 2018-06-10 stsp
40 372ccdbb 2018-06-10 stsp struct got_commit_graph_node {
41 372ccdbb 2018-06-10 stsp struct got_object_id id;
42 b43fbaa0 2018-06-11 stsp
43 ca6e02ac 2020-01-07 stsp /* Used only during iteration. */
44 ca6e02ac 2020-01-07 stsp time_t timestamp;
45 372ccdbb 2018-06-10 stsp TAILQ_ENTRY(got_commit_graph_node) entry;
46 372ccdbb 2018-06-10 stsp };
47 372ccdbb 2018-06-10 stsp
48 9ba79e04 2018-06-11 stsp TAILQ_HEAD(got_commit_graph_iter_list, got_commit_graph_node);
49 9ba79e04 2018-06-11 stsp
50 b565f6f8 2018-07-23 stsp struct got_commit_graph_branch_tip {
51 32777563 2018-11-07 stsp struct got_object_id *commit_id;
52 32777563 2018-11-07 stsp struct got_commit_object *commit;
53 32777563 2018-11-07 stsp struct got_commit_graph_node *new_node;
54 b565f6f8 2018-07-23 stsp };
55 b565f6f8 2018-07-23 stsp
56 372ccdbb 2018-06-10 stsp struct got_commit_graph {
57 372ccdbb 2018-06-10 stsp /* The set of all commits we have traversed. */
58 372ccdbb 2018-06-10 stsp struct got_object_idset *node_ids;
59 372ccdbb 2018-06-10 stsp
60 0ed6ed4c 2018-06-13 stsp int flags;
61 0ed6ed4c 2018-06-13 stsp #define GOT_COMMIT_GRAPH_FIRST_PARENT_TRAVERSAL 0x01
62 0ed6ed4c 2018-06-13 stsp
63 372ccdbb 2018-06-10 stsp /*
64 372ccdbb 2018-06-10 stsp * A set of object IDs of known parent commits which we have not yet
65 372ccdbb 2018-06-10 stsp * traversed. Each commit ID in this set represents a branch in commit
66 372ccdbb 2018-06-10 stsp * history: Either the first-parent branch of the head node, or another
67 372ccdbb 2018-06-10 stsp * branch corresponding to a traversed merge commit for which we have
68 372ccdbb 2018-06-10 stsp * not traversed a branch point commit yet.
69 372ccdbb 2018-06-10 stsp *
70 372ccdbb 2018-06-10 stsp * Whenever we add a commit with a matching ID to the graph, we remove
71 372ccdbb 2018-06-10 stsp * its corresponding element from this set, and add new elements for
72 372ccdbb 2018-06-10 stsp * each of that commit's parent commits which were not traversed yet.
73 372ccdbb 2018-06-10 stsp *
74 372ccdbb 2018-06-10 stsp * When API users ask us to fetch more commits, we fetch commits from
75 372ccdbb 2018-06-10 stsp * all currently open branches. This allows API users to process
76 372ccdbb 2018-06-10 stsp * commits in linear order even though the history contains branches.
77 372ccdbb 2018-06-10 stsp */
78 372ccdbb 2018-06-10 stsp struct got_object_idset *open_branches;
79 b565f6f8 2018-07-23 stsp
80 32777563 2018-11-07 stsp /* Array of branch tips for fetch_commits_from_open_branches(). */
81 b565f6f8 2018-07-23 stsp struct got_commit_graph_branch_tip *tips;
82 5e50c36a 2018-11-08 stsp int ntips;
83 372ccdbb 2018-06-10 stsp
84 31cedeaf 2018-09-15 stsp /* Path of tree entry of interest to the API user. */
85 31cedeaf 2018-09-15 stsp char *path;
86 31cedeaf 2018-09-15 stsp
87 94489f7d 2020-01-04 stsp /*
88 94489f7d 2020-01-04 stsp * Nodes which will be passed to the API user next, sorted by
89 94489f7d 2020-01-04 stsp * commit timestmap.
90 94489f7d 2020-01-04 stsp */
91 9ba79e04 2018-06-11 stsp struct got_commit_graph_iter_list iter_list;
92 372ccdbb 2018-06-10 stsp };
93 372ccdbb 2018-06-10 stsp
94 31cedeaf 2018-09-15 stsp static const struct got_error *
95 41fa1437 2018-11-05 stsp detect_changed_path(int *changed, struct got_commit_object *commit,
96 31cedeaf 2018-09-15 stsp struct got_object_id *commit_id, const char *path,
97 31cedeaf 2018-09-15 stsp struct got_repository *repo)
98 31cedeaf 2018-09-15 stsp {
99 31cedeaf 2018-09-15 stsp const struct got_error *err = NULL;
100 41fa1437 2018-11-05 stsp struct got_commit_object *pcommit = NULL;
101 31cedeaf 2018-09-15 stsp struct got_tree_object *tree = NULL, *ptree = NULL;
102 31cedeaf 2018-09-15 stsp struct got_object_qid *pid;
103 31cedeaf 2018-09-15 stsp
104 31cedeaf 2018-09-15 stsp if (got_path_is_root_dir(path)) {
105 31cedeaf 2018-09-15 stsp *changed = 1;
106 31cedeaf 2018-09-15 stsp return NULL;
107 31cedeaf 2018-09-15 stsp }
108 31cedeaf 2018-09-15 stsp
109 31cedeaf 2018-09-15 stsp *changed = 0;
110 31cedeaf 2018-09-15 stsp
111 dbdddfee 2021-06-23 naddy pid = STAILQ_FIRST(&commit->parent_ids);
112 31cedeaf 2018-09-15 stsp if (pid == NULL) {
113 31cedeaf 2018-09-15 stsp struct got_object_id *obj_id;
114 31cedeaf 2018-09-15 stsp err = got_object_id_by_path(&obj_id, repo, commit_id, path);
115 fd1d2703 2018-11-04 stsp if (err) {
116 d1451975 2018-11-11 stsp if (err->code == GOT_ERR_NO_TREE_ENTRY)
117 fd1d2703 2018-11-04 stsp err = NULL;
118 fd1d2703 2018-11-04 stsp } else
119 fd1d2703 2018-11-04 stsp *changed = 1; /* The path was created in this commit. */
120 31cedeaf 2018-09-15 stsp free(obj_id);
121 0e9101d5 2018-11-18 stsp return err;
122 0e9101d5 2018-11-18 stsp }
123 7310c1c3 2018-11-18 stsp
124 0e9101d5 2018-11-18 stsp err = got_object_open_as_tree(&tree, repo, commit->tree_id);
125 0e9101d5 2018-11-18 stsp if (err)
126 0e9101d5 2018-11-18 stsp return err;
127 372ccdbb 2018-06-10 stsp
128 0e9101d5 2018-11-18 stsp err = got_object_open_as_commit(&pcommit, repo, pid->id);
129 0e9101d5 2018-11-18 stsp if (err)
130 0e9101d5 2018-11-18 stsp goto done;
131 0e9101d5 2018-11-18 stsp
132 0e9101d5 2018-11-18 stsp err = got_object_open_as_tree(&ptree, repo, pcommit->tree_id);
133 0e9101d5 2018-11-18 stsp if (err)
134 0e9101d5 2018-11-18 stsp goto done;
135 0e9101d5 2018-11-18 stsp
136 81a966c0 2018-11-18 stsp err = got_object_tree_path_changed(changed, tree, ptree, path, repo);
137 31cedeaf 2018-09-15 stsp done:
138 31cedeaf 2018-09-15 stsp if (tree)
139 31cedeaf 2018-09-15 stsp got_object_tree_close(tree);
140 31cedeaf 2018-09-15 stsp if (ptree)
141 31cedeaf 2018-09-15 stsp got_object_tree_close(ptree);
142 31cedeaf 2018-09-15 stsp if (pcommit)
143 41fa1437 2018-11-05 stsp got_object_commit_close(pcommit);
144 31cedeaf 2018-09-15 stsp return err;
145 31cedeaf 2018-09-15 stsp }
146 31cedeaf 2018-09-15 stsp
147 4626e416 2018-06-10 stsp static void
148 9ba79e04 2018-06-11 stsp add_node_to_iter_list(struct got_commit_graph *graph,
149 ca6e02ac 2020-01-07 stsp struct got_commit_graph_node *node, time_t committer_time)
150 372ccdbb 2018-06-10 stsp {
151 4bd3f2bb 2018-06-10 stsp struct got_commit_graph_node *n, *next;
152 1c7a5dcb 2018-09-15 stsp
153 ca6e02ac 2020-01-07 stsp node->timestamp = committer_time;
154 ca6e02ac 2020-01-07 stsp
155 94489f7d 2020-01-04 stsp n = TAILQ_FIRST(&graph->iter_list);
156 bee6b577 2018-09-19 stsp while (n) {
157 bee6b577 2018-09-19 stsp next = TAILQ_NEXT(n, entry);
158 73026088 2018-11-18 stsp if (next && node->timestamp >= next->timestamp) {
159 bee6b577 2018-09-19 stsp TAILQ_INSERT_BEFORE(next, node, entry);
160 bee6b577 2018-09-19 stsp return;
161 fe8df4c2 2018-06-16 stsp }
162 bee6b577 2018-09-19 stsp n = next;
163 fe8df4c2 2018-06-16 stsp }
164 93e45b7c 2018-09-24 stsp TAILQ_INSERT_TAIL(&graph->iter_list, node, entry);
165 0ed6ed4c 2018-06-13 stsp }
166 0ed6ed4c 2018-06-13 stsp
167 0ed6ed4c 2018-06-13 stsp static const struct got_error *
168 ca6e02ac 2020-01-07 stsp add_node(struct got_commit_graph_node **new_node,
169 ca6e02ac 2020-01-07 stsp struct got_commit_graph *graph, struct got_object_id *commit_id,
170 ca6e02ac 2020-01-07 stsp struct got_repository *repo)
171 ca6e02ac 2020-01-07 stsp {
172 ca6e02ac 2020-01-07 stsp const struct got_error *err = NULL;
173 ca6e02ac 2020-01-07 stsp struct got_commit_graph_node *node;
174 ca6e02ac 2020-01-07 stsp
175 ca6e02ac 2020-01-07 stsp *new_node = NULL;
176 ca6e02ac 2020-01-07 stsp
177 ca6e02ac 2020-01-07 stsp node = calloc(1, sizeof(*node));
178 ca6e02ac 2020-01-07 stsp if (node == NULL)
179 ca6e02ac 2020-01-07 stsp return got_error_from_errno("calloc");
180 ca6e02ac 2020-01-07 stsp
181 ca6e02ac 2020-01-07 stsp memcpy(&node->id, commit_id, sizeof(node->id));
182 ca6e02ac 2020-01-07 stsp err = got_object_idset_add(graph->node_ids, &node->id, NULL);
183 ca6e02ac 2020-01-07 stsp if (err)
184 ca6e02ac 2020-01-07 stsp free(node);
185 ca6e02ac 2020-01-07 stsp else
186 ca6e02ac 2020-01-07 stsp *new_node = node;
187 ca6e02ac 2020-01-07 stsp return err;
188 ca6e02ac 2020-01-07 stsp }
189 ca6e02ac 2020-01-07 stsp
190 ca6e02ac 2020-01-07 stsp /*
191 ca6e02ac 2020-01-07 stsp * Ask got-read-pack to traverse first-parent history until a commit is
192 ca6e02ac 2020-01-07 stsp * encountered which modified graph->path, or until the pack file runs
193 ca6e02ac 2020-01-07 stsp * out of relevant commits. This is faster than sending an individual
194 ca6e02ac 2020-01-07 stsp * request for each commit stored in the pack file.
195 ca6e02ac 2020-01-07 stsp */
196 ca6e02ac 2020-01-07 stsp static const struct got_error *
197 ca6e02ac 2020-01-07 stsp packed_first_parent_traversal(int *ncommits_traversed,
198 ca6e02ac 2020-01-07 stsp struct got_commit_graph *graph, struct got_object_id *commit_id,
199 ca6e02ac 2020-01-07 stsp struct got_repository *repo)
200 ca6e02ac 2020-01-07 stsp {
201 ca6e02ac 2020-01-07 stsp const struct got_error *err = NULL;
202 ca6e02ac 2020-01-07 stsp struct got_object_id_queue traversed_commits;
203 ca6e02ac 2020-01-07 stsp struct got_object_qid *qid;
204 ca6e02ac 2020-01-07 stsp
205 dbdddfee 2021-06-23 naddy STAILQ_INIT(&traversed_commits);
206 ca6e02ac 2020-01-07 stsp *ncommits_traversed = 0;
207 ca6e02ac 2020-01-07 stsp
208 ca6e02ac 2020-01-07 stsp err = got_traverse_packed_commits(&traversed_commits,
209 ca6e02ac 2020-01-07 stsp commit_id, graph->path, repo);
210 ca6e02ac 2020-01-07 stsp if (err)
211 ca6e02ac 2020-01-07 stsp return err;
212 ca6e02ac 2020-01-07 stsp
213 ca6e02ac 2020-01-07 stsp /* Add all traversed commits to the graph... */
214 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(qid, &traversed_commits, entry) {
215 ca6e02ac 2020-01-07 stsp struct got_commit_graph_node *node;
216 ca6e02ac 2020-01-07 stsp
217 ca6e02ac 2020-01-07 stsp if (got_object_idset_contains(graph->open_branches, qid->id))
218 ca6e02ac 2020-01-07 stsp continue;
219 ca6e02ac 2020-01-07 stsp if (got_object_idset_contains(graph->node_ids, qid->id))
220 ca6e02ac 2020-01-07 stsp continue;
221 ca6e02ac 2020-01-07 stsp
222 ca6e02ac 2020-01-07 stsp (*ncommits_traversed)++;
223 ca6e02ac 2020-01-07 stsp
224 ca6e02ac 2020-01-07 stsp /* ... except the last commit is the new branch tip. */
225 dbdddfee 2021-06-23 naddy if (STAILQ_NEXT(qid, entry) == NULL) {
226 ca6e02ac 2020-01-07 stsp err = got_object_idset_add(graph->open_branches,
227 ca6e02ac 2020-01-07 stsp qid->id, NULL);
228 ca6e02ac 2020-01-07 stsp break;
229 ca6e02ac 2020-01-07 stsp }
230 ca6e02ac 2020-01-07 stsp
231 ca6e02ac 2020-01-07 stsp err = add_node(&node, graph, qid->id, repo);
232 ca6e02ac 2020-01-07 stsp if (err)
233 ca6e02ac 2020-01-07 stsp break;
234 ca6e02ac 2020-01-07 stsp }
235 ca6e02ac 2020-01-07 stsp
236 ca6e02ac 2020-01-07 stsp got_object_id_queue_free(&traversed_commits);
237 ca6e02ac 2020-01-07 stsp return err;
238 ca6e02ac 2020-01-07 stsp }
239 ca6e02ac 2020-01-07 stsp
240 ca6e02ac 2020-01-07 stsp static const struct got_error *
241 32c85d2c 2020-01-06 stsp close_branch(struct got_commit_graph *graph, struct got_object_id *commit_id)
242 32c85d2c 2020-01-06 stsp {
243 32c85d2c 2020-01-06 stsp const struct got_error *err;
244 32c85d2c 2020-01-06 stsp
245 32c85d2c 2020-01-06 stsp err = got_object_idset_remove(NULL, graph->open_branches, commit_id);
246 32c85d2c 2020-01-06 stsp if (err && err->code != GOT_ERR_NO_OBJ)
247 32c85d2c 2020-01-06 stsp return err;
248 32c85d2c 2020-01-06 stsp return NULL;
249 32c85d2c 2020-01-06 stsp }
250 32c85d2c 2020-01-06 stsp
251 32c85d2c 2020-01-06 stsp static const struct got_error *
252 14159a7b 2020-01-04 stsp advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
253 14159a7b 2020-01-04 stsp struct got_commit_object *commit, struct got_repository *repo)
254 0ed6ed4c 2018-06-13 stsp {
255 0ed6ed4c 2018-06-13 stsp const struct got_error *err;
256 0ed6ed4c 2018-06-13 stsp struct got_object_qid *qid;
257 0ed6ed4c 2018-06-13 stsp
258 32c85d2c 2020-01-06 stsp err = close_branch(graph, commit_id);
259 32c85d2c 2020-01-06 stsp if (err)
260 32c85d2c 2020-01-06 stsp return err;
261 32c85d2c 2020-01-06 stsp
262 0ed6ed4c 2018-06-13 stsp if (graph->flags & GOT_COMMIT_GRAPH_FIRST_PARENT_TRAVERSAL) {
263 dbdddfee 2021-06-23 naddy qid = STAILQ_FIRST(&commit->parent_ids);
264 9b88e78c 2018-11-18 stsp if (qid == NULL ||
265 8e291695 2020-01-04 stsp got_object_idset_contains(graph->open_branches, qid->id))
266 0ed6ed4c 2018-06-13 stsp return NULL;
267 ca6e02ac 2020-01-07 stsp /*
268 ca6e02ac 2020-01-07 stsp * The root directory always changes by definition, and when
269 ca6e02ac 2020-01-07 stsp * logging the root we want to traverse consecutive commits
270 ca6e02ac 2020-01-07 stsp * even if they point at the same tree.
271 ca6e02ac 2020-01-07 stsp * But if we are looking for a specific path then we can avoid
272 ca6e02ac 2020-01-07 stsp * fetching packed commits which did not modify the path and
273 ca6e02ac 2020-01-07 stsp * only fetch their IDs. This speeds up 'got blame'.
274 ca6e02ac 2020-01-07 stsp */
275 ca6e02ac 2020-01-07 stsp if (!got_path_is_root_dir(graph->path) &&
276 ca6e02ac 2020-01-07 stsp (commit->flags & GOT_COMMIT_FLAG_PACKED)) {
277 ca6e02ac 2020-01-07 stsp int ncommits = 0;
278 ca6e02ac 2020-01-07 stsp err = packed_first_parent_traversal(&ncommits,
279 ca6e02ac 2020-01-07 stsp graph, qid->id, repo);
280 ca6e02ac 2020-01-07 stsp if (err || ncommits > 0)
281 ca6e02ac 2020-01-07 stsp return err;
282 ca6e02ac 2020-01-07 stsp }
283 9b88e78c 2018-11-18 stsp return got_object_idset_add(graph->open_branches,
284 8e291695 2020-01-04 stsp qid->id, NULL);
285 bee6b577 2018-09-19 stsp }
286 bee6b577 2018-09-19 stsp
287 bee6b577 2018-09-19 stsp /*
288 bee6b577 2018-09-19 stsp * If we are graphing commits for a specific path, skip branches
289 bee6b577 2018-09-19 stsp * which do not contribute any content to this path.
290 bee6b577 2018-09-19 stsp */
291 7a62478b 2018-11-18 stsp if (commit->nparents > 1 && !got_path_is_root_dir(graph->path)) {
292 6dcdad08 2018-11-18 stsp struct got_object_id *merged_id, *prev_id = NULL;
293 bee6b577 2018-09-19 stsp int branches_differ = 0;
294 bee6b577 2018-09-19 stsp
295 bee6b577 2018-09-19 stsp err = got_object_id_by_path(&merged_id, repo, commit_id,
296 bee6b577 2018-09-19 stsp graph->path);
297 bee6b577 2018-09-19 stsp if (err)
298 bee6b577 2018-09-19 stsp return err;
299 bee6b577 2018-09-19 stsp
300 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(qid, &commit->parent_ids, entry) {
301 6dcdad08 2018-11-18 stsp struct got_object_id *id;
302 6dcdad08 2018-11-18 stsp
303 8e291695 2020-01-04 stsp if (got_object_idset_contains(graph->open_branches,
304 8e291695 2020-01-04 stsp qid->id))
305 9b88e78c 2018-11-18 stsp continue;
306 bee6b577 2018-09-19 stsp
307 bee6b577 2018-09-19 stsp err = got_object_id_by_path(&id, repo, qid->id,
308 bee6b577 2018-09-19 stsp graph->path);
309 bee6b577 2018-09-19 stsp if (err) {
310 d1451975 2018-11-11 stsp if (err->code == GOT_ERR_NO_TREE_ENTRY) {
311 bee6b577 2018-09-19 stsp branches_differ = 1;
312 bee6b577 2018-09-19 stsp continue;
313 bee6b577 2018-09-19 stsp }
314 6dcdad08 2018-11-18 stsp free(merged_id);
315 6dcdad08 2018-11-18 stsp free(prev_id);
316 bee6b577 2018-09-19 stsp return err;
317 bee6b577 2018-09-19 stsp }
318 bee6b577 2018-09-19 stsp
319 bee6b577 2018-09-19 stsp if (prev_id) {
320 bee6b577 2018-09-19 stsp if (!branches_differ &&
321 d2c2d781 2018-11-18 stsp got_object_id_cmp(id, prev_id) != 0)
322 bee6b577 2018-09-19 stsp branches_differ = 1;
323 6dcdad08 2018-11-18 stsp free(prev_id);
324 6dcdad08 2018-11-18 stsp }
325 6dcdad08 2018-11-18 stsp prev_id = id;
326 bee6b577 2018-09-19 stsp
327 bee6b577 2018-09-19 stsp /*
328 bee6b577 2018-09-19 stsp * If a branch has created the merged content we can
329 bee6b577 2018-09-19 stsp * skip any other branches.
330 bee6b577 2018-09-19 stsp */
331 bee6b577 2018-09-19 stsp if (got_object_id_cmp(merged_id, id) == 0) {
332 b36429ab 2018-11-05 stsp err = got_object_idset_add(graph->open_branches,
333 8e291695 2020-01-04 stsp qid->id, NULL);
334 6dcdad08 2018-11-18 stsp free(merged_id);
335 6dcdad08 2018-11-18 stsp free(id);
336 b36429ab 2018-11-05 stsp return err;
337 bee6b577 2018-09-19 stsp }
338 bee6b577 2018-09-19 stsp }
339 6dcdad08 2018-11-18 stsp
340 6dcdad08 2018-11-18 stsp free(prev_id);
341 6dcdad08 2018-11-18 stsp prev_id = NULL;
342 6dcdad08 2018-11-18 stsp free(merged_id);
343 6dcdad08 2018-11-18 stsp merged_id = NULL;
344 bee6b577 2018-09-19 stsp
345 bee6b577 2018-09-19 stsp /*
346 bee6b577 2018-09-19 stsp * If the path's content is the same on all branches,
347 bee6b577 2018-09-19 stsp * follow the first parent only.
348 bee6b577 2018-09-19 stsp */
349 bee6b577 2018-09-19 stsp if (!branches_differ) {
350 dbdddfee 2021-06-23 naddy qid = STAILQ_FIRST(&commit->parent_ids);
351 bee6b577 2018-09-19 stsp if (qid == NULL)
352 bee6b577 2018-09-19 stsp return NULL;
353 8e291695 2020-01-04 stsp if (got_object_idset_contains(graph->open_branches,
354 8e291695 2020-01-04 stsp qid->id))
355 b36429ab 2018-11-05 stsp return NULL;
356 8e291695 2020-01-04 stsp if (got_object_idset_contains(graph->node_ids,
357 8e291695 2020-01-04 stsp qid->id))
358 998ff57f 2018-11-18 stsp return NULL; /* parent already traversed */
359 b36429ab 2018-11-05 stsp return got_object_idset_add(graph->open_branches,
360 8e291695 2020-01-04 stsp qid->id, NULL);
361 bee6b577 2018-09-19 stsp }
362 0ed6ed4c 2018-06-13 stsp }
363 0ed6ed4c 2018-06-13 stsp
364 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(qid, &commit->parent_ids, entry) {
365 8e291695 2020-01-04 stsp if (got_object_idset_contains(graph->open_branches, qid->id))
366 b36429ab 2018-11-05 stsp continue;
367 8e291695 2020-01-04 stsp if (got_object_idset_contains(graph->node_ids, qid->id))
368 998ff57f 2018-11-18 stsp continue; /* parent already traversed */
369 8e291695 2020-01-04 stsp err = got_object_idset_add(graph->open_branches, qid->id, NULL);
370 b36429ab 2018-11-05 stsp if (err)
371 0ed6ed4c 2018-06-13 stsp return err;
372 0ed6ed4c 2018-06-13 stsp }
373 0ed6ed4c 2018-06-13 stsp
374 b43fbaa0 2018-06-11 stsp return NULL;
375 de56b2d7 2020-01-04 stsp }
376 372ccdbb 2018-06-10 stsp
377 de56b2d7 2020-01-04 stsp const struct got_error *
378 c4d7a9c4 2018-06-11 stsp got_commit_graph_open(struct got_commit_graph **graph,
379 3d509237 2020-01-04 stsp const char *path, int first_parent_traversal)
380 3d509237 2020-01-04 stsp {
381 22220781 2020-01-04 stsp const struct got_error *err = NULL;
382 3ddcebf3 2020-01-04 stsp
383 3ddcebf3 2020-01-04 stsp *graph = calloc(1, sizeof(**graph));
384 3d509237 2020-01-04 stsp if (*graph == NULL)
385 3ddcebf3 2020-01-04 stsp return got_error_from_errno("calloc");
386 88cdb9c6 2020-01-04 stsp
387 88cdb9c6 2020-01-04 stsp TAILQ_INIT(&(*graph)->iter_list);
388 3ddcebf3 2020-01-04 stsp
389 3ddcebf3 2020-01-04 stsp (*graph)->path = strdup(path);
390 3ddcebf3 2020-01-04 stsp if ((*graph)->path == NULL) {
391 3ddcebf3 2020-01-04 stsp err = got_error_from_errno("strdup");
392 22220781 2020-01-04 stsp goto done;
393 3ddcebf3 2020-01-04 stsp }
394 3ddcebf3 2020-01-04 stsp
395 3ddcebf3 2020-01-04 stsp (*graph)->node_ids = got_object_idset_alloc();
396 3ddcebf3 2020-01-04 stsp if ((*graph)->node_ids == NULL) {
397 3ddcebf3 2020-01-04 stsp err = got_error_from_errno("got_object_idset_alloc");
398 22220781 2020-01-04 stsp goto done;
399 3ddcebf3 2020-01-04 stsp }
400 372ccdbb 2018-06-10 stsp
401 3ddcebf3 2020-01-04 stsp (*graph)->open_branches = got_object_idset_alloc();
402 3ddcebf3 2020-01-04 stsp if ((*graph)->open_branches == NULL) {
403 3ddcebf3 2020-01-04 stsp err = got_error_from_errno("got_object_idset_alloc");
404 22220781 2020-01-04 stsp goto done;
405 3ddcebf3 2020-01-04 stsp }
406 3ddcebf3 2020-01-04 stsp
407 0ed6ed4c 2018-06-13 stsp if (first_parent_traversal)
408 0ed6ed4c 2018-06-13 stsp (*graph)->flags |= GOT_COMMIT_GRAPH_FIRST_PARENT_TRAVERSAL;
409 22220781 2020-01-04 stsp done:
410 22220781 2020-01-04 stsp if (err) {
411 22220781 2020-01-04 stsp got_commit_graph_close(*graph);
412 22220781 2020-01-04 stsp *graph = NULL;
413 22220781 2020-01-04 stsp }
414 22220781 2020-01-04 stsp return err;
415 372ccdbb 2018-06-10 stsp }
416 372ccdbb 2018-06-10 stsp
417 32777563 2018-11-07 stsp struct add_branch_tip_arg {
418 b565f6f8 2018-07-23 stsp struct got_commit_graph_branch_tip *tips;
419 b565f6f8 2018-07-23 stsp int ntips;
420 32777563 2018-11-07 stsp struct got_repository *repo;
421 32777563 2018-11-07 stsp struct got_commit_graph *graph;
422 372ccdbb 2018-06-10 stsp };
423 372ccdbb 2018-06-10 stsp
424 cb103d04 2018-11-07 stsp static const struct got_error *
425 32777563 2018-11-07 stsp add_branch_tip(struct got_object_id *commit_id, void *data, void *arg)
426 372ccdbb 2018-06-10 stsp {
427 32777563 2018-11-07 stsp const struct got_error *err;
428 32777563 2018-11-07 stsp struct add_branch_tip_arg *a = arg;
429 32777563 2018-11-07 stsp struct got_commit_graph_node *new_node;
430 32777563 2018-11-07 stsp struct got_commit_object *commit;
431 32777563 2018-11-07 stsp
432 32777563 2018-11-07 stsp err = got_object_open_as_commit(&commit, a->repo, commit_id);
433 32777563 2018-11-07 stsp if (err)
434 32777563 2018-11-07 stsp return err;
435 32777563 2018-11-07 stsp
436 ca6e02ac 2020-01-07 stsp err = add_node(&new_node, a->graph, commit_id, a->repo);
437 32777563 2018-11-07 stsp if (err)
438 32777563 2018-11-07 stsp return err;
439 32777563 2018-11-07 stsp
440 32777563 2018-11-07 stsp a->tips[a->ntips].commit_id = new_node ? &new_node->id : NULL;
441 32777563 2018-11-07 stsp a->tips[a->ntips].commit = commit;
442 32777563 2018-11-07 stsp a->tips[a->ntips].new_node = new_node;
443 b565f6f8 2018-07-23 stsp a->ntips++;
444 32777563 2018-11-07 stsp
445 cb103d04 2018-11-07 stsp return NULL;
446 372ccdbb 2018-06-10 stsp }
447 372ccdbb 2018-06-10 stsp
448 1142eae9 2018-06-11 stsp static const struct got_error *
449 57eecd46 2020-01-04 stsp fetch_commits_from_open_branches(struct got_commit_graph *graph,
450 6fb7cd11 2019-08-22 stsp struct got_repository *repo, got_cancel_cb cancel_cb, void *cancel_arg)
451 372ccdbb 2018-06-10 stsp {
452 372ccdbb 2018-06-10 stsp const struct got_error *err;
453 32777563 2018-11-07 stsp struct add_branch_tip_arg arg;
454 32777563 2018-11-07 stsp int i, ntips;
455 372ccdbb 2018-06-10 stsp
456 32777563 2018-11-07 stsp ntips = got_object_idset_num_elements(graph->open_branches);
457 32777563 2018-11-07 stsp if (ntips == 0)
458 372ccdbb 2018-06-10 stsp return NULL;
459 372ccdbb 2018-06-10 stsp
460 32777563 2018-11-07 stsp /* (Re-)allocate branch tips array if necessary. */
461 32777563 2018-11-07 stsp if (graph->ntips < ntips) {
462 b565f6f8 2018-07-23 stsp struct got_commit_graph_branch_tip *tips;
463 5e50c36a 2018-11-08 stsp tips = recallocarray(graph->tips, graph->ntips, ntips,
464 5e50c36a 2018-11-08 stsp sizeof(*tips));
465 b565f6f8 2018-07-23 stsp if (tips == NULL)
466 638f9024 2019-05-13 stsp return got_error_from_errno("recallocarray");
467 b565f6f8 2018-07-23 stsp graph->tips = tips;
468 32777563 2018-11-07 stsp graph->ntips = ntips;
469 b565f6f8 2018-07-23 stsp }
470 b565f6f8 2018-07-23 stsp arg.tips = graph->tips;
471 32777563 2018-11-07 stsp arg.ntips = 0; /* add_branch_tip() will increment */
472 32777563 2018-11-07 stsp arg.repo = repo;
473 32777563 2018-11-07 stsp arg.graph = graph;
474 32777563 2018-11-07 stsp err = got_object_idset_for_each(graph->open_branches, add_branch_tip,
475 32777563 2018-11-07 stsp &arg);
476 cb103d04 2018-11-07 stsp if (err)
477 32777563 2018-11-07 stsp goto done;
478 372ccdbb 2018-06-10 stsp
479 b565f6f8 2018-07-23 stsp for (i = 0; i < arg.ntips; i++) {
480 372ccdbb 2018-06-10 stsp struct got_object_id *commit_id;
481 41fa1437 2018-11-05 stsp struct got_commit_object *commit;
482 32777563 2018-11-07 stsp struct got_commit_graph_node *new_node;
483 13a851c1 2020-01-04 stsp int changed;
484 372ccdbb 2018-06-10 stsp
485 6fb7cd11 2019-08-22 stsp if (cancel_cb) {
486 6fb7cd11 2019-08-22 stsp err = (*cancel_cb)(cancel_arg);
487 6fb7cd11 2019-08-22 stsp if (err)
488 6fb7cd11 2019-08-22 stsp break;
489 6fb7cd11 2019-08-22 stsp }
490 6fb7cd11 2019-08-22 stsp
491 32777563 2018-11-07 stsp commit_id = arg.tips[i].commit_id;
492 32777563 2018-11-07 stsp commit = arg.tips[i].commit;
493 32777563 2018-11-07 stsp new_node = arg.tips[i].new_node;
494 de56b2d7 2020-01-04 stsp
495 13a851c1 2020-01-04 stsp err = detect_changed_path(&changed, commit, commit_id,
496 13a851c1 2020-01-04 stsp graph->path, repo);
497 13a851c1 2020-01-04 stsp if (err) {
498 13a851c1 2020-01-04 stsp if (err->code != GOT_ERR_NO_OBJ)
499 13a851c1 2020-01-04 stsp break;
500 13a851c1 2020-01-04 stsp /*
501 13a851c1 2020-01-04 stsp * History of the path stops here on the current
502 13a851c1 2020-01-04 stsp * branch. Keep going on other branches.
503 13a851c1 2020-01-04 stsp */
504 32c85d2c 2020-01-06 stsp err = close_branch(graph, commit_id);
505 32c85d2c 2020-01-06 stsp if (err)
506 32c85d2c 2020-01-06 stsp break;
507 ec1904dc 2020-01-04 stsp continue;
508 13a851c1 2020-01-04 stsp }
509 57eecd46 2020-01-04 stsp if (changed)
510 ca6e02ac 2020-01-07 stsp add_node_to_iter_list(graph, new_node,
511 ca6e02ac 2020-01-07 stsp got_object_commit_get_committer_time(commit));
512 14159a7b 2020-01-04 stsp err = advance_branch(graph, commit_id, commit, repo);
513 cb352812 2018-07-22 stsp if (err)
514 cb352812 2018-07-22 stsp break;
515 372ccdbb 2018-06-10 stsp }
516 32777563 2018-11-07 stsp done:
517 246e1c78 2018-11-08 stsp for (i = 0; i < arg.ntips; i++)
518 32777563 2018-11-07 stsp got_object_commit_close(arg.tips[i].commit);
519 372ccdbb 2018-06-10 stsp return err;
520 372ccdbb 2018-06-10 stsp }
521 372ccdbb 2018-06-10 stsp
522 372ccdbb 2018-06-10 stsp void
523 372ccdbb 2018-06-10 stsp got_commit_graph_close(struct got_commit_graph *graph)
524 372ccdbb 2018-06-10 stsp {
525 22220781 2020-01-04 stsp if (graph->open_branches)
526 22220781 2020-01-04 stsp got_object_idset_free(graph->open_branches);
527 22220781 2020-01-04 stsp if (graph->node_ids)
528 22220781 2020-01-04 stsp got_object_idset_free(graph->node_ids);
529 b565f6f8 2018-07-23 stsp free(graph->tips);
530 31cedeaf 2018-09-15 stsp free(graph->path);
531 372ccdbb 2018-06-10 stsp free(graph);
532 372ccdbb 2018-06-10 stsp }
533 372ccdbb 2018-06-10 stsp
534 372ccdbb 2018-06-10 stsp const struct got_error *
535 372ccdbb 2018-06-10 stsp got_commit_graph_iter_start(struct got_commit_graph *graph,
536 6fb7cd11 2019-08-22 stsp struct got_object_id *id, struct got_repository *repo,
537 6fb7cd11 2019-08-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
538 372ccdbb 2018-06-10 stsp {
539 31cedeaf 2018-09-15 stsp const struct got_error *err = NULL;
540 372ccdbb 2018-06-10 stsp
541 3d509237 2020-01-04 stsp if (!TAILQ_EMPTY(&graph->iter_list))
542 3d509237 2020-01-04 stsp return got_error(GOT_ERR_ITER_BUSY);
543 31cedeaf 2018-09-15 stsp
544 3ff3126d 2020-01-04 stsp err = got_object_idset_add(graph->open_branches, id, NULL);
545 3d509237 2020-01-04 stsp if (err)
546 7e33c8c5 2020-01-04 stsp return err;
547 3d509237 2020-01-04 stsp
548 3ff3126d 2020-01-04 stsp /* Locate first commit which changed graph->path. */
549 94489f7d 2020-01-04 stsp while (TAILQ_EMPTY(&graph->iter_list) &&
550 3ff3126d 2020-01-04 stsp got_object_idset_num_elements(graph->open_branches) > 0) {
551 3ff3126d 2020-01-04 stsp err = fetch_commits_from_open_branches(graph, repo,
552 3ff3126d 2020-01-04 stsp cancel_cb, cancel_arg);
553 3ff3126d 2020-01-04 stsp if (err)
554 7e33c8c5 2020-01-04 stsp return err;
555 5175b31a 2020-01-04 stsp }
556 5175b31a 2020-01-04 stsp
557 94489f7d 2020-01-04 stsp if (TAILQ_EMPTY(&graph->iter_list)) {
558 5175b31a 2020-01-04 stsp const char *path;
559 5175b31a 2020-01-04 stsp if (got_path_is_root_dir(graph->path))
560 5175b31a 2020-01-04 stsp return got_error_no_obj(id);
561 5175b31a 2020-01-04 stsp path = graph->path;
562 5175b31a 2020-01-04 stsp while (path[0] == '/')
563 5175b31a 2020-01-04 stsp path++;
564 5175b31a 2020-01-04 stsp return got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
565 31cedeaf 2018-09-15 stsp }
566 7e33c8c5 2020-01-04 stsp
567 7e33c8c5 2020-01-04 stsp return NULL;
568 372ccdbb 2018-06-10 stsp }
569 372ccdbb 2018-06-10 stsp
570 372ccdbb 2018-06-10 stsp const struct got_error *
571 b43fbaa0 2018-06-11 stsp got_commit_graph_iter_next(struct got_object_id **id,
572 ee780d5c 2020-01-04 stsp struct got_commit_graph *graph, struct got_repository *repo,
573 ee780d5c 2020-01-04 stsp got_cancel_cb cancel_cb, void *cancel_arg)
574 372ccdbb 2018-06-10 stsp {
575 ee780d5c 2020-01-04 stsp const struct got_error *err = NULL;
576 94489f7d 2020-01-04 stsp struct got_commit_graph_node *node;
577 ee780d5c 2020-01-04 stsp
578 9ba79e04 2018-06-11 stsp *id = NULL;
579 372ccdbb 2018-06-10 stsp
580 df8cd9c6 2020-01-05 stsp node = TAILQ_FIRST(&graph->iter_list);
581 df8cd9c6 2020-01-05 stsp if (node == NULL) {
582 2c7f8870 2018-09-19 stsp /* We are done iterating, or iteration was not started. */
583 9ba79e04 2018-06-11 stsp return got_error(GOT_ERR_ITER_COMPLETED);
584 9ba79e04 2018-06-11 stsp }
585 9ba79e04 2018-06-11 stsp
586 94489f7d 2020-01-04 stsp while (TAILQ_NEXT(node, entry) == NULL &&
587 ee780d5c 2020-01-04 stsp got_object_idset_num_elements(graph->open_branches) > 0) {
588 57eecd46 2020-01-04 stsp err = fetch_commits_from_open_branches(graph, repo,
589 57eecd46 2020-01-04 stsp cancel_cb, cancel_arg);
590 ee780d5c 2020-01-04 stsp if (err)
591 ee780d5c 2020-01-04 stsp return err;
592 ee780d5c 2020-01-04 stsp }
593 372ccdbb 2018-06-10 stsp
594 94489f7d 2020-01-04 stsp *id = &node->id;
595 94489f7d 2020-01-04 stsp TAILQ_REMOVE(&graph->iter_list, node, entry);
596 372ccdbb 2018-06-10 stsp return NULL;
597 372ccdbb 2018-06-10 stsp }
598 a9833bc9 2019-05-13 stsp
599 a9833bc9 2019-05-13 stsp const struct got_error *
600 a9833bc9 2019-05-13 stsp got_commit_graph_find_youngest_common_ancestor(struct got_object_id **yca_id,
601 a9833bc9 2019-05-13 stsp struct got_object_id *commit_id, struct got_object_id *commit_id2,
602 768705e3 2021-09-27 thomas int first_parent_traversal,
603 6fb7cd11 2019-08-22 stsp struct got_repository *repo, got_cancel_cb cancel_cb, void *cancel_arg)
604 a9833bc9 2019-05-13 stsp {
605 a9833bc9 2019-05-13 stsp const struct got_error *err = NULL;
606 a9833bc9 2019-05-13 stsp struct got_commit_graph *graph = NULL, *graph2 = NULL;
607 a9833bc9 2019-05-13 stsp int completed = 0, completed2 = 0;
608 a9833bc9 2019-05-13 stsp struct got_object_idset *commit_ids;
609 a9833bc9 2019-05-13 stsp
610 a9833bc9 2019-05-13 stsp *yca_id = NULL;
611 a9833bc9 2019-05-13 stsp
612 a9833bc9 2019-05-13 stsp commit_ids = got_object_idset_alloc();
613 a9833bc9 2019-05-13 stsp if (commit_ids == NULL)
614 638f9024 2019-05-13 stsp return got_error_from_errno("got_object_idset_alloc");
615 a9833bc9 2019-05-13 stsp
616 768705e3 2021-09-27 thomas err = got_commit_graph_open(&graph, "/", first_parent_traversal);
617 a9833bc9 2019-05-13 stsp if (err)
618 a9833bc9 2019-05-13 stsp goto done;
619 a9833bc9 2019-05-13 stsp
620 768705e3 2021-09-27 thomas err = got_commit_graph_open(&graph2, "/", first_parent_traversal);
621 a9833bc9 2019-05-13 stsp if (err)
622 a9833bc9 2019-05-13 stsp goto done;
623 a9833bc9 2019-05-13 stsp
624 6fb7cd11 2019-08-22 stsp err = got_commit_graph_iter_start(graph, commit_id, repo,
625 6fb7cd11 2019-08-22 stsp cancel_cb, cancel_arg);
626 a9833bc9 2019-05-13 stsp if (err)
627 a9833bc9 2019-05-13 stsp goto done;
628 a9833bc9 2019-05-13 stsp
629 6fb7cd11 2019-08-22 stsp err = got_commit_graph_iter_start(graph2, commit_id2, repo,
630 6fb7cd11 2019-08-22 stsp cancel_cb, cancel_arg);
631 a9833bc9 2019-05-13 stsp if (err)
632 a9833bc9 2019-05-13 stsp goto done;
633 a9833bc9 2019-05-13 stsp
634 a9833bc9 2019-05-13 stsp for (;;) {
635 ee780d5c 2020-01-04 stsp struct got_object_id *id = NULL, *id2 = NULL;
636 a9833bc9 2019-05-13 stsp
637 6fb7cd11 2019-08-22 stsp if (cancel_cb) {
638 6fb7cd11 2019-08-22 stsp err = (*cancel_cb)(cancel_arg);
639 6fb7cd11 2019-08-22 stsp if (err)
640 6fb7cd11 2019-08-22 stsp break;
641 6fb7cd11 2019-08-22 stsp }
642 6fb7cd11 2019-08-22 stsp
643 a9833bc9 2019-05-13 stsp if (!completed) {
644 ee780d5c 2020-01-04 stsp err = got_commit_graph_iter_next(&id, graph, repo,
645 ee780d5c 2020-01-04 stsp cancel_cb, cancel_arg);
646 a9833bc9 2019-05-13 stsp if (err) {
647 ee780d5c 2020-01-04 stsp if (err->code != GOT_ERR_ITER_COMPLETED)
648 a9833bc9 2019-05-13 stsp break;
649 ee780d5c 2020-01-04 stsp err = NULL;
650 ee780d5c 2020-01-04 stsp completed = 1;
651 a9833bc9 2019-05-13 stsp }
652 a9833bc9 2019-05-13 stsp }
653 a9833bc9 2019-05-13 stsp
654 a9833bc9 2019-05-13 stsp if (!completed2) {
655 ee780d5c 2020-01-04 stsp err = got_commit_graph_iter_next(&id2, graph2, repo,
656 ee780d5c 2020-01-04 stsp cancel_cb, cancel_arg);
657 a9833bc9 2019-05-13 stsp if (err) {
658 ee780d5c 2020-01-04 stsp if (err->code != GOT_ERR_ITER_COMPLETED)
659 a9833bc9 2019-05-13 stsp break;
660 ee780d5c 2020-01-04 stsp err = NULL;
661 ee780d5c 2020-01-04 stsp completed2 = 1;
662 a9833bc9 2019-05-13 stsp }
663 a9833bc9 2019-05-13 stsp }
664 a9833bc9 2019-05-13 stsp
665 a9833bc9 2019-05-13 stsp if (id) {
666 8e291695 2020-01-04 stsp if (got_object_idset_contains(commit_ids, id)) {
667 a9833bc9 2019-05-13 stsp *yca_id = got_object_id_dup(id);
668 a9833bc9 2019-05-13 stsp if (*yca_id)
669 a9833bc9 2019-05-13 stsp break;
670 82751bc5 2019-05-13 stsp err = got_error_from_errno("got_object_id_dup");
671 a9833bc9 2019-05-13 stsp break;
672 a9833bc9 2019-05-13 stsp
673 a9833bc9 2019-05-13 stsp }
674 8e291695 2020-01-04 stsp err = got_object_idset_add(commit_ids, id, NULL);
675 a9833bc9 2019-05-13 stsp if (err)
676 a9833bc9 2019-05-13 stsp break;
677 a9833bc9 2019-05-13 stsp }
678 a9833bc9 2019-05-13 stsp if (id2) {
679 8e291695 2020-01-04 stsp if (got_object_idset_contains(commit_ids, id2)) {
680 a9833bc9 2019-05-13 stsp *yca_id = got_object_id_dup(id2);
681 a9833bc9 2019-05-13 stsp if (*yca_id)
682 a9833bc9 2019-05-13 stsp break;
683 82751bc5 2019-05-13 stsp err = got_error_from_errno("got_object_id_dup");
684 a9833bc9 2019-05-13 stsp break;
685 a9833bc9 2019-05-13 stsp
686 a9833bc9 2019-05-13 stsp }
687 8e291695 2020-01-04 stsp err = got_object_idset_add(commit_ids, id2, NULL);
688 a9833bc9 2019-05-13 stsp if (err)
689 a9833bc9 2019-05-13 stsp break;
690 a9833bc9 2019-05-13 stsp }
691 a9833bc9 2019-05-13 stsp
692 a9833bc9 2019-05-13 stsp if (completed && completed2) {
693 a9833bc9 2019-05-13 stsp err = got_error(GOT_ERR_ANCESTRY);
694 a9833bc9 2019-05-13 stsp break;
695 a9833bc9 2019-05-13 stsp }
696 a9833bc9 2019-05-13 stsp
697 a9833bc9 2019-05-13 stsp }
698 a9833bc9 2019-05-13 stsp done:
699 a9833bc9 2019-05-13 stsp got_object_idset_free(commit_ids);
700 a9833bc9 2019-05-13 stsp if (graph)
701 a9833bc9 2019-05-13 stsp got_commit_graph_close(graph);
702 a9833bc9 2019-05-13 stsp if (graph2)
703 a9833bc9 2019-05-13 stsp got_commit_graph_close(graph2);
704 a9833bc9 2019-05-13 stsp return err;
705 a9833bc9 2019-05-13 stsp }