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.

ReachabilityChecker.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2019, Google LLC. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.revwalk;
  11. import java.io.IOException;
  12. import java.util.Collection;
  13. import java.util.Optional;
  14. import java.util.stream.Stream;
  15. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  16. import org.eclipse.jgit.errors.MissingObjectException;
  17. /**
  18. * Check if a commit is reachable from a collection of starting commits.
  19. * <p>
  20. * Note that this checks the reachability of commits (and tags). Trees, blobs or
  21. * any other object will cause IncorrectObjectTypeException exceptions.
  22. *
  23. * @since 5.4
  24. */
  25. public interface ReachabilityChecker {
  26. /**
  27. * Check if all targets are reachable from the {@code starter} commits.
  28. * <p>
  29. * Caller should parse the objectIds (preferably with
  30. * {@code walk.parseCommit()} and handle missing/incorrect type objects
  31. * before calling this method.
  32. *
  33. * @param targets
  34. * commits to reach.
  35. * @param starters
  36. * known starting points.
  37. * @return An unreachable target if at least one of the targets is
  38. * unreachable. An empty optional if all targets are reachable from
  39. * the starters.
  40. *
  41. * @throws MissingObjectException
  42. * if any of the incoming objects doesn't exist in the
  43. * repository.
  44. * @throws IncorrectObjectTypeException
  45. * if any of the incoming objects is not a commit or a tag.
  46. * @throws IOException
  47. * if any of the underlying indexes or readers can not be
  48. * opened.
  49. *
  50. * @deprecated see {{@link #areAllReachable(Collection, Stream)}
  51. */
  52. @Deprecated
  53. default Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
  54. Collection<RevCommit> starters) throws MissingObjectException,
  55. IncorrectObjectTypeException, IOException {
  56. return areAllReachable(targets, starters.stream());
  57. }
  58. /**
  59. * Check if all targets are reachable from the {@code starter} commits.
  60. * <p>
  61. * Caller should parse the objectIds (preferably with
  62. * {@code walk.parseCommit()} and handle missing/incorrect type objects
  63. * before calling this method.
  64. *
  65. * @param targets
  66. * commits to reach.
  67. * @param starters
  68. * known starting points.
  69. * @return An unreachable target if at least one of the targets is
  70. * unreachable. An empty optional if all targets are reachable from
  71. * the starters.
  72. *
  73. * @throws MissingObjectException
  74. * if any of the incoming objects doesn't exist in the
  75. * repository.
  76. * @throws IncorrectObjectTypeException
  77. * if any of the incoming objects is not a commit or a tag.
  78. * @throws IOException
  79. * if any of the underlying indexes or readers can not be
  80. * opened.
  81. * @since 5.6
  82. */
  83. Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
  84. Stream<RevCommit> starters)
  85. throws MissingObjectException, IncorrectObjectTypeException,
  86. IOException;
  87. }