syntax = "proto3";
package rpc;

option go_package = "github.com/harness/gitness/gitrpc/rpc";

import "shared.proto";

// SmartHTTPService is a service that provides RPCs required for HTTP-based Git
// clones via the smart HTTP protocol.
service SmartHTTPService {
  // The response body for GET /info/refs?service=git-upload-pack
  // Will be invoked when the user executes a `git fetch`, meaning the server
  // will upload the packs to that user. The user doesn't upload new objects.
  rpc InfoRefs(InfoRefsRequest) returns (stream InfoRefsResponse) {}

  // ServicePack is just upload-pack or receive-pack
  rpc ServicePack(stream ServicePackRequest) returns (stream ServicePackResponse) {}
}

message InfoRefsRequest {
  // Base specifies the base read parameters
  ReadRequest base = 1;
  // Service can be: upload-pack or receive-pack
  string service = 2;
  // Parameters to use with git -c (key=value pairs)
  repeated string git_config_options = 3;

  // Git protocol version
  string git_protocol = 4;
}

message InfoRefsResponse {
  bytes data = 1;
}

message ServicePackRequest {
  // Base specifies the base parameters.
  // Depending on the service the matching base type has to be passed
  oneof base {
    ReadRequest  read_base  = 1;
    WriteRequest write_base = 2;
  };

  // Service can be: upload-pack or receive-pack
  string service = 3;
  // Raw data to be copied to stdin of 'git upload-pack'
  bytes data = 4;
  // Parameters to use with git -c (key=value pairs)
  repeated string git_config_options = 5;
  // Git protocol version
  string git_protocol = 6;
}

message ServicePackResponse {
  // Raw data from stdout of 'git upload-pack'
  bytes data = 1;
}

