| Index: go/src/infra/libs/gitiles/commit_diff.go
|
| diff --git a/go/src/infra/libs/gitiles/commit_diff.go b/go/src/infra/libs/gitiles/commit_diff.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..db89b1142b306a09f3e1f83ede65c87c56489289
|
| --- /dev/null
|
| +++ b/go/src/infra/libs/gitiles/commit_diff.go
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +package gitiles
|
| +
|
| +import (
|
| + "strings"
|
| +
|
| + "infra/libs/git"
|
| +)
|
| +
|
| +// GetCommitDiff returns the git.TreeDiff from the given committish.
|
| +func (g *Gitiles) GetCommitDiff(committish string) (git.TreeDiff, error) {
|
| + rslt, err := g.JSON(jsonCommitDiff{}, "+", committish)
|
| + if err != nil {
|
| + return nil, err
|
| + }
|
| + diff := *rslt.(*jsonCommitDiff)
|
| + return diff.ToResult(), nil
|
| +}
|
| +
|
| +func (g *Gitiles) GetTextCommitDiff(id git.ObjectID) (string, error) {
|
| + rslt, err := g.Text("+", id.String()+"^!")
|
| + if err != nil {
|
| + return "", err
|
| + }
|
| + return string(rslt), nil
|
| +}
|
| +
|
| +// private
|
| +
|
| +type jsonCommitDiff struct {
|
| + TreeDiff []struct {
|
| + Type string `json:"type"`
|
| + OldID string `json:"old_id"`
|
| + OldMode git.Mode `json:"old_mode"`
|
| + OldPath string `json:"old_path"`
|
| + NewID string `json:"new_id"`
|
| + NewMode git.Mode `json:"new_mode"`
|
| + NewPath string `json:"new_path"`
|
| + } `json:"tree_diff"`
|
| +}
|
| +
|
| +func (c *jsonCommitDiff) ToResult() git.TreeDiff {
|
| + td := make(git.TreeDiff, 0, len(c.TreeDiff))
|
| + for _, ent := range c.TreeDiff {
|
| + td = append(td, git.TreeDiffEntry{
|
| + Action: strings.ToUpper(ent.Type[:1]),
|
| + Old: git.TreeDiffEntryHalf{
|
| + Child: *git.NewEmptyChild(ent.OldMode, git.MakeObjectID(ent.OldID)),
|
| + Name: ent.OldPath,
|
| + },
|
| + New: git.TreeDiffEntryHalf{
|
| + Child: *git.NewEmptyChild(ent.NewMode, git.MakeObjectID(ent.NewID)),
|
| + Name: ent.NewPath,
|
| + },
|
| + })
|
| + }
|
| + return td
|
| +}
|
|
|