You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StartGenerator.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 java.text.MessageFormat;
  48. import org.eclipse.jgit.JGitText;
  49. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  50. import org.eclipse.jgit.errors.MissingObjectException;
  51. import org.eclipse.jgit.revwalk.filter.AndRevFilter;
  52. import org.eclipse.jgit.revwalk.filter.RevFilter;
  53. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  54. /**
  55. * Initial RevWalk generator that bootstraps a new walk.
  56. * <p>
  57. * Initially RevWalk starts with this generator as its chosen implementation.
  58. * The first request for a RevCommit from the RevWalk instance calls to our
  59. * {@link #next()} method, and we replace ourselves with the best Generator
  60. * implementation available based upon the current RevWalk configuration.
  61. */
  62. class StartGenerator extends Generator {
  63. private final RevWalk walker;
  64. StartGenerator(final RevWalk w) {
  65. walker = w;
  66. }
  67. @Override
  68. int outputType() {
  69. return 0;
  70. }
  71. @Override
  72. RevCommit next() throws MissingObjectException,
  73. IncorrectObjectTypeException, IOException {
  74. Generator g;
  75. final RevWalk w = walker;
  76. RevFilter rf = w.getRevFilter();
  77. final TreeFilter tf = w.getTreeFilter();
  78. AbstractRevQueue q = walker.queue;
  79. w.reader.walkAdviceBeginCommits(w, w.roots);
  80. if (rf == RevFilter.MERGE_BASE) {
  81. // Computing for merge bases is a special case and does not
  82. // use the bulk of the generator pipeline.
  83. //
  84. if (tf != TreeFilter.ALL)
  85. throw new IllegalStateException(MessageFormat.format(
  86. JGitText.get().cannotCombineTreeFilterWithRevFilter, tf, rf));
  87. final MergeBaseGenerator mbg = new MergeBaseGenerator(w);
  88. walker.pending = mbg;
  89. walker.queue = AbstractRevQueue.EMPTY_QUEUE;
  90. mbg.init(q);
  91. return mbg.next();
  92. }
  93. final boolean uninteresting = q.anybodyHasFlag(RevWalk.UNINTERESTING);
  94. 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.
  99. //
  100. boundary = true;
  101. }
  102. if (boundary && !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.
  106. //
  107. boundary = false;
  108. }
  109. final DateRevQueue pending;
  110. int pendingOutputType = 0;
  111. if (q instanceof DateRevQueue)
  112. pending = (DateRevQueue)q;
  113. else
  114. pending = new DateRevQueue(q);
  115. if (tf != TreeFilter.ALL) {
  116. rf = AndRevFilter.create(rf, new RewriteTreeFilter(w, tf));
  117. pendingOutputType |= HAS_REWRITE | NEEDS_REWRITE;
  118. }
  119. walker.queue = q;
  120. if (walker instanceof DepthWalk) {
  121. DepthWalk dw = (DepthWalk) walker;
  122. g = new DepthGenerator(dw, pending);
  123. } else {
  124. g = new PendingGenerator(w, pending, rf, pendingOutputType);
  125. if (boundary) {
  126. // Because the boundary generator may produce uninteresting
  127. // commits we cannot allow the pending generator to dispose
  128. // of them early.
  129. //
  130. ((PendingGenerator) g).canDispose = false;
  131. }
  132. }
  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
  137. // output graph.
  138. //
  139. g = new FIFORevQueue(g);
  140. g = new RewriteGenerator(g);
  141. }
  142. if (walker.hasRevSort(RevSort.TOPO)
  143. && (g.outputType() & SORT_TOPO) == 0)
  144. g = new TopoSortGenerator(g);
  145. if (walker.hasRevSort(RevSort.REVERSE))
  146. g = new LIFORevQueue(g);
  147. if (boundary)
  148. g = new BoundaryGenerator(w, g);
  149. else if (uninteresting) {
  150. // Try to protect ourselves from uninteresting commits producing
  151. // due to clock skew in the commit time stamps. Delay such that
  152. // we have a chance at coloring enough of the graph correctly,
  153. // and then strip any UNINTERESTING nodes that may have leaked
  154. // through early.
  155. //
  156. if (pending.peek() != null)
  157. g = new DelayRevQueue(g);
  158. g = new FixUninterestingGenerator(g);
  159. }
  160. w.pending = g;
  161. return g.next();
  162. }
  163. }