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

Side by Side Diff: go/src/infra/libs/git/intern.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 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698