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

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

Powered by Google App Engine
This is Rietveld 408576698