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

Function pipeExtensions

lfs/extension.go:44–167  ·  view source on GitHub ↗
(cfg *config.Configuration, request *pipeRequest)

Source from the content-addressed store, hash-verified

42}
43
44func pipeExtensions(cfg *config.Configuration, request *pipeRequest) (response pipeResponse, err error) {
45 var extcmds []*extCommand
46 defer func() {
47 // In the case of an early return before the end of this
48 // function (in response to an error, etc), kill all running
49 // processes. Errors are ignored since the function has already
50 // returned.
51 //
52 // In the happy path, the commands will have already been
53 // `Wait()`-ed upon and e.cmd.Process.Kill() will return an
54 // error, but we can ignore it.
55 for _, e := range extcmds {
56 if e.cmd.Process != nil {
57 e.cmd.Process.Kill()
58 }
59 }
60 }()
61
62 for _, e := range request.extensions {
63 var pieces []string
64 switch request.action {
65 case "clean":
66 pieces = strings.Split(e.Clean, " ")
67 case "smudge":
68 pieces = strings.Split(e.Smudge, " ")
69 default:
70 err = errors.New(tr.Tr.Get("Invalid action: %s", request.action))
71 return
72 }
73 name := strings.Trim(pieces[0], " ")
74 var args []string
75 for _, value := range pieces[1:] {
76 arg := strings.Replace(value, "%f", request.fileName, -1)
77 args = append(args, arg)
78 }
79 var cmd *subprocess.Cmd
80 cmd, err = subprocess.ExecCommand(name, args...)
81 if err != nil {
82 return
83 }
84 ec := &extCommand{cmd: cmd, result: &pipeExtResult{name: e.Name}}
85 extcmds = append(extcmds, ec)
86 }
87
88 hasher := sha256.New()
89 pipeReader, pipeWriter := io.Pipe()
90 multiWriter := io.MultiWriter(hasher, pipeWriter)
91
92 var input io.Reader
93 var output io.WriteCloser
94 input = pipeReader
95 extcmds[0].cmd.Stdin = input
96 if response.file, err = TempFile(cfg, ""); err != nil {
97 return
98 }
99 defer response.file.Close()
100 output = response.file
101

Callers 2

CleanMethod · 0.85
readLocalFileMethod · 0.85

Calls 10

NewFunction · 0.92
ExecCommandFunction · 0.92
StdinPipeMethod · 0.80
StdoutPipeMethod · 0.80
TempFileFunction · 0.70
GetMethod · 0.65
CloseMethod · 0.65
WaitMethod · 0.65
StringMethod · 0.65
StartMethod · 0.45

Tested by

no test coverage detected