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

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: Lots of fixes 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 // 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698