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
12 import java.io.IOException;
13 import java.util.Collection;
14 import java.util.Optional;
15 import java.util.stream.Stream;
16
17 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
18 import org.eclipse.jgit.errors.MissingObjectException;
19
20 /**
21 * Check if a commit is reachable from a collection of starting commits.
22 * <p>
23 * Note that this checks the reachability of commits (and tags). Trees, blobs or
24 * any other object will cause IncorrectObjectTypeException exceptions.
25 *
26 * @since 5.4
27 */
28 public interface ReachabilityChecker {
29
30 /**
31 * Check if all targets are reachable from the {@code starter} commits.
32 * <p>
33 * Caller should parse the objectIds (preferably with
34 * {@code walk.parseCommit()} and handle missing/incorrect type objects
35 * before calling this method.
36 *
37 * @param targets
38 * commits to reach.
39 * @param starters
40 * known starting points.
41 * @return An unreachable target if at least one of the targets is
42 * unreachable. An empty optional if all targets are reachable from
43 * the starters.
44 *
45 * @throws MissingObjectException
46 * if any of the incoming objects doesn't exist in the
47 * repository.
48 * @throws IncorrectObjectTypeException
49 * if any of the incoming objects is not a commit or a tag.
50 * @throws IOException
51 * if any of the underlying indexes or readers can not be
52 * opened.
53 *
54 * @deprecated see {{@link #areAllReachable(Collection, Stream)}
55 */
56 @Deprecated
57 default Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
58 Collection<RevCommit> starters) throws MissingObjectException,
59 IncorrectObjectTypeException, IOException {
60 return areAllReachable(targets, starters.stream());
61 }
62
63 /**
64 * Check if all targets are reachable from the {@code starter} commits.
65 * <p>
66 * Caller should parse the objectIds (preferably with
67 * {@code walk.parseCommit()} and handle missing/incorrect type objects
68 * before calling this method.
69 *
70 * @param targets
71 * commits to reach.
72 * @param starters
73 * known starting points.
74 * @return An unreachable target if at least one of the targets is
75 * unreachable. An empty optional if all targets are reachable from
76 * the starters.
77 *
78 * @throws MissingObjectException
79 * if any of the incoming objects doesn't exist in the
80 * repository.
81 * @throws IncorrectObjectTypeException
82 * if any of the incoming objects is not a commit or a tag.
83 * @throws IOException
84 * if any of the underlying indexes or readers can not be
85 * opened.
86 * @since 5.6
87 */
88 Optional<RevCommit> areAllReachable(Collection<RevCommit> targets,
89 Stream<RevCommit> starters)
90 throws MissingObjectException, IncorrectObjectTypeException,
91 IOException;
92 }