2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org
.spearce
.jgit
.revwalk
;
40 import java
.io
.IOException
;
42 import org
.spearce
.jgit
.errors
.IncorrectObjectTypeException
;
43 import org
.spearce
.jgit
.errors
.MissingObjectException
;
44 import org
.spearce
.jgit
.revwalk
.filter
.AndRevFilter
;
45 import org
.spearce
.jgit
.revwalk
.filter
.RevFilter
;
46 import org
.spearce
.jgit
.treewalk
.filter
.TreeFilter
;
49 * Initial RevWalk generator that bootstraps a new walk.
51 * Initially RevWalk starts with this generator as its chosen implementation.
52 * The first request for a RevCommit from the RevWalk instance calls to our
53 * {@link #next()} method, and we replace ourselves with the best Generator
54 * implementation available based upon the current RevWalk configuration.
56 class StartGenerator
extends Generator
{
57 private final RevWalk walker
;
59 StartGenerator(final RevWalk w
) {
69 RevCommit
next() throws MissingObjectException
,
70 IncorrectObjectTypeException
, IOException
{
73 final RevWalk w
= walker
;
74 RevFilter rf
= w
.getRevFilter();
75 final TreeFilter tf
= w
.getTreeFilter();
76 AbstractRevQueue q
= walker
.queue
;
78 if (rf
== RevFilter
.MERGE_BASE
) {
79 // Computing for merge bases is a special case and does not
80 // use the bulk of the generator pipeline.
82 if (tf
!= TreeFilter
.ALL
)
83 throw new IllegalStateException("Cannot combine TreeFilter "
84 + tf
+ " with RevFilter " + rf
+ ".");
86 final MergeBaseGenerator mbg
= new MergeBaseGenerator(w
);
88 walker
.queue
= AbstractRevQueue
.EMPTY_QUEUE
;
93 boolean boundary
= walker
.hasRevSort(RevSort
.BOUNDARY
);
95 if (!boundary
&& walker
instanceof ObjectWalk
) {
96 // The object walker requires boundary support to color
97 // trees and blobs at the boundary uninteresting so it
98 // does not produce those in the result.
102 if (boundary
&& !q
.anybodyHasFlag(RevWalk
.UNINTERESTING
)) {
103 // If we were not fed uninteresting commits we will never
104 // construct a boundary. There is no reason to include the
105 // extra overhead associated with that in our pipeline.
110 int pendingOutputType
= 0;
111 if (walker
.hasRevSort(RevSort
.START_ORDER
)
112 && !(q
instanceof FIFORevQueue
))
113 q
= new FIFORevQueue(q
);
114 if (walker
.hasRevSort(RevSort
.COMMIT_TIME_DESC
)
115 && !(q
instanceof DateRevQueue
))
116 q
= new DateRevQueue(q
);
117 if (tf
!= TreeFilter
.ALL
) {
118 rf
= AndRevFilter
.create(rf
, new RewriteTreeFilter(w
, tf
));
119 pendingOutputType
|= HAS_REWRITE
| NEEDS_REWRITE
;
123 g
= new PendingGenerator(w
, q
, rf
, pendingOutputType
);
126 // Because the boundary generator may produce uninteresting
127 // commits we cannot allow the pending generator to dispose
130 ((PendingGenerator
) g
).canDispose
= false;
133 if ((g
.outputType() & NEEDS_REWRITE
) != 0) {
134 // Correction for an upstream NEEDS_REWRITE is to buffer
135 // fully and then apply a rewrite generator that can
136 // pull through the rewrite chain and produce a dense
139 g
= new FIFORevQueue(g
);
140 g
= new RewriteGenerator(g
);
143 if (walker
.hasRevSort(RevSort
.TOPO
)
144 && (g
.outputType() & SORT_TOPO
) == 0)
145 g
= new TopoSortGenerator(g
);
146 if (walker
.hasRevSort(RevSort
.REVERSE
))
147 g
= new LIFORevQueue(q
);
149 g
= new BoundaryGenerator(w
, g
);