| OLD | NEW |
| (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 } |
| OLD | NEW |