FetchV0Request.java

  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.Collection;
  13. import java.util.Collections;
  14. import java.util.HashSet;
  15. import java.util.Set;

  16. import org.eclipse.jgit.annotations.NonNull;
  17. import org.eclipse.jgit.annotations.Nullable;
  18. import org.eclipse.jgit.lib.ObjectId;

  19. /**
  20.  * Fetch request in the V0/V1 protocol.
  21.  */
  22. final class FetchV0Request extends FetchRequest {

  23.     FetchV0Request(@NonNull Set<ObjectId> wantIds, int depth,
  24.             @NonNull Set<ObjectId> clientShallowCommits,
  25.             @NonNull FilterSpec filterSpec,
  26.             @NonNull Set<String> clientCapabilities, @Nullable String agent) {
  27.         super(wantIds, depth, clientShallowCommits, filterSpec,
  28.                 clientCapabilities, 0, Collections.emptyList(), agent);
  29.     }

  30.     static final class Builder {

  31.         int depth;

  32.         final Set<ObjectId> wantIds = new HashSet<>();

  33.         final Set<ObjectId> clientShallowCommits = new HashSet<>();

  34.         FilterSpec filterSpec = FilterSpec.NO_FILTER;

  35.         final Set<String> clientCaps = new HashSet<>();

  36.         String agent;

  37.         /**
  38.          * @param objectId
  39.          *            object id received in a "want" line
  40.          * @return this builder
  41.          */
  42.         Builder addWantId(ObjectId objectId) {
  43.             wantIds.add(objectId);
  44.             return this;
  45.         }

  46.         /**
  47.          * @param d
  48.          *            depth set in a "deepen" line
  49.          * @return this builder
  50.          */
  51.         Builder setDepth(int d) {
  52.             depth = d;
  53.             return this;
  54.         }

  55.         /**
  56.          * @param shallowOid
  57.          *            object id received in a "shallow" line
  58.          * @return this builder
  59.          */
  60.         Builder addClientShallowCommit(ObjectId shallowOid) {
  61.             clientShallowCommits.add(shallowOid);
  62.             return this;
  63.         }

  64.         /**
  65.          * @param clientCapabilities
  66.          *            client capabilities sent by the client in the first want
  67.          *            line of the request
  68.          * @return this builder
  69.          */
  70.         Builder addClientCapabilities(Collection<String> clientCapabilities) {
  71.             clientCaps.addAll(clientCapabilities);
  72.             return this;
  73.         }

  74.         /**
  75.          * @param clientAgent
  76.          *            agent line sent by the client in the request body
  77.          * @return this builder
  78.          */
  79.         Builder setAgent(String clientAgent) {
  80.             agent = clientAgent;
  81.             return this;
  82.         }

  83.         /**
  84.          * @param filter
  85.          *            the filter set in a filter line
  86.          * @return this builder
  87.          */
  88.         Builder setFilterSpec(@NonNull FilterSpec filter) {
  89.             filterSpec = requireNonNull(filter);
  90.             return this;
  91.         }

  92.         FetchV0Request build() {
  93.             return new FetchV0Request(wantIds, depth, clientShallowCommits,
  94.                     filterSpec, clientCaps, agent);
  95.         }

  96.     }
  97. }