mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
git: synchronize update-index
with a mutex
if `pkglib.NewFromConfig` is used in parallel, it calls ``` git -C /some/directory update-index -q --refresh ``` in parallel. But `git` does not like this and exits with 128. This can be easily tried with: ``` git -C /some/dir update-index -q --refresh & \ git -C /some/dir update-index -q --refresh ``` Signed-off-by: Christoph Ostarek <christoph@zededa.com>
This commit is contained in:
parent
5a13eda661
commit
1e66928712
@ -12,6 +12,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -27,6 +28,8 @@ type git struct {
|
|||||||
dir string
|
dir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gitMutex sync.Mutex
|
||||||
|
|
||||||
// Returns git==nil and no error if the path is not within a git repository
|
// Returns git==nil and no error if the path is not within a git repository
|
||||||
func newGit(dir string) (*git, error) {
|
func newGit(dir string) (*git, error) {
|
||||||
g := &git{dir}
|
g := &git{dir}
|
||||||
@ -190,9 +193,12 @@ func (g git) isDirty(pkg, commit string) (bool, error) {
|
|||||||
// because `git diff-index` only uses the `lstat` result and
|
// because `git diff-index` only uses the `lstat` result and
|
||||||
// not the actual file contents. Running `git update-index
|
// not the actual file contents. Running `git update-index
|
||||||
// --refresh` updates the cache.
|
// --refresh` updates the cache.
|
||||||
|
gitMutex.Lock()
|
||||||
if err := g.command("update-index", "-q", "--refresh"); err != nil {
|
if err := g.command("update-index", "-q", "--refresh"); err != nil {
|
||||||
|
gitMutex.Unlock()
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
gitMutex.Unlock()
|
||||||
|
|
||||||
// diff-index works pretty well, except that
|
// diff-index works pretty well, except that
|
||||||
err := g.command("diff-index", "--quiet", commit, "--", pkg)
|
err := g.command("diff-index", "--quiet", commit, "--", pkg)
|
||||||
|
Loading…
Reference in New Issue
Block a user