MCPcopy Index your code
hub / github.com/git/git / get_branch_base_for_tip

Function get_branch_base_for_tip

commit-reach.c:1317–1432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1315#define set_best(c,v) (*best_branch_base_at(&best_branch_base, (c)) = (v))
1316
1317int get_branch_base_for_tip(struct repository *r,
1318 struct commit *tip,
1319 struct commit **bases,
1320 size_t bases_nr)
1321{
1322 int best_index = -1;
1323 struct commit *branch_point = NULL;
1324 struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
1325 int found_missing_gen = 0;
1326
1327 if (!bases_nr)
1328 return -1;
1329
1330 repo_parse_commit(r, tip);
1331 if (commit_graph_generation(tip) == GENERATION_NUMBER_INFINITY)
1332 found_missing_gen = 1;
1333
1334 /* Check for missing generation numbers. */
1335 for (size_t i = 0; i < bases_nr; i++) {
1336 struct commit *c = bases[i];
1337 repo_parse_commit(r, c);
1338 if (commit_graph_generation(c) == GENERATION_NUMBER_INFINITY)
1339 found_missing_gen = 1;
1340 }
1341
1342 if (found_missing_gen) {
1343 struct commit **commits;
1344 size_t commits_nr = bases_nr + 1;
1345
1346 CALLOC_ARRAY(commits, commits_nr);
1347 COPY_ARRAY(commits, bases, bases_nr);
1348 commits[bases_nr] = tip;
1349 ensure_generations_valid(r, commits, commits_nr);
1350 free(commits);
1351 }
1352
1353 /* Initialize queue and slab now that generations are guaranteed. */
1354 init_best_branch_base(&best_branch_base);
1355 set_best(tip, -1);
1356 prio_queue_put(&queue, tip);
1357
1358 for (size_t i = 0; i < bases_nr; i++) {
1359 struct commit *c = bases[i];
1360 int best = get_best(c);
1361
1362 /* Has this already been marked as best by another commit? */
1363 if (best) {
1364 if (best == -1) {
1365 /* We agree at this position. Stop now. */
1366 best_index = i + 1;
1367 goto cleanup;
1368 }
1369 continue;
1370 }
1371
1372 set_best(c, i + 1);
1373 prio_queue_put(&queue, c);
1374 }

Callers 2

filter_is_baseFunction · 0.85
cmd__reachFunction · 0.85

Calls 6

repo_parse_commitFunction · 0.85
commit_graph_generationFunction · 0.85
ensure_generations_validFunction · 0.85
prio_queue_putFunction · 0.85
prio_queue_getFunction · 0.85
clear_prio_queueFunction · 0.85

Tested by 1

cmd__reachFunction · 0.68