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.

BoundaryGenerator.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2009, Google Inc.
  3. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
  4. *
  5. * This program and the accompanying materials are made available under the
  6. * terms of the Eclipse Distribution License v. 1.0 which is available at
  7. * https://www.eclipse.org/org/documents/edl-v10.php.
  8. *
  9. * SPDX-License-Identifier: BSD-3-Clause
  10. */
  11. package org.eclipse.jgit.revwalk;
  12. import java.io.IOException;
  13. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  14. import org.eclipse.jgit.errors.MissingObjectException;
  15. class BoundaryGenerator extends Generator {
  16. static final int UNINTERESTING = RevWalk.UNINTERESTING;
  17. Generator g;
  18. BoundaryGenerator(RevWalk w, Generator s) {
  19. super(s.firstParent);
  20. g = new InitialGenerator(w, s);
  21. }
  22. @Override
  23. int outputType() {
  24. return g.outputType() | HAS_UNINTERESTING;
  25. }
  26. @Override
  27. void shareFreeList(BlockRevQueue q) {
  28. g.shareFreeList(q);
  29. }
  30. @Override
  31. RevCommit next() throws MissingObjectException,
  32. IncorrectObjectTypeException, IOException {
  33. return g.next();
  34. }
  35. private class InitialGenerator extends Generator {
  36. private static final int PARSED = RevWalk.PARSED;
  37. private static final int DUPLICATE = RevWalk.TEMP_MARK;
  38. private final RevWalk walk;
  39. private final FIFORevQueue held;
  40. private final Generator source;
  41. InitialGenerator(RevWalk w, Generator s) {
  42. super(s.firstParent);
  43. walk = w;
  44. held = new FIFORevQueue(firstParent);
  45. source = s;
  46. source.shareFreeList(held);
  47. }
  48. @Override
  49. int outputType() {
  50. return source.outputType();
  51. }
  52. @Override
  53. void shareFreeList(BlockRevQueue q) {
  54. q.shareFreeList(held);
  55. }
  56. @Override
  57. RevCommit next() throws MissingObjectException,
  58. IncorrectObjectTypeException, IOException {
  59. RevCommit c = source.next();
  60. if (c != null) {
  61. for (int i = 0; i < c.parents.length; i++) {
  62. if (firstParent && i > 0) {
  63. break;
  64. }
  65. RevCommit p = c.parents[i];
  66. if ((p.flags & UNINTERESTING) != 0) {
  67. held.add(p);
  68. }
  69. }
  70. return c;
  71. }
  72. final FIFORevQueue boundary = new FIFORevQueue(firstParent);
  73. boundary.shareFreeList(held);
  74. for (;;) {
  75. c = held.next();
  76. if (c == null)
  77. break;
  78. if ((c.flags & DUPLICATE) != 0)
  79. continue;
  80. if ((c.flags & PARSED) == 0)
  81. c.parseHeaders(walk);
  82. c.flags |= DUPLICATE;
  83. boundary.add(c);
  84. }
  85. boundary.removeFlag(DUPLICATE);
  86. g = boundary;
  87. return boundary.next();
  88. }
  89. }
  90. }