返回 DeepSeek-Reasonix
objects.go
根目录 / internal / gitcmd / objects.go
1 package gitcmd
2
3 import (
4 "bufio"
5 "bytes"
6 "context"
7 "errors"
8 )
9
10 // ErrObjectNotLocal reports that objects a command needs are absent from a
11 // partial clone. Host git never fetches them (GIT_NO_LAZY_FETCH).
12 var ErrObjectNotLocal = errors.New("gitcmd: git objects are not present locally")
13
14 // ObjectsMissing reports whether any object in the trees of revs is absent
15 // locally, as git itself lists them (--missing=print), without fetching. A rev
16 // that does not resolve — a root commit's parent — is skipped.
17 func (r Repo) ObjectsMissing(ctx context.Context, revs ...string) bool {
18 for _, rev := range revs {
19 out, err := r.Command(ctx, "rev-list", "--objects", "--no-walk", "--missing=print", "--end-of-options", rev, "--").Output()
20 if err != nil {
21 continue
22 }
23 sc := bufio.NewScanner(bytes.NewReader(out))
24 for sc.Scan() {
25 if bytes.HasPrefix(sc.Bytes(), []byte("?")) {
26 return true
27 }
28 }
29 }
30 return false
31 }
32
32 lines GO