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

Side by Side Diff: go/src/infra/libs/git/object.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, 1 month 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
« no previous file with comments | « go/src/infra/libs/git/mode_test.go ('k') | go/src/infra/libs/git/objectID.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
5 package git
6
7 import (
8 "fmt"
9 "strings"
10 )
11
12 func ObjectFromRaw(typ ObjectType, data []byte) (InternableObject, error) {
13 return ObjectFromRawWithID(MakeObjectIDForData(typ, data), typ, data)
14 }
15
16 func ObjectFromRawWithID(id Identifiable, typ ObjectType, data []byte) (Internab leObject, error) {
17 switch typ {
18 case BlobType:
19 return NewBlobFromRawWithID(id, data), nil
20 case TreeType:
21 return NewTreeFromRawWithID(id, data)
22 case CommitType:
23 return NewCommitFromRawWithID(id, data)
24 default:
25 return nil, fmt.Errorf("unsupported object type: %s", typ)
26 }
27 }
28
29 func InternImpl(s GitService, obj InternableObject, intern func(string) (string, error)) (*ObjectID, error) {
30 gotData := false
31 var data string
32 if !obj.Complete() {
33 gotData = true
34 data = obj.RawString()
35 }
36
37 if *obj.ID() == NoID {
38 return nil, fmt.Errorf("%v still has NoID after calling RawStrin g()", obj)
39 }
40 if s.HasObjectID(obj) {
41 return obj.ID(), nil
42 }
43
44 switch obj.Type() {
45 case CommitType, BlobType, TreeType:
46 default:
47 return nil, fmt.Errorf("git.Intern: Unrecognized type %s", obj.T ype())
48 }
49 if !gotData {
50 data = obj.RawString()
51 }
52 id_raw, err := intern(data)
53 if err != nil {
54 return nil, err
55 }
56 return MakeObjectIDErr(strings.TrimSpace(id_raw))
57 }
OLDNEW
« no previous file with comments | « go/src/infra/libs/git/mode_test.go ('k') | go/src/infra/libs/git/objectID.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698