Debian Codegraph @

git/object_scanner.go

raw symbols SCIP
1 package gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/
2
3 import (
4 "encoding/hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/"
5 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
6
7 "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/"
8 "github.com/git-lfs/gitobj/v2scip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/"
9 "github.com/git-lfs/gitobj/v2/errorsscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2/errors`/"
10 )
11
12 // object represents a generic Git object of any type.
13 type objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object# struct {
14 // Contents reads Git's internal object representation.
15 Contentsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Contents. ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#
16 // Oid is the ID of the object.
17 Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Oid. string
18 // Size is the size in bytes of the object.
19 Sizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Size. int64
20 // Type is the type of the object being held.
21 Typescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Type. string
22 // object is the gitobj object being handled.
23 objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#object. gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.Objectscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Object#
24 }
25
26 // ObjectScanner is a scanner type that scans for Git objects reference-able in
27 // Git's object database by their unique OID.
28 type ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner# struct {
29 // object is the object that the ObjectScanner last scanned, or nil.
30 objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object. *objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#
31 // err is the error (if any) that the ObjectScanner encountered during
32 // its last scan, or nil.
33 errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#err. error
34
35 gitobjscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#gitobj. *gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.ObjectDatabasescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#
36 }
37
38 // NewObjectScanner constructs a new instance of the `*ObjectScanner` type and
39 // returns it. It backs the ObjectScanner with an ObjectDatabase from the
40 // github.com/git-lfs/gitobj/v2 package.
41 // If any errors are encountered while creating the ObjectDatabase,
42 // they will be returned immediately.
43 // Otherwise, an `*ObjectScanner` is returned with no error.
44 func NewObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/NewObjectScanner().(gitEnv, osEnv Environmentscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Environment#) (*ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#, error) {
45 gitdir, err := GitCommonDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/GitCommonDir().()
46 if err != nil {
47 return nil, err
48 }
49
50 db, err := ObjectDatabasescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectDatabase().(osEnv, gitEnv, gitdir, "")
51 if err != nil {
52 return nil, err
53 }
54
55 return NewObjectScannerFromscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/NewObjectScannerFrom().(db), nil
56 }
57
58 // NewObjectScannerFrom returns a new `*ObjectScanner` populated with data from
59 // the given `io.Reader`, "r". It supplies no close function, and discards any
60 // input given to the Scan() function.
61 func NewObjectScannerFromscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/NewObjectScannerFrom().(db *gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.ObjectDatabasescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#) *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner# {
62 return &ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#{gitobjscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#gitobj.: db}
63 }
64
65 // Scan scans for a particular object given by the "oid" parameter. Once the
66 // scan is complete, the Contents(), Sha1(), Size() and Type() functions may be
67 // called and will return data corresponding to the given OID.
68 //
69 // Scan() returns whether the scan was successful, or in other words, whether or
70 // not the scanner can continue to progress.
71 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) Scanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#Scan().(oid string) bool {
72 if err := s.resetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#reset().(); err != nil {
73 s.errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#err. = err
74 return false
75 }
76
77 obj, err := s.scanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#scan().(oid)
78 s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object. = obj
79
80 if err != nil {
81 if err != ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF. {
82 s.errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#err. = err
83 }
84 return false
85 }
86 return true
87 }
88
89 // Close closes and frees any resources owned by the *ObjectScanner that it is
90 // called upon. If there were any errors in freeing that (those) resource(s), it
91 // it will be returned, otherwise nil.
92 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) Closescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#Close().() error {
93 if s == nil {
94 return nil
95 }
96
97 s.resetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#reset().()
98 s.gitobjscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#gitobj..Closescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#Close().()
99
100 return nil
101 }
102
103 // Contents returns an io.Reader which reads Git's representation of the object
104 // that was last scanned for.
105 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) Contentsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#Contents().() ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader# {
106 return s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object..Contentsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Contents.
107 }
108
109 // Sha1 returns the SHA1 object ID of the object that was last scanned for.
110 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) Sha1scip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#Sha1().() string {
111 return s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object..Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Oid.
112 }
113
114 // Size returns the size in bytes of the object that was last scanned for.
115 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) Sizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#Size().() int64 {
116 return s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object..Sizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Size.
117 }
118
119 // Type returns the type of the object that was last scanned for.
120 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) Typescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#Type().() string {
121 return s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object..Typescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Type.
122 }
123
124 // Err returns the error (if any) that was encountered during the last Scan()
125 // operation.
126 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#Err().() error { return s.errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#err. }
127
128 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) resetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#reset().() error {
129 if s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object. != nil {
130 if c, ok := s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object..objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#object..(interface {
131 Close() error
132 }); ok && c != nil {
133 if err := c.Close(); err != nil {
134 return err
135 }
136 }
137 }
138
139 s.objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#object., s.errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#err. = nil, nil
140 return nil
141 }
142
143 type missingErrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr# struct {
144 oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr#oid. string
145 }
146
147 func (m *missingErrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr#) Errorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr#Error().() string {
148 return trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("missing object: %s", m.oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr#oid.)
149 }
150
151 func IsMissingObjectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/IsMissingObject().(err error) bool {
152 _, ok := err.(*missingErrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr#)
153 return ok
154 }
155
156 func mustDecodescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/mustDecode().(oid string) []byte {
157 x, _ := hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/.DecodeStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/DecodeString().(oid)
158 return x
159 }
160
161 func (s *ObjectScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#) scanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#scan().(oid string) (*objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#, error) {
162 var (
163 obj gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.Objectscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Object#
164 size int64
165 contents ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#
166 )
167
168 obj, err := s.gitobjscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ObjectScanner#gitobj..Objectscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#Object().(mustDecodescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/mustDecode().(oid))
169 if err != nil {
170 if errorsscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2/errors`/.IsNoSuchObjectscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2/errors`/IsNoSuchObject().(err) {
171 return nil, &missingErrscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr#{oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/missingErr#oid.: oid}
172 }
173 return nil, err
174 }
175
176 // Currently, we're only interested in the size and contents of blobs,
177 // and gitobj only exposes the size easily for us for blobs anyway.
178 if obj.Typescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Object#Type().() == gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.BlobObjectTypescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/BlobObjectType. {
179 blob := obj.(*gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.Blobscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Blob#)
180 size = blob.Sizescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Blob#Size.
181 contents = blob.Contentsscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Blob#Contents.
182 }
183
184 return &objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#{
185 Contentsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Contents.: contents,
186 Oidscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Oid.: oid,
187 Sizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Size.: size,
188 Typescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#Type.: obj.Typescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Object#Type().().Stringscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectType#String().(),
189 objectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/object#object.: obj,
190 }, nil
191 }