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 7.7KB

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