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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: go/src/infra/libs/git/intern.go
diff --git a/go/src/infra/libs/git/intern.go b/go/src/infra/libs/git/intern.go
new file mode 100644
index 0000000000000000000000000000000000000000..66790c392479044686bedc2c66688609a081baf2
--- /dev/null
+++ b/go/src/infra/libs/git/intern.go
@@ -0,0 +1,43 @@
+package git
+
+import "fmt"
+import "strings"
+
+// 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)
+type InternResult struct {
+ Err error
+ ID ObjectID
+}
+
+// Intern takes an InternableObject (Blob, Tree, Commit), and writes it into
+// the on-disk Repo.
+func (r *Repo) Intern(obj InternableObject) InternResult {
+ gotData := false
+ var data string
+ if !obj.Complete() {
+ gotData = true
+ data = obj.RawString()
+ }
+
+ if obj.ID() != NoID && r.HasObjectID(obj.ID()) {
+ return InternResult{ID: obj.ID()}
+ }
+
+ switch obj.Type() {
+ case "commit", "tree", "blob":
+ default:
+ return InternResult{Err: fmt.Errorf(
+ "git.Intern: Unrecognized type %s", obj.Type())}
+ }
+ if !gotData {
+ data = obj.RawString()
+ }
+ cmd := []string{"hash-object", "-t", obj.Type(), "-w", "--stdin"}
+ out, ok := r.RunInput(data, cmd...)
+ if !ok {
+ return InternResult{
+ Err: fmt.Errorf("error running %s <- %s: not ok", cmd, data),
+ }
+ }
+ return InternResult{ID: MakeObjectID(strings.TrimSpace(string(out)))}
+}

Powered by Google App Engine
This is Rietveld 408576698