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.

AbstractRevQueue.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.revwalk;
  44. abstract class AbstractRevQueue extends Generator {
  45. static final AbstractRevQueue EMPTY_QUEUE = new AlwaysEmptyQueue();
  46. /** Current output flags set for this generator instance. */
  47. int outputType;
  48. /**
  49. * Add a commit to the queue.
  50. * <p>
  51. * This method always adds the commit, even if it is already in the queue or
  52. * previously was in the queue but has already been removed. To control
  53. * queue admission use {@link #add(RevCommit, RevFlag)}.
  54. *
  55. * @param c
  56. * commit to add.
  57. */
  58. public abstract void add(RevCommit c);
  59. /**
  60. * Add a commit if it does not have a flag set yet, then set the flag.
  61. * <p>
  62. * This method permits the application to test if the commit has the given
  63. * flag; if it does not already have the flag than the commit is added to
  64. * the queue and the flag is set. This later will prevent the commit from
  65. * being added twice.
  66. *
  67. * @param c
  68. * commit to add.
  69. * @param queueControl
  70. * flag that controls admission to the queue.
  71. */
  72. public final void add(final RevCommit c, final RevFlag queueControl) {
  73. if (!c.has(queueControl)) {
  74. c.add(queueControl);
  75. add(c);
  76. }
  77. }
  78. /**
  79. * Add a commit's parents if one does not have a flag set yet.
  80. * <p>
  81. * This method permits the application to test if the commit has the given
  82. * flag; if it does not already have the flag than the commit is added to
  83. * the queue and the flag is set. This later will prevent the commit from
  84. * being added twice.
  85. *
  86. * @param c
  87. * commit whose parents should be added.
  88. * @param queueControl
  89. * flag that controls admission to the queue.
  90. */
  91. public final void addParents(final RevCommit c, final RevFlag queueControl) {
  92. final RevCommit[] pList = c.parents;
  93. if (pList == null)
  94. return;
  95. for (RevCommit p : pList)
  96. add(p, queueControl);
  97. }
  98. /**
  99. * Remove the first commit from the queue.
  100. *
  101. * @return the first commit of this queue.
  102. */
  103. public abstract RevCommit next();
  104. /** Remove all entries from this queue. */
  105. public abstract void clear();
  106. abstract boolean everbodyHasFlag(int f);
  107. abstract boolean anybodyHasFlag(int f);
  108. @Override
  109. int outputType() {
  110. return outputType;
  111. }
  112. protected static void describe(final StringBuilder s, final RevCommit c) {
  113. s.append(c.toString());
  114. s.append('\n');
  115. }
  116. private static class AlwaysEmptyQueue extends AbstractRevQueue {
  117. @Override
  118. public void add(RevCommit c) {
  119. throw new UnsupportedOperationException();
  120. }
  121. @Override
  122. public RevCommit next() {
  123. return null;
  124. }
  125. @Override
  126. boolean anybodyHasFlag(int f) {
  127. return false;
  128. }
  129. @Override
  130. boolean everbodyHasFlag(int f) {
  131. return true;
  132. }
  133. @Override
  134. public void clear() {
  135. // Nothing to clear, we have no state.
  136. }
  137. }
  138. }