// Copyright 2020 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package local_working_copy;

enum FileType {
  Normal = 0;
  Symlink = 1;
  Executable = 2;
  Conflict = 3 [deprecated = true];
  GitSubmodule = 4;
}

message MaterializedConflictData {
  // TODO: maybe we should store num_sides here as well
  uint32 conflict_marker_len = 1;
}

message FileState {
  int64 mtime_millis_since_epoch = 1;
  uint64 size = 2;
  FileType file_type = 3;
  MaterializedConflictData materialized_conflict_data = 5;
  reserved 4;
}

message FileStateEntry {
  string path = 1;
  FileState state = 2;
}

message SparsePatterns {
  repeated string prefixes = 1;
}

message TreeState {
  bytes legacy_tree_id = 1 [deprecated = true];
  // Alternating positive and negative terms if there's a conflict, otherwise a
  // single (positive) value
  repeated bytes tree_ids = 5;
  // Labels for the terms of a conflict.
  repeated string conflict_labels = 7;
  repeated FileStateEntry file_states = 2;
  bool is_file_states_sorted = 6;
  SparsePatterns sparse_patterns = 3;
  WatchmanClock watchman_clock = 4;
}

message WatchmanClock {
  oneof watchman_clock {
    string string_clock = 1;
    int64 unix_timestamp = 2;
  }
}

message Checkout {
  // The operation at which the working copy was updated.
  bytes operation_id = 2;
  // An identifier for this workspace. It is used for looking up the current
  // working-copy commit in the repo view. Currently a human-readable name.
  // TODO: Is it better to make this a UUID and a have map that to a name in
  // config? That way users can rename a workspace.
  string workspace_name = 3;
  reserved 1;
}
