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.

LsRefsV2Request.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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.ArrayList;
  46. import java.util.Collections;
  47. import java.util.List;
  48. import org.eclipse.jgit.annotations.NonNull;
  49. import org.eclipse.jgit.annotations.Nullable;
  50. /**
  51. * ls-refs protocol v2 request.
  52. *
  53. * <p>
  54. * This is used as an input to {@link ProtocolV2Hook}.
  55. *
  56. * @since 5.1
  57. */
  58. public final class LsRefsV2Request {
  59. private final List<String> refPrefixes;
  60. private final boolean symrefs;
  61. private final boolean peel;
  62. @Nullable
  63. private final String agent;
  64. @NonNull
  65. private final List<String> serverOptions;
  66. private LsRefsV2Request(List<String> refPrefixes, boolean symrefs,
  67. boolean peel, @Nullable String agent,
  68. @NonNull List<String> serverOptions) {
  69. this.refPrefixes = refPrefixes;
  70. this.symrefs = symrefs;
  71. this.peel = peel;
  72. this.agent = agent;
  73. this.serverOptions = requireNonNull(serverOptions);
  74. }
  75. /** @return ref prefixes that the client requested. */
  76. public List<String> getRefPrefixes() {
  77. return refPrefixes;
  78. }
  79. /** @return true if the client requests symbolic references. */
  80. public boolean getSymrefs() {
  81. return symrefs;
  82. }
  83. /** @return true if the client requests tags to be peeled. */
  84. public boolean getPeel() {
  85. return peel;
  86. }
  87. /**
  88. * @return agent as reported by the client
  89. *
  90. * @since 5.2
  91. */
  92. @Nullable
  93. public String getAgent() {
  94. return agent;
  95. }
  96. /**
  97. * Get application-specific options provided by the client using
  98. * --server-option.
  99. * <p>
  100. * It returns just the content, without the "server-option=" prefix. E.g. a
  101. * request with server-option=A and server-option=B lines returns the list
  102. * [A, B].
  103. *
  104. * @return application-specific options from the client as an unmodifiable
  105. * list
  106. *
  107. * @since 5.2
  108. */
  109. @NonNull
  110. public List<String> getServerOptions() {
  111. return serverOptions;
  112. }
  113. /** @return A builder of {@link LsRefsV2Request}. */
  114. public static Builder builder() {
  115. return new Builder();
  116. }
  117. /** A builder for {@link LsRefsV2Request}. */
  118. public static final class Builder {
  119. private List<String> refPrefixes = Collections.emptyList();
  120. private boolean symrefs;
  121. private boolean peel;
  122. private final List<String> serverOptions = new ArrayList<>();
  123. private String agent;
  124. private Builder() {
  125. }
  126. /**
  127. * @param value
  128. * @return the Builder
  129. */
  130. public Builder setRefPrefixes(List<String> value) {
  131. refPrefixes = value;
  132. return this;
  133. }
  134. /**
  135. * @param value
  136. * @return the Builder
  137. */
  138. public Builder setSymrefs(boolean value) {
  139. symrefs = value;
  140. return this;
  141. }
  142. /**
  143. * @param value
  144. * @return the Builder
  145. */
  146. public Builder setPeel(boolean value) {
  147. peel = value;
  148. return this;
  149. }
  150. /**
  151. * Records an application-specific option supplied in a server-option
  152. * line, for later retrieval with
  153. * {@link LsRefsV2Request#getServerOptions}.
  154. *
  155. * @param value
  156. * the client-supplied server-option capability, without
  157. * leading "server-option=".
  158. * @return this builder
  159. * @since 5.2
  160. */
  161. public Builder addServerOption(@NonNull String value) {
  162. serverOptions.add(value);
  163. return this;
  164. }
  165. /**
  166. * Value of an agent line received after the command and before the
  167. * arguments. E.g. "agent=a.b.c/1.0" should set "a.b.c/1.0".
  168. *
  169. * @param value
  170. * the client-supplied agent capability, without leading
  171. * "agent="
  172. * @return this builder
  173. *
  174. * @since 5.2
  175. */
  176. public Builder setAgent(@Nullable String value) {
  177. agent = value;
  178. return this;
  179. }
  180. /** @return LsRefsV2Request */
  181. public LsRefsV2Request build() {
  182. return new LsRefsV2Request(
  183. Collections.unmodifiableList(refPrefixes), symrefs, peel,
  184. agent, Collections.unmodifiableList(serverOptions));
  185. }
  186. }
  187. }