diff options
author | Michael Muré <batolettre@gmail.com> | 2020-07-01 19:39:02 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-07-01 19:39:02 +0200 |
commit | 3cf31fc4049fefc82db0a3d2018b5d98ab77c5d7 (patch) | |
tree | c77a29e1f35fefa5040454976c6edcf86e7678bc /util | |
parent | 33d510ac3999b3d8fa7a4652dc44a21c713f97de (diff) | |
download | git-bug-3cf31fc4049fefc82db0a3d2018b5d98ab77c5d7.tar.gz |
repository: merge git.Hash in for one less /util package
Diffstat (limited to 'util')
-rw-r--r-- | util/git/hash.go | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/util/git/hash.go b/util/git/hash.go deleted file mode 100644 index d7254178..00000000 --- a/util/git/hash.go +++ /dev/null @@ -1,51 +0,0 @@ -package git - -import ( - "fmt" - "io" -) - -const idLengthSHA1 = 40 -const idLengthSHA256 = 64 - -// Hash is a git hash -type Hash string - -func (h Hash) String() string { - return string(h) -} - -// UnmarshalGQL implement the Unmarshaler interface for gqlgen -func (h *Hash) UnmarshalGQL(v interface{}) error { - _, ok := v.(string) - if !ok { - return fmt.Errorf("hashes must be strings") - } - - *h = v.(Hash) - - if !h.IsValid() { - return fmt.Errorf("invalid hash") - } - - return nil -} - -// MarshalGQL implement the Marshaler interface for gqlgen -func (h Hash) MarshalGQL(w io.Writer) { - _, _ = w.Write([]byte(`"` + h.String() + `"`)) -} - -// IsValid tell if the hash is valid -func (h *Hash) IsValid() bool { - // Support for both sha1 and sha256 git hashes - if len(*h) != idLengthSHA1 && len(*h) != idLengthSHA256 { - return false - } - for _, r := range *h { - if (r < 'a' || r > 'z') && (r < '0' || r > '9') { - return false - } - } - return true -} |