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

Side by Side Diff: go/src/infra/libs/gitiles/object.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 "fmt"
4 import "net/http"
5 import "strings"
6
7 import "infra/libs/git"
8
9 // ObjectResult is the error/git.{Blob|Commit|Tree} result you get back in
10 // a channel from GetBlobFromPath
11 type ObjectResult struct {
12 Err error
13 Object git.InternableObject
14 }
15
16 // GetObjectFromPath returns a channel yielding an ObjectResult from this Gitile s
17 // service. This will hit the url:
18 // {g.url}/+/{committish}/path/pieces...?format=TEXT
19 // Passing NO pieces will return a git.Commit
20 // Passing A blank piece (e.g. empty string) will return a git.Tree for the root
21 // tree.
22 // Passing non-blank pieces will return a git.Tree or git.Blob depending on
23 // the path.
24 func (g *Gitiles) GetObjectFromPath(committish string, pathPieces ...string) <-c han ObjectResult {
25 ret := make(chan ObjectResult, 1)
26 g.requests <- objRequest{
27 textRequest{
28 strings.Join(append([]string{"+", committish}, pathPiece s...), "/"),
29 nil,
30 },
31 ret,
32 }
33 return ret
34 }
35
36 // Private
37
38 type objRequest struct {
39 textRequest
40 resultChan chan<- ObjectResult
41 }
42
43 func (o objRequest) Process(rsp *http.Response, err error) {
44 var rslt ObjectResult
45
46 data, err := o.internalProcess(rsp, err)
47 if err != nil {
48 rslt.Err = err
49 } else {
50 typ := rsp.Header.Get("X-Gitiles-Object-Type")
51 switch typ {
52 case "blob":
53 rslt.Object = git.BlobFromRaw(data)
54 case "tree":
55 // TODO(riannucci): When gitiles supports format=RAW, us e that instead
56 if tree, err := git.TreeFromText(data); err != nil {
57 rslt.Err = err
58 } else {
59 rslt.Object = tree
60 }
61 case "commit":
62 if c, err := git.CommitFromRaw(data); err != nil {
63 rslt.Err = err
64 } else {
65 rslt.Object = c
66 }
67 default:
68 rslt.Err = fmt.Errorf("Unknown object type %#v", typ)
69 }
70 }
71
72 o.resultChan <- rslt
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698