// Copyright 2017 The LUCI 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
//
//      http://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";

import "google/protobuf/timestamp.proto";

package git;

option go_package = "go.chromium.org/luci/common/proto/git";

// Commit is a single parsed commit as represented in a git log or git show
// expression.
message Commit {
  // The hex sha1 of the commit.
  string id = 1;

  // The hex sha1 of the tree for this commit.
  string tree = 2;

  // The hex sha1's of each of this commits' parents.
  repeated string parents = 3;

  // User represents the (name, email, timestamp) Commit header for author and/or
  // commtter.
  message User {
    string name = 1;
    string email = 2;
    google.protobuf.Timestamp time = 3;
  }

  User author = 4;
  User committer = 5;

  // This is the entire unaltered message body.
  string message = 6;

  // Each TreeDiff represents a single file that's changed between this commit
  // and the "previous" commit, where "previous" depends on the context of how
  // this Commit object was produced (i.e. the specific `git log` invocation, or
  // similar command).
  //
  // Note that these are an artifact of the `git log` expression, not of the
  // commit itself (since git log has different ways that it could sort the
  // commits in the log, and thus different ways it could calculate these
  // diffs). In particular, you should avoid caching the TreeDiff data using
  // only the Commit.id as the key.
  //
  // The old_* fields correspond to the matching file in the previous commit (in
  // the case of COPY/DELETE/MODIFY/RENAME), telling its blob hash, file mode
  // and path name.
  //
  // The new_* fields correspond to the matching file in this commit (in the
  // case of ADD/COPY/MODIFY/RENAME), telling its blob hash, file mode and path
  // name.
  message TreeDiff {
    enum ChangeType {
      ADD = 0;
      COPY = 1;
      DELETE = 2;
      MODIFY = 3;
      RENAME = 4;
    }

    // How this file changed.
    ChangeType type = 1;

    string old_id = 2;
    uint32 old_mode = 3;
    string old_path = 4;

    string new_id = 5;
    uint32 new_mode = 6;
    string new_path = 7;
  }
  repeated TreeDiff tree_diff = 7;
}
