syntax = "proto3";

package mesh.v1;

import "google/protobuf/timestamp.proto";

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

/* Attributes that describe an annotated git tag */
message RpcAnnotatedTag {
  bytes message = 1;
  RpcTag tag = 2;
  RpcPerson tagger = 3;
  //@since 2.2
  optional google.protobuf.Timestamp tagger_timestamp = 4;
}

/* Attributes that describe a git branch */
message RpcBranch {
  bytes id = 1;
  bool default = 3;
  string latest_commit = 2;
}

/* Attributes that describe a single change made by a git commit */
message RpcChange {
  string content_id = 2;
  optional bool executable = 3;
  string from_content_id = 4;
  RpcNodeType node_type = 5;
  bytes path = 6;
  optional uint32 percent_unchanged = 7;
  optional bool src_executable = 8;
  optional bytes src_path = 9;
  RpcChangeType type = 10;
}

enum RpcChangeType {
  CHANGE_TYPE_UNSPECIFIED = 0;
  CHANGE_TYPE_ADD = 1;
  CHANGE_TYPE_COPY = 2;
  CHANGE_TYPE_DELETE = 3;
  CHANGE_TYPE_MODIFY = 4;
  CHANGE_TYPE_RENAME = 5;
  CHANGE_TYPE_TYPE = 6;
  CHANGE_TYPE_UNKNOWN = 7;
  CHANGE_TYPE_UNMERGED = 8;
}

/* Attributes that describe a git commit */
message RpcCommit {
  string id = 1;

  RpcPerson author = 2;
  int64 author_epoch = 3;
  RpcPerson committer = 4;
  int64 committer_epoch = 5;
  optional bytes message = 6;

  repeated string parents = 7;
}

message RpcDirectory {
  string content_id = 1;
  bytes path = 2;
}

message RpcFile {
  string content_id = 1;
  bytes path = 2;
  //File-specific properties
  bool executable = 3;
  optional uint64 size = 4;
}

message RpcGitObjectInfo {
  bytes object_id = 1;
  uint64 size = 2;
  RpcGitObjectType type = 3;
}

/* The object types Git supports. */
enum RpcGitObjectType {
  OBJECT_UNSPECIFIED = 0;
  OBJECT_BLOB = 1;
  OBJECT_COMMIT = 2;
  OBJECT_TAG = 3;
  OBJECT_TREE = 4;
}

/* General options, applicable to most if not all git operations. */
message RpcGitOptions {
  repeated string alternates = 1;
  map<string, bytes> config = 2;
  map<string, bytes> environment = 3;
}

/* Timeouts for git operations, allowing callers to specify how long processes may run. */
message RpcGitTimeouts {
  //The overall execution timeout in seconds, which limits process duration regardless of whether it is
  //consuming input or producing output.
  uint64 execution = 1;
  //The idle timeout in seconds, which limits how long a process can run without consuming any input or
  //producing any output.
  uint64 idle = 2;
}

/* Chunk of data written by a hook */
message RpcHookChunk {
  enum Channel {
    CHANNEL_UNSPECIFIED = 0;
    CHANNEL_STDERR = 1;
    CHANNEL_STDOUT = 2;
  }

  Channel channel = 1;
  bytes data = 2;
  optional sint32 exit_code = 3;
}

/* The result of a hook invocation */
enum RpcHookResult {
  HOOK_RESULT_UNSPECIFIED = 0;
  HOOK_RESULT_ACCEPTED = 1;
  HOOK_RESULT_REJECTED = 2;
  HOOK_RESULT_NOT_CALLED = 3;
}

/* Summary for a git merge conflict. */
message RpcMergeConflict {
  string message = 1;
  repeated string more_messages = 2;
}

message RpcMergeConflicts {
  repeated bytes binary_paths = 1;
  repeated RpcMergeConflict conflicts = 2;
  string from_commit_id = 3;
}

/* The minimal revision data for a commit */
message RpcMinimalCommit {
  string id = 1;
  repeated string parents = 2;
}

/* Enumerates possible node types. */
enum RpcNodeType {
  NODE_UNSPECIFIED = 0;
  NODE_DIRECTORY = 1;
  NODE_FILE = 2;
  NODE_SUBMODULE = 3;
}

message RpcOsFile {
  google.protobuf.Timestamp last_modified = 1;
  bytes path = 2;
  uint64 size = 3;
}

/* An author/committer/tagger identity, which is comprised of an email address and a name */
message RpcPerson {
  string email = 1;
  bytes name = 2;
}

message RpcProgressUpdate {
  int32 percentage = 1;
  string message = 2;
}

/* Provides information about the quarantine environment, which is active during pushes and used
   to separate received-but-unverified objects from those already in a repository. */
message RpcQuarantineEnvironment {
  //The repository the quarantine environment applies to. This is used to determine whether
  //to apply the environment depending on what repository the request is executing for
  string repository = 1;

  string alternate_object_dirs = 2;
  string object_dir = 3;
  string quarantine_path = 4;
}

message RpcRef {
  bytes id = 1;
  string object_id = 2;
}

enum RpcRefType {
  REF_UNSPECIFIED = 0;
  REF_TAG = 1;
  REF_BRANCH = 2;
}

message RpcRefUpdate {
  bytes ref_id = 1;
  string old_hash = 2;
  string new_hash = 3;
}

message RpcSubmodule {
  string content_id = 1;
  bytes path = 2;
  //Submodule-specific properties
  bool active = 10;
  bytes branch = 11;
  string url = 12;
}

/* Attributes that describe a git tag */
message RpcTag {
  bytes id = 1;
  string latest_commit = 2;
  string hash = 3;
}

enum RpcTagType {
  TAG_UNSPECIFIED = 0;
  TAG_ANNOTATED = 1;
  TAG_LIGHTWEIGHT = 2;
}
