Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefactor package hashing #4816

Merged
merged 14 commits into from May 4, 2023
21 changes: 3 additions & 18 deletions cli/internal/fs/hash.go
Expand Up @@ -5,9 +5,9 @@ import (
"encoding/hex"
"fmt"
"io"
"os"
"strconv"

"github.com/vercel/turbo/cli/internal/turbopath"
"github.com/vercel/turbo/cli/internal/xxhash"
)

Expand All @@ -19,25 +19,10 @@ func HashObject(i interface{}) (string, error) {
return hex.EncodeToString(hash.Sum(nil)), err
}

func HashFile(filePath string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah nice find

file, err := os.Open(filePath)
if err != nil {
return "", err
}
defer file.Close()

hash := xxhash.New()
if _, err := io.Copy(hash, file); err != nil {
return "", err
}

return hex.EncodeToString(hash.Sum(nil)), nil
}

// GitLikeHashFile is a function that mimics how Git
// calculates the SHA1 for a file (or, in Git terms, a "blob") (without git)
func GitLikeHashFile(filePath string) (string, error) {
file, err := os.Open(filePath)
func GitLikeHashFile(filePath turbopath.AbsoluteSystemPath) (string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I needed to touch this, I made it a turbopath...

file, err := filePath.Open()
if err != nil {
return "", err
}
Expand Down