1 /*
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10
11 package org.eclipse.jgit.revwalk;
12
13 import java.io.IOException;
14
15 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
16 import org.eclipse.jgit.errors.MissingObjectException;
17
18 /**
19 * Produces commits for RevWalk to return to applications.
20 * <p>
21 * Implementations of this basic class provide the real work behind RevWalk.
22 * Conceptually a Generator is an iterator or a queue, it returns commits until
23 * there are no more relevant. Generators may be piped/stacked together to
24 * create a more complex set of operations.
25 *
26 * @see PendingGenerator
27 * @see StartGenerator
28 */
29 abstract class Generator {
30 /** Commits are sorted by commit date and time, descending. */
31 static final int SORT_COMMIT_TIME_DESC = 1 << 0;
32
33 /** Output may have {@link RevWalk#REWRITE} marked on it. */
34 static final int HAS_REWRITE = 1 << 1;
35
36 /** Output needs {@link RewriteGenerator}. */
37 static final int NEEDS_REWRITE = 1 << 2;
38
39 /** Topological ordering is enforced (all children before parents). */
40 static final int SORT_TOPO = 1 << 3;
41
42 /** Output may have {@link RevWalk#UNINTERESTING} marked on it. */
43 static final int HAS_UNINTERESTING = 1 << 4;
44
45 protected final boolean firstParent;
46
47 protected Generator(boolean firstParent) {
48 this.firstParent = firstParent;
49 }
50
51 /**
52 * Connect the supplied queue to this generator's own free list (if any).
53 *
54 * @param q
55 * another FIFO queue that wants to share our queue's free list.
56 */
57 void shareFreeList(BlockRevQueue q) {
58 // Do nothing by default.
59 }
60
61 /**
62 * Obtain flags describing the output behavior of this generator.
63 *
64 * @return one or more of the constants declared in this class, describing
65 * how this generator produces its results.
66 */
67 abstract int outputType();
68
69 /**
70 * Return the next commit to the application, or the next generator.
71 *
72 * @return next available commit; null if no more are to be returned.
73 * @throws MissingObjectException
74 * @throws IncorrectObjectTypeException
75 * @throws IOException
76 */
77 abstract RevCommit next() throws MissingObjectException,
78 IncorrectObjectTypeException, IOException;
79 }