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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2018, 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.transport;
  11. import static java.util.Objects.requireNonNull;
  12. import java.util.List;
  13. import java.util.Set;
  14. import org.eclipse.jgit.annotations.NonNull;
  15. import org.eclipse.jgit.annotations.Nullable;
  16. import org.eclipse.jgit.lib.ObjectId;
  17. /**
  18. * Common fields between v0/v1/v2 fetch requests.
  19. */
  20. abstract class FetchRequest {
  21. final Set<ObjectId> wantIds;
  22. final int depth;
  23. final Set<ObjectId> clientShallowCommits;
  24. final FilterSpec filterSpec;
  25. final Set<String> clientCapabilities;
  26. final int deepenSince;
  27. final List<String> deepenNotRefs;
  28. @Nullable
  29. final String agent;
  30. /**
  31. * Initialize the common fields of a fetch request.
  32. *
  33. * @param wantIds
  34. * list of want ids
  35. * @param depth
  36. * how deep to go in the tree
  37. * @param clientShallowCommits
  38. * commits the client has without history
  39. * @param filterSpec
  40. * the filter spec
  41. * @param clientCapabilities
  42. * capabilities sent in the request
  43. * @param deepenNotRefs
  44. * Requests that the shallow clone/fetch should be cut at these
  45. * specific revisions instead of a depth.
  46. * @param deepenSince
  47. * Requests that the shallow clone/fetch should be cut at a
  48. * specific time, instead of depth
  49. * @param agent
  50. * agent as reported by the client in the request body
  51. */
  52. FetchRequest(@NonNull Set<ObjectId> wantIds, int depth,
  53. @NonNull Set<ObjectId> clientShallowCommits,
  54. @NonNull FilterSpec filterSpec,
  55. @NonNull Set<String> clientCapabilities, int deepenSince,
  56. @NonNull List<String> deepenNotRefs, @Nullable String agent) {
  57. this.wantIds = requireNonNull(wantIds);
  58. this.depth = depth;
  59. this.clientShallowCommits = requireNonNull(clientShallowCommits);
  60. this.filterSpec = requireNonNull(filterSpec);
  61. this.clientCapabilities = requireNonNull(clientCapabilities);
  62. this.deepenSince = deepenSince;
  63. this.deepenNotRefs = requireNonNull(deepenNotRefs);
  64. this.agent = agent;
  65. }
  66. /**
  67. * @return object ids in the "want" (and "want-ref") lines of the request
  68. */
  69. @NonNull
  70. Set<ObjectId> getWantIds() {
  71. return wantIds;
  72. }
  73. /**
  74. * @return the depth set in a "deepen" line. 0 by default.
  75. */
  76. int getDepth() {
  77. return depth;
  78. }
  79. /**
  80. * Shallow commits the client already has.
  81. *
  82. * These are sent by the client in "shallow" request lines.
  83. *
  84. * @return set of commits the client has declared as shallow.
  85. */
  86. @NonNull
  87. Set<ObjectId> getClientShallowCommits() {
  88. return clientShallowCommits;
  89. }
  90. /**
  91. * @return the filter spec given in a "filter" line
  92. */
  93. @NonNull
  94. FilterSpec getFilterSpec() {
  95. return filterSpec;
  96. }
  97. /**
  98. * Capabilities that the client wants enabled from the server.
  99. *
  100. * Capabilities are options that tune the expected response from the server,
  101. * like "thin-pack", "no-progress" or "ofs-delta". This list should be a
  102. * subset of the capabilities announced by the server in its first response.
  103. *
  104. * These options are listed and well-defined in the git protocol
  105. * specification.
  106. *
  107. * The agent capability is not included in this set. It can be retrieved via
  108. * {@link #getAgent()}.
  109. *
  110. * @return capabilities sent by the client (excluding the "agent"
  111. * capability)
  112. */
  113. @NonNull
  114. Set<String> getClientCapabilities() {
  115. return clientCapabilities;
  116. }
  117. /**
  118. * The value in a "deepen-since" line in the request, indicating the
  119. * timestamp where to stop fetching/cloning.
  120. *
  121. * @return timestamp in seconds since the epoch, where to stop the shallow
  122. * fetch/clone. Defaults to 0 if not set in the request.
  123. */
  124. int getDeepenSince() {
  125. return deepenSince;
  126. }
  127. /**
  128. * @return refs received in "deepen-not" lines.
  129. */
  130. @NonNull
  131. List<String> getDeepenNotRefs() {
  132. return deepenNotRefs;
  133. }
  134. /**
  135. * @return string identifying the agent (as sent in the request body by the
  136. * client)
  137. */
  138. @Nullable
  139. String getAgent() {
  140. return agent;
  141. }
  142. }