| 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..87b17b0094a812e96d6309004d5f30c0bf9f2c5a
|
| --- /dev/null
|
| +++ b/go/src/infra/libs/gitiles/commit_diff.go
|
| @@ -0,0 +1,66 @@
|
| +package gitiles
|
| +
|
| +import "strings"
|
| +
|
| +import "infra/libs/git"
|
| +
|
| +// CommitDiffResult contains a git.TreeDiff, or an error.
|
| +type CommitDiffResult struct {
|
| + Err error
|
| + Diff git.TreeDiff
|
| +}
|
| +
|
| +type TextCommitDiffResult struct {
|
| + Err error
|
| + Diff []string
|
| +}
|
| +
|
| +// GetCommitDiff returns the CommitDiffResult from the given committish.
|
| +func (g *Gitiles) GetCommitDiff(committish string) CommitDiffResult {
|
| + rslt := <-g.JSON(jsonCommitDiff{}, "+", committish)
|
| + if rslt.Err != nil {
|
| + return CommitDiffResult{Err: rslt.Err}
|
| + }
|
| + diff := *rslt.DataPtr.(*jsonCommitDiff)
|
| + return diff.ToResult()
|
| +}
|
| +
|
| +func (g *Gitiles) GetTextCommitDiff(id git.ObjectID) TextCommitDiffResult {
|
| + rslt := <-g.Text("+", id.String()+"^!")
|
| + if rslt.Err != nil {
|
| + return TextCommitDiffResult{Err: rslt.Err}
|
| + }
|
| + return TextCommitDiffResult{Diff: strings.Split(string(rslt.Data), "\n")}
|
| +}
|
| +
|
| +// 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() CommitDiffResult {
|
| + 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 CommitDiffResult{Diff: td}
|
| +}
|
|
|