Skip to content

Commit 8dd15d4

Browse files
committed
commit-reach: move min_generation check into paint_queue_get()
Consolidate the min_generation termination condition into paint_queue_get(), alongside the existing stale-entry and side-exhaustion checks. Move last_gen into struct paint_state so that commit_graph_generation() is called exactly once per dequeued commit and the result is shared across all termination checks and the monotonicity BUG assertion. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
1 parent 4506780 commit 8dd15d4

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

commit-reach.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ struct paint_state {
8989
size_t parent1_count;
9090
size_t parent2_count;
9191
size_t mb_candidate_count;
92+
timestamp_t min_generation;
93+
timestamp_t last_gen;
9294
};
9395

9496
static void paint_count_update(struct paint_state *state,
@@ -138,11 +140,23 @@ static void paint_queue_put(struct paint_state *state,
138140
static struct commit *paint_queue_get(struct paint_state *state)
139141
{
140142
struct commit *commit = prio_queue_get(&state->queue);
143+
timestamp_t generation;
141144

142145
if (!commit)
143146
return NULL;
144147

145148
commit->object.flags &= ~ENQUEUED;
149+
generation = commit_graph_generation(commit);
150+
151+
if (state->min_generation && generation > state->last_gen)
152+
BUG("bad generation skip %"PRItime" > %"PRItime" at %s",
153+
generation, state->last_gen,
154+
oid_to_hex(&commit->object.oid));
155+
state->last_gen = generation;
156+
157+
/* generation cutoff */
158+
if (generation < state->min_generation)
159+
return NULL;
146160

147161
if (!state->mb_candidate_count) {
148162
/* only stale entries remain */
@@ -151,7 +165,7 @@ static struct commit *paint_queue_get(struct paint_state *state)
151165

152166
/* one side is exhausted */
153167
if ((!state->parent1_count || !state->parent2_count) &&
154-
commit_graph_generation(commit) < GENERATION_NUMBER_INFINITY)
168+
generation < GENERATION_NUMBER_INFINITY)
155169
return NULL;
156170
}
157171

@@ -177,9 +191,10 @@ static int paint_down_to_common(struct repository *r,
177191
struct commit *commit;
178192
int i;
179193
int steps = 0;
180-
timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
181194
struct commit_list **tail = result;
182195

196+
state.min_generation = min_generation;
197+
state.last_gen = GENERATION_NUMBER_INFINITY;
183198
if (!min_generation && !corrected_commit_dates_enabled(r))
184199
state.queue.compare = compare_commits_by_commit_date;
185200

@@ -196,18 +211,8 @@ static int paint_down_to_common(struct repository *r,
196211
while ((commit = paint_queue_get(&state))) {
197212
struct commit_list *parents;
198213
int flags;
199-
timestamp_t generation = commit_graph_generation(commit);
200214
steps++;
201215

202-
if (min_generation && generation > last_gen)
203-
BUG("bad generation skip %"PRItime" > %"PRItime" at %s",
204-
generation, last_gen,
205-
oid_to_hex(&commit->object.oid));
206-
last_gen = generation;
207-
208-
if (generation < min_generation)
209-
break;
210-
211216
flags = commit->object.flags & (PARENT1 | PARENT2 | STALE);
212217
if (flags == (PARENT1 | PARENT2)) {
213218
if (!(commit->object.flags & RESULT)) {
@@ -219,7 +224,7 @@ static int paint_down_to_common(struct repository *r,
219224
* descendant of this one.
220225
*/
221226
if (!(mb_flags & MERGE_BASE_FIND_ALL) &&
222-
generation < GENERATION_NUMBER_INFINITY)
227+
state.last_gen < GENERATION_NUMBER_INFINITY)
223228
break;
224229
}
225230
/* Mark parents of a found merge stale */

0 commit comments

Comments
 (0)