MCPcopy
hub / github.com/git-lfs/git-lfs / Batch

Method Batch

tq/api.go:68–114  ·  view source on GitHub ↗
(remote string, bReq *batchRequest)

Source from the content-addressed store, hash-verified

66}
67
68func (c *tqClient) Batch(remote string, bReq *batchRequest) (*BatchResponse, error) {
69 bRes := &BatchResponse{}
70 if len(bReq.Objects) == 0 {
71 return bRes, nil
72 }
73
74 if len(bReq.TransferAdapterNames) == 1 && bReq.TransferAdapterNames[0] == "basic" {
75 bReq.TransferAdapterNames = nil
76 }
77
78 bRes.endpoint = c.Endpoints.Endpoint(bReq.Operation, remote)
79 requestedAt := time.Now()
80
81 req, err := c.NewRequest("POST", bRes.endpoint, "objects/batch", bReq)
82 if err != nil {
83 return nil, errors.Wrap(err, tr.Tr.Get("batch request"))
84 }
85
86 tracerx.Printf("api: batch %d files", len(bReq.Objects))
87
88 req = c.Client.LogRequest(req, "lfs.batch")
89 res, err := c.DoAPIRequestWithAuth(remote, lfshttp.WithRetries(req, c.MaxRetries()))
90 if err != nil {
91 tracerx.Printf("api error: %s", err)
92 return nil, errors.Wrap(err, tr.Tr.Get("batch response"))
93 }
94
95 if err := lfshttp.DecodeJSON(res, bRes); err != nil {
96 return bRes, errors.Wrap(err, tr.Tr.Get("batch response"))
97 }
98
99 if bRes.HashAlgorithm != "" && bRes.HashAlgorithm != "sha256" {
100 return bRes, errors.Wrap(errors.New(tr.Tr.Get("unsupported hash algorithm")), tr.Tr.Get("batch response"))
101 }
102
103 if res.StatusCode != 200 {
104 return nil, lfshttp.NewStatusCodeError(res)
105 }
106
107 for _, obj := range bRes.Objects {
108 for _, a := range obj.Actions {
109 a.createdAt = requestedAt
110 }
111 }
112
113 return bRes, nil
114}

Callers 3

TestAPIBatchFunction · 0.95
TestAPIBatchOnlyBasicFunction · 0.95
TestAPIBatchEmptyObjectsFunction · 0.95

Calls 11

MaxRetriesMethod · 0.95
WrapFunction · 0.92
WithRetriesFunction · 0.92
DecodeJSONFunction · 0.92
NewFunction · 0.92
NewStatusCodeErrorFunction · 0.92
DoAPIRequestWithAuthMethod · 0.80
EndpointMethod · 0.65
GetMethod · 0.65
NewRequestMethod · 0.45
LogRequestMethod · 0.45

Tested by 3

TestAPIBatchFunction · 0.76
TestAPIBatchOnlyBasicFunction · 0.76
TestAPIBatchEmptyObjectsFunction · 0.76