MCPcopy Create free account
hub / github.com/bufbuild/buf / getRawRefForInputConfig

Method getRawRefForInputConfig

private/buf/buffetch/internal/ref_parser.go:205–280  ·  view source on GitHub ↗
(
	inputConfig bufconfig.InputConfig,
)

Source from the content-addressed store, hash-verified

203}
204
205func (a *refParser) getRawRefForInputConfig(
206 inputConfig bufconfig.InputConfig,
207) (*RawRef, error) {
208 rawRef := &RawRef{
209 Path: inputConfig.Location(),
210 UnrecognizedOptions: make(map[string]string),
211 }
212 if a.rawRefProcessor != nil {
213 if err := a.rawRefProcessor(rawRef); err != nil {
214 return nil, err
215 }
216 }
217 switch inputConfig.Type() {
218 case bufconfig.InputConfigTypeModule:
219 rawRef.Format = "mod"
220 case bufconfig.InputConfigTypeDirectory:
221 rawRef.Format = "dir"
222 case bufconfig.InputConfigTypeGitRepo:
223 rawRef.Format = "git"
224 case bufconfig.InputConfigTypeProtoFile:
225 rawRef.Format = "protofile"
226 case bufconfig.InputConfigTypeTarball:
227 rawRef.Format = "tar"
228 case bufconfig.InputConfigTypeZipArchive:
229 rawRef.Format = "zip"
230 case bufconfig.InputConfigTypeBinaryImage:
231 rawRef.Format = "binpb"
232 case bufconfig.InputConfigTypeJSONImage:
233 rawRef.Format = "json"
234 case bufconfig.InputConfigTypeTextImage:
235 rawRef.Format = "txtpb"
236 case bufconfig.InputConfigTypeYAMLImage:
237 rawRef.Format = "yaml"
238 default:
239 return nil, syserror.Newf("unknown InputConfigType: %v", inputConfig.Type())
240 }
241 // This cannot be set ahead of time, it can only happen after all options are read.
242 if inputConfig.Type() == bufconfig.InputConfigTypeGitRepo {
243 // TODO FUTURE: might change rawRef.Depth into a pointer or use some other way to handle the case where 0 is specified
244 if inputConfig.Depth() != nil {
245 if *inputConfig.Depth() == 0 {
246 return nil, NewDepthZeroError()
247 }
248 rawRef.GitDepth = *inputConfig.Depth()
249 }
250 rawRef.GitBranch = inputConfig.Branch()
251 rawRef.GitCommitOrTag = inputConfig.CommitOrTag()
252 rawRef.GitRef = inputConfig.Ref()
253 rawRef.GitRecurseSubmodules = inputConfig.RecurseSubmodules()
254 if rawRef.GitDepth == 0 {
255 // Default to 1
256 rawRef.GitDepth = 1
257 if rawRef.GitRef != "" {
258 // Default to 50 when using ref
259 rawRef.GitDepth = 50
260 }
261 }
262 }

Callers 1

Calls 15

validateRawRefMethod · 0.95
NewfFunction · 0.92
NewDepthZeroErrorFunction · 0.85
parseCompressionTypeFunction · 0.85
parseSubDirPathFunction · 0.85
LocationMethod · 0.65
TypeMethod · 0.65
DepthMethod · 0.65
BranchMethod · 0.65
CommitOrTagMethod · 0.65
RefMethod · 0.65
RecurseSubmodulesMethod · 0.65

Tested by

no test coverage detected