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

Function GetInputConfigForRef

private/buf/buffetch/internal/internal.go:904–954  ·  view source on GitHub ↗

GetInputConfigForRef returns the input config for the ref. A string is also passed because if the ref is a git ref, it would only have a git.Name, instead of a git branch, a git ref and a git tag. Therefore the original string is passed.

(ref Ref, value string)

Source from the content-addressed store, hash-verified

902// passed because if the ref is a git ref, it would only have a git.Name, instead
903// of a git branch, a git ref and a git tag. Therefore the original string is passed.
904func GetInputConfigForRef(ref Ref, value string) (bufconfig.InputConfig, error) {
905 _, options, err := getRawPathAndOptions(value)
906 if err != nil {
907 return nil, err
908 }
909 switch t := ref.(type) {
910 case ArchiveRef:
911 switch t.ArchiveType() {
912 case ArchiveTypeZip:
913 return bufconfig.NewZipArchiveInputConfig(
914 t.Path(),
915 t.SubDirPath(),
916 t.StripComponents(),
917 )
918 case ArchiveTypeTar:
919 return bufconfig.NewTarballInputConfig(
920 t.Path(),
921 t.SubDirPath(),
922 t.CompressionType().String(),
923 t.StripComponents(),
924 )
925 default:
926 return nil, fmt.Errorf("invalid archive type: %v", t.ArchiveType())
927 }
928 case DirRef:
929 return bufconfig.NewDirectoryInputConfig(
930 t.Path(),
931 )
932 case ModuleRef:
933 return bufconfig.NewModuleInputConfig(
934 t.ModuleRef().String(),
935 )
936 case ProtoFileRef:
937 return bufconfig.NewProtoFileInputConfig(
938 t.Path(),
939 t.IncludePackageFiles(),
940 )
941 case GitRef:
942 return bufconfig.NewGitRepoInputConfig(
943 t.Path(),
944 t.SubDirPath(),
945 options["branch"],
946 options["tag"],
947 options["ref"],
948 toPointer(t.Depth()),
949 t.RecurseSubmodules(),
950 )
951 default:
952 return nil, fmt.Errorf("unexpected Ref of type %T", ref)
953 }
954}
955
956func toPointer[T any](value T) *T {
957 return &value

Callers 1

GetInputConfigForStringFunction · 0.92

Calls 15

NewZipArchiveInputConfigFunction · 0.92
NewTarballInputConfigFunction · 0.92
NewDirectoryInputConfigFunction · 0.92
NewModuleInputConfigFunction · 0.92
NewProtoFileInputConfigFunction · 0.92
NewGitRepoInputConfigFunction · 0.92
getRawPathAndOptionsFunction · 0.85
toPointerFunction · 0.70
ArchiveTypeMethod · 0.65
PathMethod · 0.65
SubDirPathMethod · 0.65
StripComponentsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…