diff --git a/app/build/build.go b/app/build/build.go index 3b52a7c025..bd13080a75 100644 --- a/app/build/build.go +++ b/app/build/build.go @@ -9,7 +9,6 @@ package build import ( "bytes" "compress/gzip" - "crypto/sha1" "errors" "fmt" "io" @@ -24,6 +23,8 @@ import ( "appengine/datastore" "cache" + + "golang.org/x/build/internal/loghash" ) const ( @@ -863,13 +864,11 @@ func (l *Log) Text() ([]byte, error) { } func PutLog(c appengine.Context, text string) (hash string, err error) { - h := sha1.New() - io.WriteString(h, text) b := new(bytes.Buffer) z, _ := gzip.NewWriterLevel(b, gzip.BestCompression) io.WriteString(z, text) z.Close() - hash = fmt.Sprintf("%x", h.Sum(nil)) + hash = loghash.New(text) key := datastore.NewKey(c, "Log", hash, 0, nil) _, err = datastore.Put(c, key, &Log{b.Bytes()}) return diff --git a/internal/loghash/loghash.go b/internal/loghash/loghash.go new file mode 100644 index 0000000000..d47e6fc860 --- /dev/null +++ b/internal/loghash/loghash.go @@ -0,0 +1,20 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package loghash provides the shared information for computing +// a log hash (as in https://build.golang.org/log/HASH). +package loghash + +import ( + "crypto/sha1" + "fmt" + "io" +) + +// New returns a new hash for the given log text. +func New(text string) (hash string) { + h := sha1.New() + io.WriteString(h, text) + return fmt.Sprintf("%x", h.Sum(nil)) +}