| 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 |
| 5 package gitiles |
| 6 |
| 7 import ( |
| 8 "infra/libs/git" |
| 9 "strings" |
| 10 ) |
| 11 |
| 12 // Private ///////////////////////////////////////////////////////////////////// |
| 13 |
| 14 // Types /////////////////////////////////////////////////////////////////////// |
| 15 |
| 16 type jsonCommitDiff struct { |
| 17 TreeDiff []struct { |
| 18 Type string `json:"type"` |
| 19 OldID string `json:"old_id"` |
| 20 OldMode git.Mode `json:"old_mode"` |
| 21 OldPath string `json:"old_path"` |
| 22 NewID string `json:"new_id"` |
| 23 NewMode git.Mode `json:"new_mode"` |
| 24 NewPath string `json:"new_path"` |
| 25 } `json:"tree_diff"` |
| 26 } |
| 27 |
| 28 // Member functions //////////////////////////////////////////////////////////// |
| 29 |
| 30 func (c *jsonCommitDiff) ToResult() (git.TreeDiff, error) { |
| 31 td := make(git.TreeDiff, 0, len(c.TreeDiff)) |
| 32 for _, ent := range c.TreeDiff { |
| 33 oldID, err := git.MakeObjectIDErr(ent.OldID) |
| 34 if err != nil { |
| 35 return nil, err |
| 36 } |
| 37 newID, err := git.MakeObjectIDErr(ent.NewID) |
| 38 if err != nil { |
| 39 return nil, err |
| 40 } |
| 41 oldChild, err := git.NewEmptyChild(ent.OldMode, oldID) |
| 42 if err != nil { |
| 43 return nil, err |
| 44 } |
| 45 newChild, err := git.NewEmptyChild(ent.NewMode, newID) |
| 46 if err != nil { |
| 47 return nil, err |
| 48 } |
| 49 |
| 50 td = append(td, git.TreeDiffEntry{ |
| 51 Action: strings.ToUpper(ent.Type[:1]), |
| 52 Old: git.TreeDiffEntryHalf{ |
| 53 Child: *oldChild, |
| 54 Name: ent.OldPath, |
| 55 }, |
| 56 New: git.TreeDiffEntryHalf{ |
| 57 Child: *newChild, |
| 58 Name: ent.NewPath, |
| 59 }, |
| 60 }) |
| 61 } |
| 62 return td, nil |
| 63 } |
| OLD | NEW |