diff options
author | Michael Muré <batolettre@gmail.com> | 2019-08-11 14:08:03 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-08-11 14:08:03 +0200 |
commit | 67a3752e176790e82a48706236f889cab4f8913d (patch) | |
tree | 113251396fc2569d1db2c2e6fcadb30289b3aa96 /util | |
parent | a0dfc202117e31e01d2d6ec701a41292df35d35d (diff) | |
download | git-bug-67a3752e176790e82a48706236f889cab4f8913d.tar.gz |
bug,entity: use a dedicated type to store IDs
Diffstat (limited to 'util')
-rw-r--r-- | util/git/hash.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/util/git/hash.go b/util/git/hash.go index d9160d75..d7254178 100644 --- a/util/git/hash.go +++ b/util/git/hash.go @@ -5,6 +5,9 @@ import ( "io" ) +const idLengthSHA1 = 40 +const idLengthSHA256 = 64 + // Hash is a git hash type Hash string @@ -16,7 +19,7 @@ func (h Hash) String() string { func (h *Hash) UnmarshalGQL(v interface{}) error { _, ok := v.(string) if !ok { - return fmt.Errorf("labels must be strings") + return fmt.Errorf("hashes must be strings") } *h = v.(Hash) @@ -35,7 +38,8 @@ func (h Hash) MarshalGQL(w io.Writer) { // IsValid tell if the hash is valid func (h *Hash) IsValid() bool { - if len(*h) != 40 && len(*h) != 64 { + // Support for both sha1 and sha256 git hashes + if len(*h) != idLengthSHA1 && len(*h) != idLengthSHA256 { return false } for _, r := range *h { |