FetchRequest.java

  1. /*
  2.  * Copyright (C) 2018, 2022 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> deepenNots;

  28.     @Nullable
  29.     final String agent;

  30.     @Nullable
  31.     final String clientSID;

  32.     /**
  33.      * Initialize the common fields of a fetch request.
  34.      *
  35.      * @param wantIds
  36.      *            list of want ids
  37.      * @param depth
  38.      *            how deep to go in the tree
  39.      * @param clientShallowCommits
  40.      *            commits the client has without history
  41.      * @param filterSpec
  42.      *            the filter spec
  43.      * @param clientCapabilities
  44.      *            capabilities sent in the request
  45.      * @param deepenNots
  46.      *            Requests that the shallow clone/fetch should be cut at these
  47.      *            specific revisions instead of a depth.
  48.      * @param deepenSince
  49.      *            Requests that the shallow clone/fetch should be cut at a
  50.      *            specific time, instead of depth
  51.      * @param agent
  52.      *            agent as reported by the client in the request body
  53.      * @param clientSID
  54.      *            agent as reported by the client in the request body
  55.      */
  56.     FetchRequest(@NonNull Set<ObjectId> wantIds, int depth,
  57.             @NonNull Set<ObjectId> clientShallowCommits,
  58.             @NonNull FilterSpec filterSpec,
  59.             @NonNull Set<String> clientCapabilities, int deepenSince,
  60.             @NonNull List<String> deepenNots, @Nullable String agent,
  61.             @Nullable String clientSID) {
  62.         this.wantIds = requireNonNull(wantIds);
  63.         this.depth = depth;
  64.         this.clientShallowCommits = requireNonNull(clientShallowCommits);
  65.         this.filterSpec = requireNonNull(filterSpec);
  66.         this.clientCapabilities = requireNonNull(clientCapabilities);
  67.         this.deepenSince = deepenSince;
  68.         this.deepenNots = requireNonNull(deepenNots);
  69.         this.agent = agent;
  70.         this.clientSID = clientSID;
  71.     }

  72.     /**
  73.      * @return object ids in the "want" (and "want-ref") lines of the request
  74.      */
  75.     @NonNull
  76.     Set<ObjectId> getWantIds() {
  77.         return wantIds;
  78.     }

  79.     /**
  80.      * @return the depth set in a "deepen" line. 0 by default.
  81.      */
  82.     int getDepth() {
  83.         return depth;
  84.     }

  85.     /**
  86.      * Shallow commits the client already has.
  87.      *
  88.      * These are sent by the client in "shallow" request lines.
  89.      *
  90.      * @return set of commits the client has declared as shallow.
  91.      */
  92.     @NonNull
  93.     Set<ObjectId> getClientShallowCommits() {
  94.         return clientShallowCommits;
  95.     }

  96.     /**
  97.      * @return the filter spec given in a "filter" line
  98.      */
  99.     @NonNull
  100.     FilterSpec getFilterSpec() {
  101.         return filterSpec;
  102.     }

  103.     /**
  104.      * Capabilities that the client wants enabled from the server.
  105.      *
  106.      * Capabilities are options that tune the expected response from the server,
  107.      * like "thin-pack", "no-progress" or "ofs-delta". This list should be a
  108.      * subset of the capabilities announced by the server in its first response.
  109.      *
  110.      * These options are listed and well-defined in the git protocol
  111.      * specification.
  112.      *
  113.      * The agent capability is not included in this set. It can be retrieved via
  114.      * {@link #getAgent()}.
  115.      *
  116.      * @return capabilities sent by the client (excluding the "agent"
  117.      *         capability)
  118.      */
  119.     @NonNull
  120.     Set<String> getClientCapabilities() {
  121.         return clientCapabilities;
  122.     }

  123.     /**
  124.      * The value in a "deepen-since" line in the request, indicating the
  125.      * timestamp where to stop fetching/cloning.
  126.      *
  127.      * @return timestamp in seconds since the epoch, where to stop the shallow
  128.      *         fetch/clone. Defaults to 0 if not set in the request.
  129.      */
  130.     int getDeepenSince() {
  131.         return deepenSince;
  132.     }

  133.     /**
  134.      * @return refs received in "deepen-not" lines.
  135.      */
  136.     @NonNull
  137.     List<String> getDeepenNots() {
  138.         return deepenNots;
  139.     }

  140.     /**
  141.      * @return string identifying the agent (as sent in the request body by the
  142.      *         client)
  143.      */
  144.     @Nullable
  145.     String getAgent() {
  146.         return agent;
  147.     }

  148.     /**
  149.      * @return string identifying the client session ID (as sent in the request body by the
  150.      *         client)
  151.      */
  152.     @Nullable
  153.     String getClientSID() {
  154.         return clientSID;
  155.     }
  156. }