1 /* 2 * Copyright (C) 2008-2009, Google Inc. 3 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com> 4 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> 5 * and other copyright owners as documented in the project's IP log. 6 * 7 * This program and the accompanying materials are made available 8 * under the terms of the Eclipse Distribution License v1.0 which 9 * accompanies this distribution, is reproduced below, and is 10 * available at http://www.eclipse.org/org/documents/edl-v10.php 11 * 12 * All rights reserved. 13 * 14 * Redistribution and use in source and binary forms, with or 15 * without modification, are permitted provided that the following 16 * conditions are met: 17 * 18 * - Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 21 * - Redistributions in binary form must reproduce the above 22 * copyright notice, this list of conditions and the following 23 * disclaimer in the documentation and/or other materials provided 24 * with the distribution. 25 * 26 * - Neither the name of the Eclipse Foundation, Inc. nor the 27 * names of its contributors may be used to endorse or promote 28 * products derived from this software without specific prior 29 * written permission. 30 * 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 32 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 33 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 34 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 36 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 38 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 39 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 43 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 */ 45 46 package org.eclipse.jgit.revwalk; 47 48 import java.io.IOException; 49 import java.text.MessageFormat; 50 51 import org.eclipse.jgit.errors.IncorrectObjectTypeException; 52 import org.eclipse.jgit.errors.MissingObjectException; 53 import org.eclipse.jgit.internal.JGitText; 54 import org.eclipse.jgit.revwalk.filter.AndRevFilter; 55 import org.eclipse.jgit.revwalk.filter.RevFilter; 56 import org.eclipse.jgit.treewalk.filter.TreeFilter; 57 58 /** 59 * Initial RevWalk generator that bootstraps a new walk. 60 * <p> 61 * Initially RevWalk starts with this generator as its chosen implementation. 62 * The first request for a RevCommit from the RevWalk instance calls to our 63 * {@link #next()} method, and we replace ourselves with the best Generator 64 * implementation available based upon the current RevWalk configuration. 65 */ 66 class StartGenerator extends Generator { 67 private final RevWalk walker; 68 69 StartGenerator(RevWalk w) { 70 walker = w; 71 } 72 73 @Override 74 int outputType() { 75 return 0; 76 } 77 78 @Override 79 RevCommit next() throws MissingObjectException, 80 IncorrectObjectTypeException, IOException { 81 Generator g; 82 83 final RevWalk w = walker; 84 RevFilter rf = w.getRevFilter(); 85 final TreeFilter tf = w.getTreeFilter(); 86 AbstractRevQueue q = walker.queue; 87 88 if (rf == RevFilter.MERGE_BASE) { 89 // Computing for merge bases is a special case and does not 90 // use the bulk of the generator pipeline. 91 // 92 if (tf != TreeFilter.ALL) 93 throw new IllegalStateException(MessageFormat.format( 94 JGitText.get().cannotCombineTreeFilterWithRevFilter, tf, rf)); 95 96 final MergeBaseGeneratorerator.html#MergeBaseGenerator">MergeBaseGenerator mbg = new MergeBaseGenerator(w); 97 walker.pending = mbg; 98 walker.queue = AbstractRevQueue.EMPTY_QUEUE; 99 mbg.init(q); 100 return mbg.next(); 101 } 102 103 final boolean uninteresting = q.anybodyHasFlag(RevWalk.UNINTERESTING); 104 boolean boundary = walker.hasRevSort(RevSort.BOUNDARY); 105 106 if (!boundary && walker instanceof ObjectWalk) { 107 // The object walker requires boundary support to color 108 // trees and blobs at the boundary uninteresting so it 109 // does not produce those in the result. 110 // 111 boundary = true; 112 } 113 if (boundary && !uninteresting) { 114 // If we were not fed uninteresting commits we will never 115 // construct a boundary. There is no reason to include the 116 // extra overhead associated with that in our pipeline. 117 // 118 boundary = false; 119 } 120 121 final DateRevQueue pending; 122 int pendingOutputType = 0; 123 if (q instanceof DateRevQueue) 124 pending = (DateRevQueue)q; 125 else 126 pending = new DateRevQueue(q); 127 if (tf != TreeFilter.ALL) { 128 int rewriteFlag; 129 if (w.getRewriteParents()) { 130 pendingOutputType |= HAS_REWRITE | NEEDS_REWRITE; 131 rewriteFlag = RevWalk.REWRITE; 132 } else 133 rewriteFlag = 0; 134 rf = AndRevFilter.create(new TreeRevFilter(w, tf, rewriteFlag), rf); 135 } 136 137 walker.queue = q; 138 139 if (walker instanceof DepthWalk) { 140 DepthWalk dw = (DepthWalk) walker; 141 g = new DepthGenerator(dw, pending); 142 } else { 143 g = new PendingGenerator(w, pending, rf, pendingOutputType); 144 145 if (walker.hasRevSort(RevSort.BOUNDARY)) { 146 // Because the boundary generator may produce uninteresting 147 // commits we cannot allow the pending generator to dispose 148 // of them early. 149 // 150 ((PendingGenerator) g).canDispose = false; 151 } 152 } 153 154 if ((g.outputType() & NEEDS_REWRITE) != 0) { 155 // Correction for an upstream NEEDS_REWRITE is to buffer 156 // fully and then apply a rewrite generator that can 157 // pull through the rewrite chain and produce a dense 158 // output graph. 159 // 160 g = new FIFORevQueue(g); 161 g = new RewriteGenerator(g); 162 } 163 164 if (walker.hasRevSort(RevSort.TOPO) 165 && (g.outputType() & SORT_TOPO) == 0) 166 g = new TopoSortGenerator(g); 167 if (walker.hasRevSort(RevSort.REVERSE)) 168 g = new LIFORevQueue(g); 169 if (boundary) 170 g = new BoundaryGenerator(w, g); 171 else if (uninteresting) { 172 // Try to protect ourselves from uninteresting commits producing 173 // due to clock skew in the commit time stamps. Delay such that 174 // we have a chance at coloring enough of the graph correctly, 175 // and then strip any UNINTERESTING nodes that may have leaked 176 // through early. 177 // 178 if (pending.peek() != null) 179 g = new DelayRevQueue(g); 180 g = new FixUninterestingGenerator(g); 181 } 182 183 w.pending = g; 184 return g.next(); 185 } 186 }