Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 package git | |
| 2 | |
| 3 import "fmt" | |
| 4 import "strings" | |
| 5 | |
| 6 // InternResult contians either the ID of the intern'd object, or an error. | |
|
M-A Ruel
2014/10/18 00:47:05
contains
iannucci
2014/10/20 21:11:57
Done (removed this struct entirely)
| |
| 7 type InternResult struct { | |
| 8 Err error | |
| 9 ID ObjectID | |
| 10 } | |
| 11 | |
| 12 // Intern takes an InternableObject (Blob, Tree, Commit), and writes it into | |
| 13 // the on-disk Repo. | |
| 14 func (r *Repo) Intern(obj InternableObject) InternResult { | |
| 15 gotData := false | |
| 16 var data string | |
| 17 if !obj.Complete() { | |
| 18 gotData = true | |
| 19 data = obj.RawString() | |
| 20 } | |
| 21 | |
| 22 if obj.ID() != NoID && r.HasObjectID(obj.ID()) { | |
| 23 return InternResult{ID: obj.ID()} | |
| 24 } | |
| 25 | |
| 26 switch obj.Type() { | |
| 27 case "commit", "tree", "blob": | |
| 28 default: | |
| 29 return InternResult{Err: fmt.Errorf( | |
| 30 "git.Intern: Unrecognized type %s", obj.Type())} | |
| 31 } | |
| 32 if !gotData { | |
| 33 data = obj.RawString() | |
| 34 } | |
| 35 cmd := []string{"hash-object", "-t", obj.Type(), "-w", "--stdin"} | |
| 36 out, ok := r.RunInput(data, cmd...) | |
| 37 if !ok { | |
| 38 return InternResult{ | |
| 39 Err: fmt.Errorf("error running %s <- %s: not ok", cmd, d ata), | |
| 40 } | |
| 41 } | |
| 42 return InternResult{ID: MakeObjectID(strings.TrimSpace(string(out)))} | |
| 43 } | |
| OLD | NEW |