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.

FetchRequest.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (C) 2018, Google LLC.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.transport;
  44. import static java.util.Objects.requireNonNull;
  45. import java.util.List;
  46. import java.util.Set;
  47. import org.eclipse.jgit.annotations.NonNull;
  48. import org.eclipse.jgit.annotations.Nullable;
  49. import org.eclipse.jgit.lib.ObjectId;
  50. /**
  51. * Common fields between v0/v1/v2 fetch requests.
  52. */
  53. abstract class FetchRequest {
  54. final Set<ObjectId> wantIds;
  55. final int depth;
  56. final Set<ObjectId> clientShallowCommits;
  57. final FilterSpec filterSpec;
  58. final Set<String> clientCapabilities;
  59. final int deepenSince;
  60. final List<String> deepenNotRefs;
  61. @Nullable
  62. final String agent;
  63. /**
  64. * Initialize the common fields of a fetch request.
  65. *
  66. * @param wantIds
  67. * list of want ids
  68. * @param depth
  69. * how deep to go in the tree
  70. * @param clientShallowCommits
  71. * commits the client has without history
  72. * @param filterSpec
  73. * the filter spec
  74. * @param clientCapabilities
  75. * capabilities sent in the request
  76. * @param deepenNotRefs
  77. * Requests that the shallow clone/fetch should be cut at these
  78. * specific revisions instead of a depth.
  79. * @param deepenSince
  80. * Requests that the shallow clone/fetch should be cut at a
  81. * specific time, instead of depth
  82. * @param agent
  83. * agent as reported by the client in the request body
  84. */
  85. FetchRequest(@NonNull Set<ObjectId> wantIds, int depth,
  86. @NonNull Set<ObjectId> clientShallowCommits,
  87. @NonNull FilterSpec filterSpec,
  88. @NonNull Set<String> clientCapabilities, int deepenSince,
  89. @NonNull List<String> deepenNotRefs, @Nullable String agent) {
  90. this.wantIds = requireNonNull(wantIds);
  91. this.depth = depth;
  92. this.clientShallowCommits = requireNonNull(clientShallowCommits);
  93. this.filterSpec = requireNonNull(filterSpec);
  94. this.clientCapabilities = requireNonNull(clientCapabilities);
  95. this.deepenSince = deepenSince;
  96. this.deepenNotRefs = requireNonNull(deepenNotRefs);
  97. this.agent = agent;
  98. }
  99. /**
  100. * @return object ids in the "want" (and "want-ref") lines of the request
  101. */
  102. @NonNull
  103. Set<ObjectId> getWantIds() {
  104. return wantIds;
  105. }
  106. /**
  107. * @return the depth set in a "deepen" line. 0 by default.
  108. */
  109. int getDepth() {
  110. return depth;
  111. }
  112. /**
  113. * Shallow commits the client already has.
  114. *
  115. * These are sent by the client in "shallow" request lines.
  116. *
  117. * @return set of commits the client has declared as shallow.
  118. */
  119. @NonNull
  120. Set<ObjectId> getClientShallowCommits() {
  121. return clientShallowCommits;
  122. }
  123. /**
  124. * @return the filter spec given in a "filter" line
  125. */
  126. @NonNull
  127. FilterSpec getFilterSpec() {
  128. return filterSpec;
  129. }
  130. /**
  131. * Capabilities that the client wants enabled from the server.
  132. *
  133. * Capabilities are options that tune the expected response from the server,
  134. * like "thin-pack", "no-progress" or "ofs-delta". This list should be a
  135. * subset of the capabilities announced by the server in its first response.
  136. *
  137. * These options are listed and well-defined in the git protocol
  138. * specification.
  139. *
  140. * The agent capability is not included in this set. It can be retrieved via
  141. * {@link #getAgent()}.
  142. *
  143. * @return capabilities sent by the client (excluding the "agent"
  144. * capability)
  145. */
  146. @NonNull
  147. Set<String> getClientCapabilities() {
  148. return clientCapabilities;
  149. }
  150. /**
  151. * The value in a "deepen-since" line in the request, indicating the
  152. * timestamp where to stop fetching/cloning.
  153. *
  154. * @return timestamp in seconds since the epoch, where to stop the shallow
  155. * fetch/clone. Defaults to 0 if not set in the request.
  156. */
  157. int getDeepenSince() {
  158. return deepenSince;
  159. }
  160. /**
  161. * @return refs received in "deepen-not" lines.
  162. */
  163. @NonNull
  164. List<String> getDeepenNotRefs() {
  165. return deepenNotRefs;
  166. }
  167. /**
  168. * @return string identifying the agent (as sent in the request body by the
  169. * client)
  170. */
  171. @Nullable
  172. String getAgent() {
  173. return agent;
  174. }
  175. }