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

Function smudge

commands/command_smudge.go:101–147  ·  view source on GitHub ↗

smudge smudges the given `*lfs.Pointer`, "ptr", and writes its objects contents to the `io.Writer`, "to". If the encoded LFS pointer is not parse-able as a pointer, the contents of that file will instead be spooled to a temporary location on disk and then copied out back to Git. If the pointer file

(gf *lfs.GitFilter, to io.Writer, from io.Reader, filename string, skip bool, filter *filepathfilter.Filter)

Source from the content-addressed store, hash-verified

99// were non-fatal, otherwise execution will halt and the process will be
100// terminated by using the `commands.Panic()` func.
101func smudge(gf *lfs.GitFilter, to io.Writer, from io.Reader, filename string, skip bool, filter *filepathfilter.Filter) (int64, error) {
102 ptr, pbuf, perr := lfs.DecodeFrom(from)
103 if perr != nil {
104 n, err := tools.Spool(to, pbuf, cfg.TempDir())
105 if err != nil {
106 return 0, errors.Wrap(err, perr.Error())
107 }
108
109 if n != 0 {
110 return 0, errors.NewNotAPointerError(errors.New(
111 tr.Tr.Get("Unable to parse pointer at: %q", filename),
112 ))
113 }
114 return 0, nil
115 }
116
117 lfs.LinkOrCopyFromReference(cfg, ptr.Oid, ptr.Size)
118 cb, file, err := gf.CopyCallbackFile("download", filename, 1, 1)
119 if err != nil {
120 return 0, err
121 }
122
123 if skip || !filter.Allows(filename) {
124 n, err := ptr.Encode(to)
125 return int64(n), err
126 }
127
128 n, err := gf.Smudge(to, ptr, filename, true, getTransferManifestOperationRemote("download", cfg.Remote()), cb)
129 if file != nil {
130 file.Close()
131 }
132
133 if err != nil {
134 ptr.Encode(to)
135 var oid string = ptr.Oid
136 if len(oid) >= 7 {
137 oid = oid[:7]
138 }
139
140 LoggedError(err, tr.Tr.Get("Error downloading object: %s (%s): %s", filename, oid, err))
141 if !cfg.SkipDownloadErrors() {
142 os.Exit(2)
143 }
144 }
145
146 return n, nil
147}
148
149func smudgeCommand(cmd *cobra.Command, args []string) {
150 requireStdin(tr.Tr.Get("This command should be run by the Git 'smudge' filter"))

Callers 2

smudgeCommandFunction · 0.85
filterCommandFunction · 0.85

Calls 15

DecodeFromFunction · 0.92
SpoolFunction · 0.92
WrapFunction · 0.92
NewNotAPointerErrorFunction · 0.92
NewFunction · 0.92
LinkOrCopyFromReferenceFunction · 0.92
LoggedErrorFunction · 0.85
CopyCallbackFileMethod · 0.80
AllowsMethod · 0.80
EncodeMethod · 0.80
SmudgeMethod · 0.80

Tested by

no test coverage detected