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

Unified Diff: go/src/infra/libs/gitiles/priv_jsonCommitDiff.go

Issue 662113003: Drover's back, baby! (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git/+/master
Patch Set: more tests and refactors 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/libs/gitiles/gitiles.go ('k') | go/src/infra/libs/gitiles/priv_jsonRequest.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/libs/gitiles/priv_jsonCommitDiff.go
diff --git a/go/src/infra/libs/gitiles/priv_jsonCommitDiff.go b/go/src/infra/libs/gitiles/priv_jsonCommitDiff.go
new file mode 100644
index 0000000000000000000000000000000000000000..0081add1aff36bdc7680b978f5c5d54d038e82d2
--- /dev/null
+++ b/go/src/infra/libs/gitiles/priv_jsonCommitDiff.go
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package gitiles
+
+import (
+ "infra/libs/git"
+ "strings"
+)
+
+// Private /////////////////////////////////////////////////////////////////////
+
+// Types ///////////////////////////////////////////////////////////////////////
+
+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"`
+}
+
+// Member functions ////////////////////////////////////////////////////////////
+
+func (c *jsonCommitDiff) ToResult() (git.TreeDiff, error) {
+ td := make(git.TreeDiff, 0, len(c.TreeDiff))
+ for _, ent := range c.TreeDiff {
+ oldID, err := git.MakeObjectIDErr(ent.OldID)
+ if err != nil {
+ return nil, err
+ }
+ newID, err := git.MakeObjectIDErr(ent.NewID)
+ if err != nil {
+ return nil, err
+ }
+ oldChild, err := git.NewEmptyChild(ent.OldMode, oldID)
+ if err != nil {
+ return nil, err
+ }
+ newChild, err := git.NewEmptyChild(ent.NewMode, newID)
+ if err != nil {
+ return nil, err
+ }
+
+ td = append(td, git.TreeDiffEntry{
+ Action: strings.ToUpper(ent.Type[:1]),
+ Old: git.TreeDiffEntryHalf{
+ Child: *oldChild,
+ Name: ent.OldPath,
+ },
+ New: git.TreeDiffEntryHalf{
+ Child: *newChild,
+ Name: ent.NewPath,
+ },
+ })
+ }
+ return td, nil
+}
« no previous file with comments | « go/src/infra/libs/gitiles/gitiles.go ('k') | go/src/infra/libs/gitiles/priv_jsonRequest.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698