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.

FetchConnection.java 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. package org.eclipse.jgit.transport;
  47. import java.io.OutputStream;
  48. import java.util.Collection;
  49. import java.util.Set;
  50. import org.eclipse.jgit.errors.TransportException;
  51. import org.eclipse.jgit.internal.storage.file.PackLock;
  52. import org.eclipse.jgit.lib.ObjectId;
  53. import org.eclipse.jgit.lib.ProgressMonitor;
  54. import org.eclipse.jgit.lib.Ref;
  55. /**
  56. * Lists known refs from the remote and copies objects of selected refs.
  57. * <p>
  58. * A fetch connection typically connects to the <code>git-upload-pack</code>
  59. * service running where the remote repository is stored. This provides a
  60. * one-way object transfer service to copy objects from the remote repository
  61. * into this local repository.
  62. * <p>
  63. * Instances of a FetchConnection must be created by a
  64. * {@link org.eclipse.jgit.transport.Transport} that implements a specific
  65. * object transfer protocol that both sides of the connection understand.
  66. * <p>
  67. * FetchConnection instances are not thread safe and may be accessed by only one
  68. * thread at a time.
  69. *
  70. * @see Transport
  71. */
  72. public interface FetchConnection extends Connection {
  73. /**
  74. * Fetch objects we don't have but that are reachable from advertised refs.
  75. * <p>
  76. * Only one call per connection is allowed. Subsequent calls will result in
  77. * {@link org.eclipse.jgit.errors.TransportException}.
  78. * </p>
  79. * <p>
  80. * Implementations are free to use network connections as necessary to
  81. * efficiently (for both client and server) transfer objects from the remote
  82. * repository into this repository. When possible implementations should
  83. * avoid replacing/overwriting/duplicating an object already available in
  84. * the local destination repository. Locally available objects and packs
  85. * should always be preferred over remotely available objects and packs.
  86. * {@link org.eclipse.jgit.transport.Transport#isFetchThin()} should be
  87. * honored if applicable.
  88. * </p>
  89. *
  90. * @param monitor
  91. * progress monitor to inform the end-user about the amount of
  92. * work completed, or to indicate cancellation. Implementations
  93. * should poll the monitor at regular intervals to look for
  94. * cancellation requests from the user.
  95. * @param want
  96. * one or more refs advertised by this connection that the caller
  97. * wants to store locally.
  98. * @param have
  99. * additional objects known to exist in the destination
  100. * repository, especially if they aren't yet reachable by the ref
  101. * database. Connections should take this set as an addition to
  102. * what is reachable through all Refs, not in replace of it.
  103. * @throws org.eclipse.jgit.errors.TransportException
  104. * objects could not be copied due to a network failure,
  105. * protocol error, or error on remote side, or connection was
  106. * already used for fetch.
  107. */
  108. void fetch(final ProgressMonitor monitor,
  109. final Collection<Ref> want, final Set<ObjectId> have)
  110. throws TransportException;
  111. /**
  112. * Fetch objects we don't have but that are reachable from advertised refs.
  113. * <p>
  114. * Only one call per connection is allowed. Subsequent calls will result in
  115. * {@link org.eclipse.jgit.errors.TransportException}.
  116. * </p>
  117. * <p>
  118. * Implementations are free to use network connections as necessary to
  119. * efficiently (for both client and server) transfer objects from the remote
  120. * repository into this repository. When possible implementations should
  121. * avoid replacing/overwriting/duplicating an object already available in
  122. * the local destination repository. Locally available objects and packs
  123. * should always be preferred over remotely available objects and packs.
  124. * {@link org.eclipse.jgit.transport.Transport#isFetchThin()} should be
  125. * honored if applicable.
  126. * </p>
  127. *
  128. * @param monitor
  129. * progress monitor to inform the end-user about the amount of
  130. * work completed, or to indicate cancellation. Implementations
  131. * should poll the monitor at regular intervals to look for
  132. * cancellation requests from the user.
  133. * @param want
  134. * one or more refs advertised by this connection that the caller
  135. * wants to store locally.
  136. * @param have
  137. * additional objects known to exist in the destination
  138. * repository, especially if they aren't yet reachable by the ref
  139. * database. Connections should take this set as an addition to
  140. * what is reachable through all Refs, not in replace of it.
  141. * @param out
  142. * OutputStream to write sideband messages to
  143. * @throws org.eclipse.jgit.errors.TransportException
  144. * objects could not be copied due to a network failure,
  145. * protocol error, or error on remote side, or connection was
  146. * already used for fetch.
  147. * @since 3.0
  148. */
  149. void fetch(final ProgressMonitor monitor,
  150. final Collection<Ref> want, final Set<ObjectId> have,
  151. OutputStream out) throws TransportException;
  152. /**
  153. * Did the last {@link #fetch(ProgressMonitor, Collection, Set)} get tags?
  154. * <p>
  155. * Some Git aware transports are able to implicitly grab an annotated tag if
  156. * {@link org.eclipse.jgit.transport.TagOpt#AUTO_FOLLOW} or
  157. * {@link org.eclipse.jgit.transport.TagOpt#FETCH_TAGS} was selected and the
  158. * object the tag peels to (references) was transferred as part of the last
  159. * {@link #fetch(ProgressMonitor, Collection, Set)} call. If it is possible
  160. * for such tags to have been included in the transfer this method returns
  161. * true, allowing the caller to attempt tag discovery.
  162. * <p>
  163. * By returning only true/false (and not the actual list of tags obtained)
  164. * the transport itself does not need to be aware of whether or not tags
  165. * were included in the transfer.
  166. *
  167. * @return true if the last fetch call implicitly included tag objects;
  168. * false if tags were not implicitly obtained.
  169. */
  170. boolean didFetchIncludeTags();
  171. /**
  172. * Did the last {@link #fetch(ProgressMonitor, Collection, Set)} validate
  173. * graph?
  174. * <p>
  175. * Some transports walk the object graph on the client side, with the client
  176. * looking for what objects it is missing and requesting them individually
  177. * from the remote peer. By virtue of completing the fetch call the client
  178. * implicitly tested the object connectivity, as every object in the graph
  179. * was either already local or was requested successfully from the peer. In
  180. * such transports this method returns true.
  181. * <p>
  182. * Some transports assume the remote peer knows the Git object graph and is
  183. * able to supply a fully connected graph to the client (although it may
  184. * only be transferring the parts the client does not yet have). Its faster
  185. * to assume such remote peers are well behaved and send the correct
  186. * response to the client. In such transports this method returns false.
  187. *
  188. * @return true if the last fetch had to perform a connectivity check on the
  189. * client side in order to succeed; false if the last fetch assumed
  190. * the remote peer supplied a complete graph.
  191. */
  192. boolean didFetchTestConnectivity();
  193. /**
  194. * Set the lock message used when holding a pack out of garbage collection.
  195. * <p>
  196. * Callers that set a lock message <b>must</b> ensure they call
  197. * {@link #getPackLocks()} after
  198. * {@link #fetch(ProgressMonitor, Collection, Set)}, even if an exception
  199. * was thrown, and release the locks that are held.
  200. *
  201. * @param message message to use when holding a pack in place.
  202. */
  203. void setPackLockMessage(String message);
  204. /**
  205. * All locks created by the last
  206. * {@link #fetch(ProgressMonitor, Collection, Set)} call.
  207. *
  208. * @return collection (possibly empty) of locks created by the last call to
  209. * fetch. The caller must release these after refs are updated in
  210. * order to safely permit garbage collection.
  211. */
  212. Collection<PackLock> getPackLocks();
  213. }