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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: go/src/infra/libs/gitiles/commit_diff.go
diff --git a/go/src/infra/libs/gitiles/commit_diff.go b/go/src/infra/libs/gitiles/commit_diff.go
new file mode 100644
index 0000000000000000000000000000000000000000..db89b1142b306a09f3e1f83ede65c87c56489289
--- /dev/null
+++ b/go/src/infra/libs/gitiles/commit_diff.go
@@ -0,0 +1,60 @@
+// 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 (
+ "strings"
+
+ "infra/libs/git"
+)
+
+// GetCommitDiff returns the git.TreeDiff from the given committish.
+func (g *Gitiles) GetCommitDiff(committish string) (git.TreeDiff, error) {
+ rslt, err := g.JSON(jsonCommitDiff{}, "+", committish)
+ if err != nil {
+ return nil, err
+ }
+ diff := *rslt.(*jsonCommitDiff)
+ return diff.ToResult(), nil
+}
+
+func (g *Gitiles) GetTextCommitDiff(id git.ObjectID) (string, error) {
+ rslt, err := g.Text("+", id.String()+"^!")
+ if err != nil {
+ return "", err
+ }
+ return string(rslt), nil
+}
+
+// private
+
+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"`
+}
+
+func (c *jsonCommitDiff) ToResult() git.TreeDiff {
+ td := make(git.TreeDiff, 0, len(c.TreeDiff))
+ for _, ent := range c.TreeDiff {
+ td = append(td, git.TreeDiffEntry{
+ Action: strings.ToUpper(ent.Type[:1]),
+ Old: git.TreeDiffEntryHalf{
+ Child: *git.NewEmptyChild(ent.OldMode, git.MakeObjectID(ent.OldID)),
+ Name: ent.OldPath,
+ },
+ New: git.TreeDiffEntryHalf{
+ Child: *git.NewEmptyChild(ent.NewMode, git.MakeObjectID(ent.NewID)),
+ Name: ent.NewPath,
+ },
+ })
+ }
+ return td
+}

Powered by Google App Engine
This is Rietveld 408576698