syntax = "proto3";

package mesh.v1;

import "mesh/v1/git_model.proto";
import "mesh/v1/stream.proto";

option go_package = "atlassian.com/bitbucket/mesh/rpc/v1";
option java_multiple_files = true;
option java_outer_classname = "GitPlumbingProtos";
option java_package = "com.atlassian.bitbucket.mesh.rpc.v1";

message RpcCallRequest {
  string repository = 1;
  RpcGitOptions options = 2;
  RpcGitTimeouts timeouts = 3;

  repeated bytes arguments = 10;
  string command = 11;
}

/* A fragment of a request for arbitrary git commands which accept input via stdin. */
message RpcCallStdinFragment {
  oneof request_oneof {
    RpcCallRequest request = 1;
    RpcStreamChunk stdin = 2;
  }
}
message RpcCatFileBatchRequest {
  string repository = 1;
  RpcGitOptions options = 2;
  RpcGitTimeouts timeouts = 3;
}

message RpcCatFilePretty {
  bytes object_id = 1;
}

/* Request for git cat-file [-p|-t] */
message RpcCatFileRequest {
  string repository = 1;
  RpcGitOptions options = 2;
  RpcGitTimeouts timeouts = 3;

  oneof cat_file_oneof {
    RpcCatFilePretty pretty = 10;
    RpcCatFileType type = 11;
  }
}

/* A fragment of a request for git cat-file --batch */
message RpcCatFileStdinFragment {
  oneof request_oneof {
    RpcCatFileBatchRequest request = 1;
    RpcStreamChunk stdin = 2;
  }
}

message RpcCatFileType {
  bool allow_unknown_type = 1;
  bytes object_id = 2;
}

/* Request for git for-each-ref */
message RpcForEachRefRequest {
  string repository = 1;
  RpcGitOptions options = 2;
  RpcGitTimeouts timeouts = 3;

  int32 count = 10;
  string format = 11;
  repeated bytes patterns = 12;
  string sort = 13;
}

/* Request for git ls-tree */
message RpcLsTreeRequest {
  string repository = 1;
  RpcGitOptions options = 2;
  RpcGitTimeouts timeouts = 3;

  bool null_terminated = 10;
  repeated bytes paths = 11;
  bool recursive = 12;
  bool sizes = 13;
  bytes treeish = 14;
}

message RpcPackObjectsStdinFragment {
  oneof request_oneof {
    RpcPackObjectsRequest request = 1;
    RpcStreamChunk stdin = 2;
  }
}

/* Request for git pack-objects --stdout */
message RpcPackObjectsRequest {
  string repository = 1;
  RpcGitOptions options = 2;
  RpcGitTimeouts timeouts = 3;

  bool all = 4;
  bool delta_base_offset = 7;
  //revs can only provided when used with PlumbingService/PackObjects. Providing them on a
  //request fragment in a RpcPackObjectsStdinFragment will result in an error.
  repeated bytes revs = 5;
  bool thin = 6;
}

/* Controls whether rev-list includes merge commits. */
enum RpcRevListMerges {
  MERGES_UNSPECIFIED = 0;
  MERGES_DEFAULT = 1;//This is the default in Bitbucket Server.
  MERGES_EXCLUDE = 2;
  MERGES_INCLUDE = 3;
  MERGES_ONLY = 4;
}

/* Reusable options that are common to rev-list and log. (log accepts every
   option rev-list does, plus some. There are no rev-list options log does
   not accept.) */
message RpcRevListOptions {
  bool all = 1;
  bool branches = 2;
  string format = 3;
  bool ignore_missing = 4;
  int32 limit = 5;
  RpcRevListMerges merges = 6;
  RpcRevListOrder order = 7;
  bool parents = 8;
  repeated bytes paths = 9;
  repeated bytes revs = 10;
  optional int64 since = 14;
  int32 skip = 13;
  bool tags = 11;
  RpcRevListWalk walk = 12;
}

/* Controls the order rev-list returns commits in. */
enum RpcRevListOrder {
  ORDER_UNSPECIFIED = 0;
  ORDER_AUTHOR_DATE = 1;
  ORDER_DEFAULT = 2;
  ORDER_DATE = 3; //This is the default in Bitbucket Server.
  ORDER_TOPOLOGICAL = 4;
}

/* Request for git rev-list. This request is essentially a glorified wrapper for
   RevListOptions, since git log accepts every rev-list option. */
message RpcRevListRequest {
  string repository = 1;
  RpcGitOptions options = 2;
  RpcGitTimeouts timeouts = 3;

  RpcRevListOptions rev_list_options = 10;
}

/* A fragment of a request for git rev-list --stdin. The request is started when the
   RevListRequest is received, which _must_ be the first fragment. After that, stdin
   is provided in chunks, with closed=true on the final one.
   Note: git rev-list will not produce output until stdin is closed, so no response
   fragments will be returned until a stdin chunk with closed=true is received. */
message RpcRevListStdinFragment {
  oneof request_oneof {
    RpcRevListRequest request = 1;
    RpcStreamChunk stdin = 2;
  }
}

/* Controls whether rev-list walks from the included tips, or not. */
enum RpcRevListWalk {
  WALK_UNSPECIFIED = 0;
  WALK_DEFAULT = 1;
  WALK_DO = 2;
  WALK_NO = 3;
  WALK_NO_UNSORTED = 4;
}
