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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 sorted by commit time order. */
  48. public class DateRevQueue extends AbstractRevQueue {
  49. private Entry head;
  50. private Entry free;
  51. /** Create an empty date queue. */
  52. public DateRevQueue() {
  53. super();
  54. }
  55. DateRevQueue(final Generator s) throws MissingObjectException,
  56. IncorrectObjectTypeException, IOException {
  57. for (;;) {
  58. final RevCommit c = s.next();
  59. if (c == null)
  60. break;
  61. add(c);
  62. }
  63. }
  64. public void add(final RevCommit c) {
  65. Entry q = head;
  66. final long when = c.commitTime;
  67. final Entry n = newEntry(c);
  68. if (q == null || when > q.commit.commitTime) {
  69. n.next = q;
  70. head = n;
  71. } else {
  72. Entry p = q.next;
  73. while (p != null && p.commit.commitTime > when) {
  74. q = p;
  75. p = q.next;
  76. }
  77. n.next = q.next;
  78. q.next = n;
  79. }
  80. }
  81. public RevCommit next() {
  82. final Entry q = head;
  83. if (q == null)
  84. return null;
  85. head = q.next;
  86. freeEntry(q);
  87. return q.commit;
  88. }
  89. /**
  90. * Peek at the next commit, without removing it.
  91. *
  92. * @return the next available commit; null if there are no commits left.
  93. */
  94. public RevCommit peek() {
  95. return head != null ? head.commit : null;
  96. }
  97. public void clear() {
  98. head = null;
  99. free = null;
  100. }
  101. boolean everbodyHasFlag(final int f) {
  102. for (Entry q = head; q != null; q = q.next) {
  103. if ((q.commit.flags & f) == 0)
  104. return false;
  105. }
  106. return true;
  107. }
  108. boolean anybodyHasFlag(final int f) {
  109. for (Entry q = head; q != null; q = q.next) {
  110. if ((q.commit.flags & f) != 0)
  111. return true;
  112. }
  113. return false;
  114. }
  115. @Override
  116. int outputType() {
  117. return outputType | SORT_COMMIT_TIME_DESC;
  118. }
  119. public String toString() {
  120. final StringBuilder s = new StringBuilder();
  121. for (Entry q = head; q != null; q = q.next)
  122. describe(s, q.commit);
  123. return s.toString();
  124. }
  125. private Entry newEntry(final RevCommit c) {
  126. Entry r = free;
  127. if (r == null)
  128. r = new Entry();
  129. else
  130. free = r.next;
  131. r.commit = c;
  132. return r;
  133. }
  134. private void freeEntry(final Entry e) {
  135. e.next = free;
  136. free = e;
  137. }
  138. static class Entry {
  139. Entry next;
  140. RevCommit commit;
  141. }
  142. }