Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

StartGenerator.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. package org.eclipse.jgit.revwalk;
  46. import java.io.IOException;
  47. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  48. import org.eclipse.jgit.errors.MissingObjectException;
  49. import org.eclipse.jgit.revwalk.filter.AndRevFilter;
  50. import org.eclipse.jgit.revwalk.filter.RevFilter;
  51. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  52. /**
  53. * Initial RevWalk generator that bootstraps a new walk.
  54. * <p>
  55. * Initially RevWalk starts with this generator as its chosen implementation.
  56. * The first request for a RevCommit from the RevWalk instance calls to our
  57. * {@link #next()} method, and we replace ourselves with the best Generator
  58. * implementation available based upon the current RevWalk configuration.
  59. */
  60. class StartGenerator extends Generator {
  61. private final RevWalk walker;
  62. StartGenerator(final RevWalk w) {
  63. walker = w;
  64. }
  65. @Override
  66. int outputType() {
  67. return 0;
  68. }
  69. @Override
  70. RevCommit next() throws MissingObjectException,
  71. IncorrectObjectTypeException, IOException {
  72. Generator g;
  73. final RevWalk w = walker;
  74. RevFilter rf = w.getRevFilter();
  75. final TreeFilter tf = w.getTreeFilter();
  76. AbstractRevQueue q = walker.queue;
  77. if (rf == RevFilter.MERGE_BASE) {
  78. // Computing for merge bases is a special case and does not
  79. // use the bulk of the generator pipeline.
  80. //
  81. if (tf != TreeFilter.ALL)
  82. throw new IllegalStateException("Cannot combine TreeFilter "
  83. + tf + " with RevFilter " + rf + ".");
  84. final MergeBaseGenerator mbg = new MergeBaseGenerator(w);
  85. walker.pending = mbg;
  86. walker.queue = AbstractRevQueue.EMPTY_QUEUE;
  87. mbg.init(q);
  88. return mbg.next();
  89. }
  90. final boolean uninteresting = q.anybodyHasFlag(RevWalk.UNINTERESTING);
  91. boolean boundary = walker.hasRevSort(RevSort.BOUNDARY);
  92. if (!boundary && walker instanceof ObjectWalk) {
  93. // The object walker requires boundary support to color
  94. // trees and blobs at the boundary uninteresting so it
  95. // does not produce those in the result.
  96. //
  97. boundary = true;
  98. }
  99. if (boundary && !uninteresting) {
  100. // If we were not fed uninteresting commits we will never
  101. // construct a boundary. There is no reason to include the
  102. // extra overhead associated with that in our pipeline.
  103. //
  104. boundary = false;
  105. }
  106. final DateRevQueue pending;
  107. int pendingOutputType = 0;
  108. if (q instanceof DateRevQueue)
  109. pending = (DateRevQueue)q;
  110. else
  111. pending = new DateRevQueue(q);
  112. if (tf != TreeFilter.ALL) {
  113. rf = AndRevFilter.create(rf, new RewriteTreeFilter(w, tf));
  114. pendingOutputType |= HAS_REWRITE | NEEDS_REWRITE;
  115. }
  116. walker.queue = q;
  117. g = new PendingGenerator(w, pending, rf, pendingOutputType);
  118. if (boundary) {
  119. // Because the boundary generator may produce uninteresting
  120. // commits we cannot allow the pending generator to dispose
  121. // of them early.
  122. //
  123. ((PendingGenerator) g).canDispose = false;
  124. }
  125. if ((g.outputType() & NEEDS_REWRITE) != 0) {
  126. // Correction for an upstream NEEDS_REWRITE is to buffer
  127. // fully and then apply a rewrite generator that can
  128. // pull through the rewrite chain and produce a dense
  129. // output graph.
  130. //
  131. g = new FIFORevQueue(g);
  132. g = new RewriteGenerator(g);
  133. }
  134. if (walker.hasRevSort(RevSort.TOPO)
  135. && (g.outputType() & SORT_TOPO) == 0)
  136. g = new TopoSortGenerator(g);
  137. if (walker.hasRevSort(RevSort.REVERSE))
  138. g = new LIFORevQueue(g);
  139. if (boundary)
  140. g = new BoundaryGenerator(w, g);
  141. else if (uninteresting) {
  142. // Try to protect ourselves from uninteresting commits producing
  143. // due to clock skew in the commit time stamps. Delay such that
  144. // we have a chance at coloring enough of the graph correctly,
  145. // and then strip any UNINTERESTING nodes that may have leaked
  146. // through early.
  147. //
  148. if (pending.peek() != null)
  149. g = new DelayRevQueue(g);
  150. g = new FixUninterestingGenerator(g);
  151. }
  152. w.pending = g;
  153. return g.next();
  154. }
  155. }