Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: go/src/infra/libs/gitiles/commit_diff.go

Issue 662113003: Drover's back, baby! (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git/+/master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package gitiles
2
3 import "strings"
4
5 import "infra/libs/git"
6
7 // CommitDiffResult contains a git.TreeDiff, or an error.
8 type CommitDiffResult struct {
9 Err error
10 Diff git.TreeDiff
11 }
12
13 type TextCommitDiffResult struct {
14 Err error
15 Diff []string
16 }
17
18 // GetCommitDiff returns the CommitDiffResult from the given committish.
19 func (g *Gitiles) GetCommitDiff(committish string) CommitDiffResult {
20 rslt := <-g.JSON(jsonCommitDiff{}, "+", committish)
21 if rslt.Err != nil {
22 return CommitDiffResult{Err: rslt.Err}
23 }
24 diff := *rslt.DataPtr.(*jsonCommitDiff)
25 return diff.ToResult()
26 }
27
28 func (g *Gitiles) GetTextCommitDiff(id git.ObjectID) TextCommitDiffResult {
29 rslt := <-g.Text("+", id.String()+"^!")
30 if rslt.Err != nil {
31 return TextCommitDiffResult{Err: rslt.Err}
32 }
33 return TextCommitDiffResult{Diff: strings.Split(string(rslt.Data), "\n") }
34 }
35
36 // private
37
38 type jsonCommitDiff struct {
39 TreeDiff []struct {
40 Type string `json:"type"`
41 OldID string `json:"old_id"`
42 OldMode git.Mode `json:"old_mode"`
43 OldPath string `json:"old_path"`
44 NewID string `json:"new_id"`
45 NewMode git.Mode `json:"new_mode"`
46 NewPath string `json:"new_path"`
47 } `json:"tree_diff"`
48 }
49
50 func (c *jsonCommitDiff) ToResult() CommitDiffResult {
51 td := make(git.TreeDiff, 0, len(c.TreeDiff))
52 for _, ent := range c.TreeDiff {
53 td = append(td, git.TreeDiffEntry{
54 Action: strings.ToUpper(ent.Type[:1]),
55 Old: git.TreeDiffEntryHalf{
56 Child: *git.NewEmptyChild(ent.OldMode, git.MakeO bjectID(ent.OldID)),
57 Name: ent.OldPath,
58 },
59 New: git.TreeDiffEntryHalf{
60 Child: *git.NewEmptyChild(ent.NewMode, git.MakeO bjectID(ent.NewID)),
61 Name: ent.NewPath,
62 },
63 })
64 }
65 return CommitDiffResult{Diff: td}
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698