syntax = "proto3";

package gitaly;

option go_package = "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb";

import "shared.proto";

service BlobService {
  // GetBlob returns the contents of a blob object referenced by its object
  // ID. We use a stream to return a chunked arbitrarily large binary
  // response
  rpc GetBlob(GetBlobRequest) returns (stream GetBlobResponse) {
    option (op_type).op = ACCESSOR;
  }
  rpc GetBlobs(GetBlobsRequest) returns (stream GetBlobsResponse) {
    option (op_type).op = ACCESSOR;
  }
  rpc GetLFSPointers(GetLFSPointersRequest) returns (stream GetLFSPointersResponse) {
    option (op_type).op = ACCESSOR;
  }
  rpc GetNewLFSPointers(GetNewLFSPointersRequest) returns (stream GetNewLFSPointersResponse) {
    option (op_type).op = ACCESSOR;
  }
  rpc GetAllLFSPointers(GetAllLFSPointersRequest) returns (stream GetAllLFSPointersResponse) {
    option (op_type).op = ACCESSOR;
  }
}

message GetBlobRequest {

  Repository repository = 1;
  // Object ID (SHA1) of the blob we want to get
  string oid = 2;
  // Maximum number of bytes we want to receive. Use '-1' to get the full blob no matter how big.
  int64 limit = 3;
}

message GetBlobResponse {
  // Blob size; present only in first response message
  int64 size = 1;
  // Chunk of blob data
  bytes data = 2;
  // Object ID of the actual blob returned. Empty if no blob was found.
  string oid = 3;
}

message GetBlobsRequest {

  message RevisionPath {
    string revision = 1;
    bytes path = 2;
  }

  Repository repository = 1;
  // Revision/Path pairs of the blobs we want to get.
  repeated RevisionPath revision_paths = 2;
  // Maximum number of bytes we want to receive. Use '-1' to get the full blobs no matter how big.
  int64 limit = 3;
}

message GetBlobsResponse {
  // Blob size; present only on the first message per blob
  int64 size = 1;
  // Chunk of blob data, could span over multiple messages.
  bytes data = 2;
  // Object ID of the current blob. Only present on the first message per blob. Empty if no blob was found.
  string oid = 3;
  bool is_submodule = 4;
  int32 mode = 5;
  string revision = 6;
  bytes path = 7;
}

message LFSPointer {
  int64 size = 1;
  bytes data = 2;
  string oid = 3;
}

message NewBlobObject {
  int64 size = 1;
  string oid = 2;
  bytes path = 3;
}

message GetLFSPointersRequest {

  Repository repository = 1;
  repeated string blob_ids = 2;
}

message GetLFSPointersResponse {
  repeated LFSPointer lfs_pointers = 1;
}

message GetNewLFSPointersRequest {

  Repository repository = 1;
  bytes revision = 2;
  int32 limit = 3;
  // Note: When `not_in_all` is true, `not_in_refs` is ignored
  bool not_in_all = 4;
  repeated bytes not_in_refs = 5;
}

message GetNewLFSPointersResponse {
  repeated LFSPointer lfs_pointers = 1;
}

message GetAllLFSPointersRequest {
  Repository repository = 1;
  bytes revision = 2;
}

message GetAllLFSPointersResponse {
  repeated LFSPointer lfs_pointers = 1;
}
