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.

FIFORevQueue.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. import java.io.IOException;
  45. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  46. import org.eclipse.jgit.errors.MissingObjectException;
  47. /** A queue of commits in FIFO order. */
  48. public class FIFORevQueue extends BlockRevQueue {
  49. private Block head;
  50. private Block tail;
  51. /** Create an empty FIFO queue. */
  52. public FIFORevQueue() {
  53. super();
  54. }
  55. FIFORevQueue(final Generator s) throws MissingObjectException,
  56. IncorrectObjectTypeException, IOException {
  57. super(s);
  58. }
  59. public void add(final RevCommit c) {
  60. Block b = tail;
  61. if (b == null) {
  62. b = free.newBlock();
  63. b.add(c);
  64. head = b;
  65. tail = b;
  66. return;
  67. } else if (b.isFull()) {
  68. b = free.newBlock();
  69. tail.next = b;
  70. tail = b;
  71. }
  72. b.add(c);
  73. }
  74. /**
  75. * Insert the commit pointer at the front of the queue.
  76. *
  77. * @param c
  78. * the commit to insert into the queue.
  79. */
  80. public void unpop(final RevCommit c) {
  81. Block b = head;
  82. if (b == null) {
  83. b = free.newBlock();
  84. b.resetToMiddle();
  85. b.add(c);
  86. head = b;
  87. tail = b;
  88. return;
  89. } else if (b.canUnpop()) {
  90. b.unpop(c);
  91. return;
  92. }
  93. b = free.newBlock();
  94. b.resetToEnd();
  95. b.unpop(c);
  96. b.next = head;
  97. head = b;
  98. }
  99. public RevCommit next() {
  100. final Block b = head;
  101. if (b == null)
  102. return null;
  103. final RevCommit c = b.pop();
  104. if (b.isEmpty()) {
  105. head = b.next;
  106. if (head == null)
  107. tail = null;
  108. free.freeBlock(b);
  109. }
  110. return c;
  111. }
  112. public void clear() {
  113. head = null;
  114. tail = null;
  115. free.clear();
  116. }
  117. boolean everbodyHasFlag(final int f) {
  118. for (Block b = head; b != null; b = b.next) {
  119. for (int i = b.headIndex; i < b.tailIndex; i++)
  120. if ((b.commits[i].flags & f) == 0)
  121. return false;
  122. }
  123. return true;
  124. }
  125. boolean anybodyHasFlag(final int f) {
  126. for (Block b = head; b != null; b = b.next) {
  127. for (int i = b.headIndex; i < b.tailIndex; i++)
  128. if ((b.commits[i].flags & f) != 0)
  129. return true;
  130. }
  131. return false;
  132. }
  133. void removeFlag(final int f) {
  134. final int not_f = ~f;
  135. for (Block b = head; b != null; b = b.next) {
  136. for (int i = b.headIndex; i < b.tailIndex; i++)
  137. b.commits[i].flags &= not_f;
  138. }
  139. }
  140. public String toString() {
  141. final StringBuilder s = new StringBuilder();
  142. for (Block q = head; q != null; q = q.next) {
  143. for (int i = q.headIndex; i < q.tailIndex; i++)
  144. describe(s, q.commits[i]);
  145. }
  146. return s.toString();
  147. }
  148. }