MCPcopy Create free account
hub / github.com/git/git / remove_redundant_with_gen

Function remove_redundant_with_gen

commit-reach.c:339–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337}
338
339static int remove_redundant_with_gen(struct repository *r,
340 struct commit **array, size_t cnt,
341 size_t *dedup_cnt)
342{
343 size_t i, count_non_stale = 0, count_still_independent = cnt;
344 timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
345 struct commit **sorted;
346 struct commit_stack walk_start = COMMIT_STACK_INIT;
347 size_t min_gen_pos = 0;
348
349 /*
350 * Sort the input by generation number, ascending. This allows
351 * us to increase the "min_generation" limit when we discover
352 * the commit with lowest generation is STALE. The index
353 * min_gen_pos points to the current position within 'array'
354 * that is not yet known to be STALE.
355 */
356 DUP_ARRAY(sorted, array, cnt);
357 QSORT(sorted, cnt, compare_commits_by_gen);
358 min_generation = commit_graph_generation(sorted[0]);
359
360 commit_stack_grow(&walk_start, cnt);
361
362 /* Mark all parents of the input as STALE */
363 for (i = 0; i < cnt; i++) {
364 struct commit_list *parents;
365
366 repo_parse_commit(r, array[i]);
367 array[i]->object.flags |= RESULT;
368 parents = array[i]->parents;
369
370 while (parents) {
371 repo_parse_commit(r, parents->item);
372 if (!(parents->item->object.flags & STALE)) {
373 parents->item->object.flags |= STALE;
374 commit_stack_push(&walk_start, parents->item);
375 }
376 parents = parents->next;
377 }
378 }
379
380 QSORT(walk_start.items, walk_start.nr, compare_commits_by_gen);
381
382 /* remove STALE bit for now to allow walking through parents */
383 for (i = 0; i < walk_start.nr; i++)
384 walk_start.items[i]->object.flags &= ~STALE;
385
386 /*
387 * Start walking from the highest generation. Hopefully, it will
388 * find all other items during the first-parent walk, and we can
389 * terminate early. Otherwise, we will do the same amount of work
390 * as before.
391 */
392 for (i = walk_start.nr; i && count_still_independent > 1; i--) {
393 /* push the STALE bits up to min generation */
394 struct commit_list *stack = NULL;
395
396 commit_list_insert(walk_start.items[i - 1], &stack);

Callers 1

remove_redundantFunction · 0.85

Calls 10

commit_graph_generationFunction · 0.85
commit_stack_growFunction · 0.85
repo_parse_commitFunction · 0.85
commit_stack_pushFunction · 0.85
commit_list_insertFunction · 0.85
oideqFunction · 0.85
pop_commitFunction · 0.85
commit_list_freeFunction · 0.85
clear_commit_marks_manyFunction · 0.85
commit_stack_clearFunction · 0.85

Tested by

no test coverage detected