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

Method Batch

tq/ssh.go:46–138  ·  view source on GitHub ↗
(remote string, bReq *batchRequest)

Source from the content-addressed store, hash-verified

44}
45
46func (a *SSHBatchClient) Batch(remote string, bReq *batchRequest) (*BatchResponse, error) {
47 bRes := &BatchResponse{TransferAdapterName: "ssh"}
48 if len(bReq.Objects) == 0 {
49 return bRes, nil
50 }
51
52 batchLines := make([]string, 0, len(bReq.Objects))
53 for _, obj := range bReq.Objects {
54 batchLines = append(batchLines, fmt.Sprintf("%s %d", obj.Oid, obj.Size))
55 }
56
57 tracerx.Printf("api: batch %d files", len(bReq.Objects))
58
59 requestedAt := time.Now()
60 args := []string{"transfer=ssh", "hash-algo=sha256"}
61 if bReq.Ref != nil {
62 args = append(args, fmt.Sprintf("refname=%s", bReq.Ref.Name))
63 }
64 status, args, lines, err := a.batchInternal(args, batchLines)
65 if err != nil {
66 return nil, err
67 }
68
69 if status != 200 {
70 msg := tr.Tr.Get("no message provided")
71 if len(lines) > 0 {
72 msg = lines[0]
73 }
74 return nil, errors.New(tr.Tr.Get("batch response: status %d from server (%s)", status, msg))
75 }
76
77 for _, arg := range args {
78 entries := strings.SplitN(arg, "=", 2)
79 if len(entries) < 2 {
80 continue
81 }
82 if entries[0] == "hash-algo" {
83 bRes.HashAlgorithm = entries[1]
84 if bRes.HashAlgorithm != "sha256" {
85 return nil, errors.New(tr.Tr.Get("batch response: unsupported hash algorithm: %q", entries[1]))
86 }
87 }
88 }
89
90 sort.Strings(lines)
91 for _, line := range lines {
92 entries := strings.Split(line, " ")
93 if len(entries) < 3 {
94 return nil, errors.New(tr.Tr.Get("batch response: malformed response: %q", line))
95 }
96 length := len(bRes.Objects)
97 if length == 0 || bRes.Objects[length-1].Oid != entries[0] {
98 bRes.Objects = append(bRes.Objects, &Transfer{Actions: make(map[string]*Action)})
99 }
100 transfer := bRes.Objects[len(bRes.Objects)-1]
101 transfer.Oid = entries[0]
102 transfer.Size, err = strconv.ParseInt(entries[1], 10, 64)
103 if err != nil {

Callers

nothing calls this directly

Calls 3

batchInternalMethod · 0.95
NewFunction · 0.92
GetMethod · 0.65

Tested by

no test coverage detected