| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 package gitiles |
| 5 |
| 6 import ( |
| 7 "strings" |
| 8 |
| 9 "infra/libs/git" |
| 10 ) |
| 11 |
| 12 // GetCommitDiff returns the git.TreeDiff from the given committish. |
| 13 func (g *Gitiles) GetCommitDiff(committish string) (git.TreeDiff, error) { |
| 14 rslt, err := g.JSON(jsonCommitDiff{}, "+", committish) |
| 15 if err != nil { |
| 16 return nil, err |
| 17 } |
| 18 diff := *rslt.(*jsonCommitDiff) |
| 19 return diff.ToResult(), nil |
| 20 } |
| 21 |
| 22 func (g *Gitiles) GetTextCommitDiff(id git.ObjectID) (string, error) { |
| 23 rslt, err := g.Text("+", id.String()+"^!") |
| 24 if err != nil { |
| 25 return "", err |
| 26 } |
| 27 return string(rslt), nil |
| 28 } |
| 29 |
| 30 // private |
| 31 |
| 32 type jsonCommitDiff struct { |
| 33 TreeDiff []struct { |
| 34 Type string `json:"type"` |
| 35 OldID string `json:"old_id"` |
| 36 OldMode git.Mode `json:"old_mode"` |
| 37 OldPath string `json:"old_path"` |
| 38 NewID string `json:"new_id"` |
| 39 NewMode git.Mode `json:"new_mode"` |
| 40 NewPath string `json:"new_path"` |
| 41 } `json:"tree_diff"` |
| 42 } |
| 43 |
| 44 func (c *jsonCommitDiff) ToResult() git.TreeDiff { |
| 45 td := make(git.TreeDiff, 0, len(c.TreeDiff)) |
| 46 for _, ent := range c.TreeDiff { |
| 47 td = append(td, git.TreeDiffEntry{ |
| 48 Action: strings.ToUpper(ent.Type[:1]), |
| 49 Old: git.TreeDiffEntryHalf{ |
| 50 Child: *git.NewEmptyChild(ent.OldMode, git.MakeO
bjectID(ent.OldID)), |
| 51 Name: ent.OldPath, |
| 52 }, |
| 53 New: git.TreeDiffEntryHalf{ |
| 54 Child: *git.NewEmptyChild(ent.NewMode, git.MakeO
bjectID(ent.NewID)), |
| 55 Name: ent.NewPath, |
| 56 }, |
| 57 }) |
| 58 } |
| 59 return td |
| 60 } |
| OLD | NEW |