Debian Codegraph @

git/filter_process_scanner.go

raw symbols SCIP
1 // Package git contains various commands that shell out to git
2 // NOTE: Subject to change, do not rely on this package from outside git-lfs source
3 package gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/
4
5 import (
6 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
7 "slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/"
8 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
9
10 "github.com/git-lfs/git-lfs/v3/errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/"
11 "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`/"
12 "github.com/git-lfs/pktlinescip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/"
13 "github.com/rubyist/tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/"
14 )
15
16 // FilterProcessScanner provides a scanner-like interface capable of
17 // initializing the filter process with the Git parent, and scanning for
18 // requests across the protocol.
19 //
20 // Reading a request (and errors) is as follows:
21 //
22 // s := NewFilterProcessScanner(os.Stdin, os.Stderr)
23 // for s.Scan() {
24 // req := s.Request()
25 // // ...
26 // }
27 //
28 // if err := s.Err(); err != nil {
29 // // ...
30 // }
31 type FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner# struct {
32 // pl is the *pktline instance used to read and write packets back and
33 // forth between Git.
34 plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl. *pktlinescip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/.Pktlinescip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#
35
36 // req is a temporary variable used to hold the value accessible by the
37 // `Request()` function. It is cleared at the beginning of each `Scan()`
38 // invocation, and written to at the end of each `Scan()` invocation.
39 reqscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#req. *Requestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#
40 // err is a temporary variable used to hold the value accessible by the
41 // `Request()` function. It is cleared at the beginning of each `Scan()`
42 // invocation, and written to at the end of each `Scan()` invocation.
43 errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#err. error
44 }
45
46 // NewFilterProcessScanner constructs a new instance of the
47 // `*FilterProcessScanner` type which reads packets from the `io.Reader` "r",
48 // and writes packets to the `io.Writer`, "w".
49 //
50 // Both reader and writers SHOULD NOT be `*git.PacketReader` or
51 // `*git.PacketWriter`s, they will be transparently treated as such. In other
52 // words, it is safe (and recommended) to pass `os.Stdin` and `os.Stdout`
53 // directly.
54 func NewFilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/NewFilterProcessScanner().(r 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#, w ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Writerscip-go gomod github.com/golang/go/src go1.25.0 io/Writer#) *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner# {
55 return &FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#{
56 plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl.: pktlinescip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/.NewPktlinescip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/NewPktline().(r, w),
57 }
58 }
59
60 // Init initializes the filter and ACKs back and forth between the Git LFS
61 // subprocess and the Git parent process that each is a git-filter-server and
62 // client respectively.
63 //
64 // If either side wrote an invalid sequence of data, or did not meet
65 // expectations, an error will be returned. If the filter type is not supported,
66 // an error will be returned. If the pkt-line welcome message was invalid, an
67 // error will be returned.
68 //
69 // If there was an error reading or writing any of the packets below, an error
70 // will be returned.
71 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) Initscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#Init().() error {
72 tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("Initialize filter-process")
73 reqVer := "version=2"
74
75 initMsg, err := o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..ReadPacketTextscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#ReadPacketText().()
76 if err != nil {
77 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Wrapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Wrap().(err, 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().("reading filter-process initialization"))
78 }
79 if initMsg != "git-filter-client" {
80 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(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().("invalid filter-process pkt-line welcome message: %s", initMsg))
81 }
82
83 supVers, err := o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..ReadPacketListscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#ReadPacketList().()
84 if err != nil {
85 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Wrapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Wrap().(err, 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().("reading filter-process versions"))
86 }
87 if !slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.0 slices/Contains().(supVers, reqVer) {
88 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(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().("filter '%s' not supported (your Git supports: %s)", reqVer, supVers))
89 }
90
91 err = o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..WritePacketListscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#WritePacketList().([]string{"git-filter-server", reqVer})
92 if err != nil {
93 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Wrapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Wrap().(err, 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().("writing filter-process initialization failed"))
94 }
95 return nil
96 }
97
98 // NegotiateCapabilities executes the process of negotiating capabilities
99 // between the filter client and server. If we don't support any of the
100 // capabilities given to LFS by Git, an error will be returned. If there was an
101 // error reading or writing capabilities between the two, an error will be
102 // returned.
103 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) NegotiateCapabilitiesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#NegotiateCapabilities().() ([]string, error) {
104 reqCaps := []string{"capability=clean", "capability=smudge"}
105
106 supCaps, err := o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..ReadPacketListscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#ReadPacketList().()
107 if err != nil {
108 return nil, errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(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().("reading filter-process capabilities failed with %s", err))
109 }
110
111 if slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.0 slices/Contains().(supCaps, "capability=delay") {
112 reqCaps = append(reqCaps, "capability=delay")
113 }
114
115 for _, reqCap := range reqCaps {
116 if !slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.0 slices/Contains().(supCaps, reqCap) {
117 return nil, errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(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().("filter '%s' not supported (your Git supports: %s)", reqCap, supCaps))
118 }
119 }
120
121 err = o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..WritePacketListscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#WritePacketList().(reqCaps)
122 if err != nil {
123 return nil, errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(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().("writing filter-process capabilities failed with %s", err))
124 }
125
126 return supCaps, nil
127 }
128
129 // Request represents a single command sent to LFS from the parent Git process.
130 type Requestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request# struct {
131 // Header maps header strings to values, and is encoded as the first
132 // part of the packet.
133 Headerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#Header. map[string]string
134 // Payload represents the body of the packet, and contains the contents
135 // of the file in the index.
136 Payloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#Payload. 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#
137 }
138
139 // Scan scans for the next request, or error and returns whether or not the scan
140 // was successful, indicating the presence of a valid request. If the Scan
141 // failed, there was either an error reading the next request (and the results
142 // of calling `Err()` should be inspected), or the pipe was closed and no more
143 // requests are present.
144 //
145 // Closing the pipe is Git's way to communicate that no more files will be
146 // filtered. Git expects that the LFS process exits after this event.
147 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) Scanscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#Scan().() bool {
148 o.reqscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#req., o.errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#err. = nil, nil
149
150 req, err := o.readRequestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#readRequest().()
151 if err != nil {
152 o.errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#err. = err
153 return false
154 }
155
156 o.reqscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#req. = req
157 return true
158 }
159
160 // Request returns the request read from a call to Scan(). It is available only
161 // after a call to `Scan()` has completed, and is re-initialized to nil at the
162 // beginning of the subsequent `Scan()` call.
163 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) Requestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#Request().() *Requestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request# { return o.reqscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#req. }
164
165 // Err returns any error encountered from the last call to Scan(). It is available only
166 // after a call to `Scan()` has completed, and is re-initialized to nil at the
167 // beginning of the subsequent `Scan()` call.
168 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) Errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#Err().() error { return o.errscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#err. }
169
170 // readRequest reads the headers of a request and yields an `io.Reader` which
171 // will read the body of the request. Since the body is _not_ offset, one
172 // request should be read in its entirety before consuming the next request.
173 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) readRequestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#readRequest().() (*Requestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#, error) {
174 requestList, err := o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..ReadPacketListscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#ReadPacketList().()
175 if err != nil {
176 return nil, err
177 }
178
179 req := &Requestscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#{
180 Headerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#Header.: make(map[string]string),
181 Payloadscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#Payload.: pktlinescip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/.NewPktlineReaderFromPktlinescip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/NewPktlineReaderFromPktline().(o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl., 65536),
182 }
183
184 for _, pair := range requestList {
185 v := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitNscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitN().(pair, "=", 2)
186 if len(v) > 1 {
187 req.Headerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Request#Header.[v[0]] = v[1]
188 }
189 }
190
191 return req, nil
192 }
193
194 // WriteList writes a list of strings to the underlying pktline data stream in
195 // pktline format.
196 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) WriteListscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#WriteList().(list []string) error {
197 return o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..WritePacketListscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#WritePacketList().(list)
198 }
199
200 func (o *FilterProcessScannerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#) WriteStatusscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#WriteStatus().(status FilterProcessStatusscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessStatus#) error {
201 return o.plscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessScanner#pl..WritePacketListscip-go gomod github.com/git-lfs/pktline 06e9096e2825 `github.com/git-lfs/pktline`/Pktline#WritePacketList().([]string{"status=" + status.Stringscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/FilterProcessStatus#String().()})
202 }