Skip to content

Commit

Permalink
disable git cache hint
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelvigee committed Apr 19, 2024
1 parent 9f9e315 commit 96edc99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func BuildConfig(root *hroot.State, profiles []string) (*config.Config, error) {
cfg.CacheHistory = 3
cfg.Engine.GC = true
cfg.Engine.CacheHints = true
cfg.Engine.GitCacheHints = true
cfg.Engine.GitCacheHints = false
cfg.Engine.ParallelCaching = true
cfg.Engine.SmartGen = true
cfg.CacheOrder = config.CacheOrderLatency
Expand Down
43 changes: 18 additions & 25 deletions gitstatus/gitstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package gitstatus

import (
"context"
"github.com/hephbuild/heph/log/log"
"github.com/hephbuild/heph/utils/ads"
"golang.org/x/exp/slices"
"os/exec"
"path/filepath"
"strings"
Expand All @@ -13,44 +11,41 @@ import (

type GitStatus struct {
root string
m sync.Mutex
o sync.Once

dirty []string
dirty map[string]struct{}
}

func New(root string) *GitStatus {
return &GitStatus{root: root}
}

func (gs *GitStatus) diffIndexOnce(ctx context.Context) []string {
gs.m.Lock()
defer gs.m.Unlock()
func (gs *GitStatus) diffIndexOnce(ctx context.Context) map[string]struct{} {
gs.o.Do(func() {
// If something went wrong, we can assume nothing is dirty
dirty, _ := gs.diffIndex(ctx)

if gs.dirty == nil {
gs.dirty = gs.diffIndex(ctx)
if gs.dirty == nil {
gs.dirty = []string{}
gs.dirty = make(map[string]struct{}, len(dirty))
for _, file := range dirty {
gs.dirty[file] = struct{}{}
}
}
})

return gs.dirty[:]
return gs.dirty
}

func (gs *GitStatus) diffIndex(ctx context.Context) []string {
func (gs *GitStatus) diffIndex(ctx context.Context) ([]string, error) {
gitPath, err := exec.LookPath("git")
if err != nil {
// git not found, assume nothing is dirty
return nil
return nil, err
}

cmd := exec.CommandContext(ctx, gitPath, "diff-index", "HEAD", "--name-only")
cmd.Dir = gs.root

b, err := cmd.Output()
if err != nil {
// something failed, assume nothing is dirty
log.Errorf("git: diff-index: %v", err)
return nil
return nil, err
}

lines := strings.Split(string(b), "\n")
Expand All @@ -60,18 +55,16 @@ func (gs *GitStatus) diffIndex(ctx context.Context) []string {

return ads.Map(lines, func(line string) string {
return filepath.Join(gs.root, line)
})
}), nil
}

func (gs *GitStatus) IsDirty(ctx context.Context, path string) bool {
dirty := gs.diffIndexOnce(ctx)

return slices.Contains(dirty, path)
_, ok := dirty[path]
return ok
}

func (gs *GitStatus) Reset() {
gs.m.Lock()
defer gs.m.Unlock()

gs.dirty = nil
gs.o = sync.Once{}
}

0 comments on commit 96edc99

Please sign in to comment.