diff options
author | Alex Guerrieri <alex@tyba.com> | 2015-10-06 18:51:47 +0200 |
---|---|---|
committer | Alex Guerrieri <alex@tyba.com> | 2015-10-06 18:51:47 +0200 |
commit | 465cba710284204f9851854587c2887c247222db (patch) | |
tree | 75158b29f50acf928a069f4478852de51d77b466 /commons/hash.go | |
parent | b9471b13256703d3f5eb88b280b4a16ce325ec1b (diff) | |
download | go-git-465cba710284204f9851854587c2887c247222db.tar.gz |
Extract GitHash function
Diffstat (limited to 'commons/hash.go')
-rw-r--r-- | commons/hash.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/commons/hash.go b/commons/hash.go new file mode 100644 index 0000000..03fa53f --- /dev/null +++ b/commons/hash.go @@ -0,0 +1,17 @@ +package commons + +import ( + "crypto/sha1" + "fmt" + "strconv" +) + +func GitHash(t string, b []byte) string { + h := []byte(t) + h = append(h, ' ') + h = strconv.AppendInt(h, int64(len(b)), 10) + h = append(h, 0) + h = append(h, b...) + + return fmt.Sprintf("%x", sha1.Sum(h)) +} |