model

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package model provides utility functions for modeling a git repository in OCI.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedReferenceType indicates a Git reference type is not supported.
	ErrUnsupportedReferenceType = errors.New("unsupported reference type")
	// ErrReferenceNotFound indicates a reference does not exist in the OCI remote.
	ErrReferenceNotFound = errors.New("reference not found in remote data model")
)
View Source
var ErrLFSManifestNotFound = fmt.Errorf("LFS manifest not found")

ErrLFSManifestNotFound indicates an LFS manifest was not found.

Functions

This section is empty.

Types

type FetchLFSOptions

type FetchLFSOptions struct {
	Progress *ProgressOptions
}

FetchLFSOptions define optional parameters for fetching LFS files.

type LFSModeler

type LFSModeler interface {
	Modeler
	ReadOnlyLFSModeler

	// PushLFSManifest upload the git-lfs OCI data model in it's current state.
	PushLFSManifest(ctx context.Context, subject ocispec.Descriptor) (ocispec.Descriptor, error)
	// PushLFSFile adds a git-lfs file as a layer to the git-lfs OCI data model
	// and pushes it to the remote.
	PushLFSFile(ctx context.Context, path string, opts *PushLFSOptions) (ocispec.Descriptor, error)
}

LFSModeler extends Modeler with LFS support.

func NewLFSModeler

func NewLFSModeler(ref registry.Reference, fstore *file.Store, gt oras.GraphTarget) LFSModeler

NewLFSModeler initializes a new git-lfs modeler.

type Modeler

type Modeler interface {
	ReadOnlyModeler

	// Push uploads the Git OCI data model in its current state.
	Push(ctx context.Context, referrerUpdates ...ReferrerUpdater) (ocispec.Descriptor, error)
	// AddPack adds a packfile as a layer to the Git OCI data model and updates
	// the remote references whose objs are included in the packfile.
	AddPack(ctx context.Context, path string, refs ...*plumbing.Reference) (ocispec.Descriptor, error)
	// UpdateRef updates a Git reference and the object it points to in the
	// Git OCI data model. Useful for updating a reference where its object
	// is within a packfile that already exists in the remote OCI registry.
	UpdateRef(ctx context.Context, ref *plumbing.Reference, ociLayer digest.Digest) error
	// DeleteRef removes a reference from the remote. The commit remains.
	DeleteRef(ctx context.Context, refName plumbing.ReferenceName) error
}

Modeler extends ReadOnlyModeler with updating and pushing a Git OCI data model to an OCI registry.

func NewModeler

func NewModeler(ref registry.Reference, fstore *file.Store, gt oras.GraphTarget) Modeler

NewModeler initializes a new git modeler.

type ProgressOptions

type ProgressOptions struct {
	// Info enable receiving status information on how many bytes has been pushed.
	Info chan progress.Progress
	// ProgressInterval is the sending tick rate for progress updates.
	// Noop if Info is not set.
	Interval time.Duration
}

ProgressOptions allow for enabling and customizing LFS file push progress info.

type PushLFSOptions

type PushLFSOptions struct {
	Progress *ProgressOptions
}

PushLFSOptions define optional parameters for pushing LFS files.

type ReadOnlyLFSModeler

type ReadOnlyLFSModeler interface {
	ReadOnlyModeler

	// FetchLFS pulls git-lfs OCI metadata from a remote. It does not pull layers.
	FetchLFS(ctx context.Context) (ocispec.Descriptor, error)
	// FetchLFSOrDefault extends [LFSModeler.Fetch] to initialize an empty OCI
	// manifest if the remote does not exist.
	FetchLFSOrDefault(ctx context.Context) (ocispec.Descriptor, error)
	// FetchLFSLayer fetches an LFS file from a layer in the git-lfs OCI data model.
	FetchLFSLayer(ctx context.Context, dgst digest.Digest, opts *FetchLFSOptions) (io.ReadCloser, error)
}

ReadOnlyLFSModeler extends ReadOnlyModeler to support reading Git LFS OCI data model.

type ReadOnlyModeler

type ReadOnlyModeler interface {
	// Ref provides a convenient way to get the OCI remote reference where the
	// Git data model is stored.
	Ref() registry.Reference
	// Fetch pulls Git OCI metadata from a remote. It does not pull layers.
	Fetch(ctx context.Context) (ocispec.Descriptor, error)
	// FetchOrDefault extends [ReadOnlyModeler.Fetch] to initialize an empty OCI manifest and config
	// if the remote ref does not exist.
	FetchOrDefault(ctx context.Context) (ocispec.Descriptor, error)
	// FetchLayer fetches a packfile layer from OCI identifies by digest.
	FetchLayer(ctx context.Context, dgst digest.Digest) (io.ReadCloser, error)
	// FetchLayersReverse returns an iterator that walks the set of packfile layers
	// in reverse.
	FetchLayersReverse(ctx context.Context) iter.Seq2[io.ReadCloser, error]
	// ResolveRef resolves the commit hash a remote reference refers to. Returns nil, nil if
	// the ref does not exist or if not supported (head or tag ref).
	ResolveRef(ctx context.Context, refName plumbing.ReferenceName) (*plumbing.Reference, digest.Digest, error)
	// HeadRefs returns the existing head references.
	HeadRefs() map[plumbing.ReferenceName]oci.ReferenceInfo
	// TagRefs returns the existing tag references.
	TagRefs() map[plumbing.ReferenceName]oci.ReferenceInfo
	// CommitExists uses a local repository to resolve the best known OCI layer containing the commit.
	// a nil error with an empty layer digest indicates a commit does not exist.
	CommitExists(localRepo git.Repository, commit *object.Commit) (digest.Digest, error)
}

ReadOnlyModeler supports reading a Git OCI data model.

type ReferrerUpdater

type ReferrerUpdater func(ctx context.Context, subject ocispec.Descriptor) error

ReferrerUpdater updates referring manifests to a new subject descriptor.

func UpdateLFSReferrer

func UpdateLFSReferrer(m LFSModeler) ReferrerUpdater

UpdateLFSReferrer updates the subject of an existing LFS referrer manifest to a new subject descriptor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL