1 /*
2 * Copyright (C) 2009, Google Inc.
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Distribution License v. 1.0 which is available at
7 * https://www.eclipse.org/org/documents/edl-v10.php.
8 *
9 * SPDX-License-Identifier: BSD-3-Clause
10 */
11
12 package org.eclipse.jgit.revwalk;
13
14 import java.io.IOException;
15
16 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
17 import org.eclipse.jgit.errors.MissingObjectException;
18
19 /**
20 * Delays commits to be at least {@link PendingGenerator#OVER_SCAN} late.
21 * <p>
22 * This helps to "fix up" weird corner cases resulting from clock skew, by
23 * slowing down what we produce to the caller we get a better chance to ensure
24 * PendingGenerator reached back far enough in the graph to correctly mark
25 * commits {@link RevWalk#UNINTERESTING} if necessary.
26 * <p>
27 * This generator should appear before {@link FixUninterestingGenerator} if the
28 * lower level {@link #pending} isn't already fully buffered.
29 */
30 final class DelayRevQueue extends Generator {
31 private static final int OVER_SCAN = PendingGenerator.OVER_SCAN;
32
33 private final Generator pending;
34
35 private final FIFORevQueue delay;
36
37 private int size;
38
39 DelayRevQueue(Generator g) {
40 super(g.firstParent);
41 pending = g;
42 delay = new FIFORevQueue();
43 }
44
45 @Override
46 int outputType() {
47 return pending.outputType();
48 }
49
50 @Override
51 RevCommit next() throws MissingObjectException,
52 IncorrectObjectTypeException, IOException {
53 while (size < OVER_SCAN) {
54 final RevCommit c = pending.next();
55 if (c == null)
56 break;
57 delay.add(c);
58 size++;
59 }
60
61 final RevCommit c = delay.next();
62 if (c == null)
63 return null;
64 size--;
65 return c;
66 }
67 }