1 /*
2 * Copyright (C) 2008-2009, Google Inc.
3 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
4 * Copyright (C) 2008, Mike Ralphson <mike@abacus.co.uk>
5 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * and other copyright owners as documented in the project's IP log.
7 *
8 * This program and the accompanying materials are made available
9 * under the terms of the Eclipse Distribution License v1.0 which
10 * accompanies this distribution, is reproduced below, and is
11 * available at http://www.eclipse.org/org/documents/edl-v10.php
12 *
13 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or
16 * without modification, are permitted provided that the following
17 * conditions are met:
18 *
19 * - Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials provided
25 * with the distribution.
26 *
27 * - Neither the name of the Eclipse Foundation, Inc. nor the
28 * names of its contributors may be used to endorse or promote
29 * products derived from this software without specific prior
30 * written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
33 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
34 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
39 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
44 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 */
46
47 package org.eclipse.jgit.transport;
48
49 import java.io.OutputStream;
50 import java.util.Collection;
51 import java.util.Set;
52
53 import org.eclipse.jgit.errors.TransportException;
54 import org.eclipse.jgit.internal.storage.file.PackLock;
55 import org.eclipse.jgit.lib.ObjectId;
56 import org.eclipse.jgit.lib.ProgressMonitor;
57 import org.eclipse.jgit.lib.Ref;
58
59 /**
60 * Lists known refs from the remote and copies objects of selected refs.
61 * <p>
62 * A fetch connection typically connects to the <code>git-upload-pack</code>
63 * service running where the remote repository is stored. This provides a
64 * one-way object transfer service to copy objects from the remote repository
65 * into this local repository.
66 * <p>
67 * Instances of a FetchConnection must be created by a {@link Transport} that
68 * implements a specific object transfer protocol that both sides of the
69 * connection understand.
70 * <p>
71 * FetchConnection instances are not thread safe and may be accessed by only one
72 * thread at a time.
73 *
74 * @see Transport
75 */
76 public interface FetchConnection extends Connection {
77 /**
78 * Fetch objects we don't have but that are reachable from advertised refs.
79 * <p>
80 * Only one call per connection is allowed. Subsequent calls will result in
81 * {@link TransportException}.
82 * </p>
83 * <p>
84 * Implementations are free to use network connections as necessary to
85 * efficiently (for both client and server) transfer objects from the remote
86 * repository into this repository. When possible implementations should
87 * avoid replacing/overwriting/duplicating an object already available in
88 * the local destination repository. Locally available objects and packs
89 * should always be preferred over remotely available objects and packs.
90 * {@link Transport#isFetchThin()} should be honored if applicable.
91 * </p>
92 *
93 * @param monitor
94 * progress monitor to inform the end-user about the amount of
95 * work completed, or to indicate cancellation. Implementations
96 * should poll the monitor at regular intervals to look for
97 * cancellation requests from the user.
98 * @param want
99 * one or more refs advertised by this connection that the caller
100 * wants to store locally.
101 * @param have
102 * additional objects known to exist in the destination
103 * repository, especially if they aren't yet reachable by the ref
104 * database. Connections should take this set as an addition to
105 * what is reachable through all Refs, not in replace of it.
106 * @throws TransportException
107 * objects could not be copied due to a network failure,
108 * protocol error, or error on remote side, or connection was
109 * already used for fetch.
110 */
111 public void fetch(final ProgressMonitor monitor,
112 final Collection<Ref> want, final Set<ObjectId> have)
113 throws TransportException;
114
115 /**
116 * Fetch objects we don't have but that are reachable from advertised refs.
117 * <p>
118 * Only one call per connection is allowed. Subsequent calls will result in
119 * {@link TransportException}.
120 * </p>
121 * <p>
122 * Implementations are free to use network connections as necessary to
123 * efficiently (for both client and server) transfer objects from the remote
124 * repository into this repository. When possible implementations should
125 * avoid replacing/overwriting/duplicating an object already available in
126 * the local destination repository. Locally available objects and packs
127 * should always be preferred over remotely available objects and packs.
128 * {@link Transport#isFetchThin()} should be honored if applicable.
129 * </p>
130 *
131 * @param monitor
132 * progress monitor to inform the end-user about the amount of
133 * work completed, or to indicate cancellation. Implementations
134 * should poll the monitor at regular intervals to look for
135 * cancellation requests from the user.
136 * @param want
137 * one or more refs advertised by this connection that the caller
138 * wants to store locally.
139 * @param have
140 * additional objects known to exist in the destination
141 * repository, especially if they aren't yet reachable by the ref
142 * database. Connections should take this set as an addition to
143 * what is reachable through all Refs, not in replace of it.
144 * @param out
145 * OutputStream to write sideband messages to
146 * @throws TransportException
147 * objects could not be copied due to a network failure,
148 * protocol error, or error on remote side, or connection was
149 * already used for fetch.
150 * @since 3.0
151 */
152 public void fetch(final ProgressMonitor monitor,
153 final Collection<Ref> want, final Set<ObjectId> have,
154 OutputStream out) throws TransportException;
155
156 /**
157 * Did the last {@link #fetch(ProgressMonitor, Collection, Set)} get tags?
158 * <p>
159 * Some Git aware transports are able to implicitly grab an annotated tag if
160 * {@link TagOpt#AUTO_FOLLOW} or {@link TagOpt#FETCH_TAGS} was selected and
161 * the object the tag peels to (references) was transferred as part of the
162 * last {@link #fetch(ProgressMonitor, Collection, Set)} call. If it is
163 * possible for such tags to have been included in the transfer this method
164 * returns true, allowing the caller to attempt tag discovery.
165 * <p>
166 * By returning only true/false (and not the actual list of tags obtained)
167 * the transport itself does not need to be aware of whether or not tags
168 * were included in the transfer.
169 *
170 * @return true if the last fetch call implicitly included tag objects;
171 * false if tags were not implicitly obtained.
172 */
173 public boolean didFetchIncludeTags();
174
175 /**
176 * Did the last {@link #fetch(ProgressMonitor, Collection, Set)} validate
177 * graph?
178 * <p>
179 * Some transports walk the object graph on the client side, with the client
180 * looking for what objects it is missing and requesting them individually
181 * from the remote peer. By virtue of completing the fetch call the client
182 * implicitly tested the object connectivity, as every object in the graph
183 * was either already local or was requested successfully from the peer. In
184 * such transports this method returns true.
185 * <p>
186 * Some transports assume the remote peer knows the Git object graph and is
187 * able to supply a fully connected graph to the client (although it may
188 * only be transferring the parts the client does not yet have). Its faster
189 * to assume such remote peers are well behaved and send the correct
190 * response to the client. In such transports this method returns false.
191 *
192 * @return true if the last fetch had to perform a connectivity check on the
193 * client side in order to succeed; false if the last fetch assumed
194 * the remote peer supplied a complete graph.
195 */
196 public boolean didFetchTestConnectivity();
197
198 /**
199 * Set the lock message used when holding a pack out of garbage collection.
200 * <p>
201 * Callers that set a lock message <b>must</b> ensure they call
202 * {@link #getPackLocks()} after
203 * {@link #fetch(ProgressMonitor, Collection, Set)}, even if an exception
204 * was thrown, and release the locks that are held.
205 *
206 * @param message message to use when holding a pack in place.
207 */
208 public void setPackLockMessage(String message);
209
210 /**
211 * All locks created by the last
212 * {@link #fetch(ProgressMonitor, Collection, Set)} call.
213 *
214 * @return collection (possibly empty) of locks created by the last call to
215 * fetch. The caller must release these after refs are updated in
216 * order to safely permit garbage collection.
217 */
218 public Collection<PackLock> getPackLocks();
219 }