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

Function ahead_behind

commit-reach.c:1117–1193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1115}
1116
1117void ahead_behind(struct repository *r,
1118 struct commit **commits, size_t commits_nr,
1119 struct ahead_behind_count *counts, size_t counts_nr)
1120{
1121 struct nonstale_queue queue = {
1122 { .compare = compare_commits_by_gen_then_commit_date }
1123 };
1124 size_t width = DIV_ROUND_UP(commits_nr, BITS_IN_EWORD);
1125
1126 if (!commits_nr || !counts_nr)
1127 return;
1128
1129 for (size_t i = 0; i < counts_nr; i++) {
1130 counts[i].ahead = 0;
1131 counts[i].behind = 0;
1132 }
1133
1134 ensure_generations_valid(r, commits, commits_nr);
1135
1136 init_bit_arrays(&bit_arrays);
1137
1138 for (size_t i = 0; i < commits_nr; i++) {
1139 struct commit *c = commits[i];
1140 struct bitmap *bitmap = get_bit_array(c, width);
1141
1142 bitmap_set(bitmap, i);
1143 insert_no_dup(&queue, c);
1144 }
1145
1146 while (queue.max_nonstale) {
1147 struct commit *c = nonstale_queue_get(&queue);
1148 struct commit_list *p;
1149 struct bitmap *bitmap_c = get_bit_array(c, width);
1150
1151 for (size_t i = 0; i < counts_nr; i++) {
1152 int reach_from_tip = !!bitmap_get(bitmap_c, counts[i].tip_index);
1153 int reach_from_base = !!bitmap_get(bitmap_c, counts[i].base_index);
1154
1155 if (reach_from_tip ^ reach_from_base) {
1156 if (reach_from_base)
1157 counts[i].behind++;
1158 else
1159 counts[i].ahead++;
1160 }
1161 }
1162
1163 for (p = c->parents; p; p = p->next) {
1164 struct bitmap *bitmap_p;
1165
1166 repo_parse_commit(r, p->item);
1167
1168 bitmap_p = get_bit_array(p->item, width);
1169 bitmap_or(bitmap_p, bitmap_c);
1170
1171 /*
1172 * If this parent is reachable from every starting
1173 * commit, then none of its ancestors can contribute
1174 * to the ahead/behind count. Mark it as STALE, so

Callers 1

filter_ahead_behindFunction · 0.85

Calls 12

ensure_generations_validFunction · 0.85
get_bit_arrayFunction · 0.85
bitmap_setFunction · 0.85
insert_no_dupFunction · 0.85
nonstale_queue_getFunction · 0.85
bitmap_getFunction · 0.85
repo_parse_commitFunction · 0.85
bitmap_orFunction · 0.85
bitmap_popcountFunction · 0.85
free_bit_arrayFunction · 0.85
repo_clear_commit_marksFunction · 0.85
clear_nonstale_queueFunction · 0.85

Tested by

no test coverage detected