lfs

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: BSD-3-Clause, MIT Imports: 34 Imported by: 4

Documentation

Overview

Package lfs brings together the core LFS functionality NOTE: Subject to change, do not rely on this package from outside git-lfs source

Index

Constants

View Source
const (
	ScanRefsMode          = ScanningMode(iota) // 0 - or default scan mode
	ScanAllMode           = ScanningMode(iota)
	ScanRangeToRemoteMode = ScanningMode(iota)
)
View Source
const (
	LogDiffAdditions = LogDiffDirection('+') // include '+' diffs
	LogDiffDeletions = LogDiffDirection('-') // include '-' diffs
)
View Source
const (
	PlatformWindows      = Platform(iota)
	PlatformLinux        = Platform(iota)
	PlatformOSX          = Platform(iota)
	PlatformOther        = Platform(iota) // most likely a *nix variant e.g. freebsd
	PlatformUndetermined = Platform(iota)
)

Variables

This section is empty.

Functions

func CopyFileContents

func CopyFileContents(cfg *config.Configuration, src string, dst string) error

func EncodePointer

func EncodePointer(writer io.Writer, pointer *Pointer) (int, error)

func Environ

func Environ(cfg *config.Configuration, manifest tq.Manifest, envOverrides map[string]string) []string

func IsCallbackMissing

func IsCallbackMissing(err error) bool

IsCallbackMissing returns a boolean indicating whether the error is reporting that a GitScanner is missing a required GitScannerCallback.

func IsWindows

func IsWindows() bool

Are we running on Windows? Need to handle some extra path shenanigans

func LinkOrCopy

func LinkOrCopy(cfg *config.Configuration, src string, dst string) error

func LinkOrCopyFromReference

func LinkOrCopyFromReference(cfg *config.Configuration, oid string, size int64) error

func TempFile

func TempFile(cfg *config.Configuration, pattern string) (*os.File, error)

TempFile creates a temporary file in the temporary directory specified by the configuration that has the proper permissions for the repository. On success, it returns an open, non-nil *os.File, and the caller is responsible for closing and/or removing it. On failure, the temporary file is automatically cleaned up and an error returned.

This function is designed to handle only temporary files that will be renamed into place later somewhere within the Git repository.

Types

type Attribute

type Attribute struct {
	// The Section of an Attribute refers to the location at which all
	// properties are relative to. For example, for a Section with the value
	// "core", Git will produce something like:
	//
	// [core]
	//	autocrlf = true
	//	...
	Section string

	// The Properties of an Attribute refer to all of the keys and values
	// that define that Attribute.
	Properties map[string]string
	// Previous values of these attributes that can be automatically upgraded
	Upgradeables map[string][]string
}

Attribute wraps the structure and some operations of Git's conception of an "attribute", as defined here: http://git-scm.com/docs/gitattributes.

func (*Attribute) Install

func (a *Attribute) Install(opt *FilterOptions) error

Install instructs Git to set all keys and values relative to the root location of this Attribute. For any particular key/value pair, if a matching key is already set, it will be overridden if it is either a) empty, or b) the `force` argument is passed as true. If an attribute is already set to a different value than what is given, and force is false, an error will be returned immediately, and the rest of the attributes will not be set.

func (*Attribute) Uninstall

func (a *Attribute) Uninstall(opt *FilterOptions) error

Uninstall removes all properties in the path of this property.

type ByPriority

type ByPriority []*PointerExtension

func (ByPriority) Len

func (p ByPriority) Len() int

func (ByPriority) Less

func (p ByPriority) Less(i, j int) bool

func (ByPriority) Swap

func (p ByPriority) Swap(i, j int)

type DiffIndexEntry

type DiffIndexEntry struct {
	// SrcMode is the file mode of the "src" file, stored as a string-based
	// octal.
	SrcMode string
	// DstMode is the file mode of the "dst" file, stored as a string-based
	// octal.
	DstMode string
	// SrcSha is the Git blob ID of the "src" file.
	SrcSha string
	// DstSha is the Git blob ID of the "dst" file.
	DstSha string
	// Status is the status of the file in the index.
	Status DiffIndexStatus
	// StatusScore is the optional "score" associated with a particular
	// status.
	StatusScore int
	// SrcName is the name of the file in its "src" state as it appears in
	// the index.
	SrcName string
	// DstName is the name of the file in its "dst" state as it appears in
	// the index.
	DstName string
}

DiffIndexEntry holds information about a single item in the results of a `git diff-index` command.

type DiffIndexScanner

type DiffIndexScanner struct {
	// contains filtered or unexported fields
}

DiffIndexScanner scans the output of the `git diff-index` command.

func NewDiffIndexScanner

func NewDiffIndexScanner(ref string, cached bool, refresh bool, workingDir string) (*DiffIndexScanner, error)

NewDiffIndexScanner initializes a new `DiffIndexScanner` scanning at the given ref, "ref".

If "cache" is given, the DiffIndexScanner will scan for differences between the given ref and the index. If "cache" is _not_ given, DiffIndexScanner will scan for differences between the given ref and the currently checked out tree.

If "refresh" is given, the DiffIndexScanner will refresh the index. This is probably what you want in all cases except fsck, where invoking a filtering operation would be undesirable due to the possibility of corruption. It can also be disabled where another operation will have refreshed the index.

If "workingDir" is set, the DiffIndexScanner will be run in the given directory. Otherwise, the DiffIndexScanner will be run in the current working directory.

If any error was encountered in starting the command or closing its `stdin`, that error will be returned immediately. Otherwise, a `*DiffIndexScanner` will be returned with a `nil` error.

func (*DiffIndexScanner) Entry

func (s *DiffIndexScanner) Entry() *DiffIndexEntry

Entry returns the last entry that was Scan()'d by the DiffIndexScanner.

func (*DiffIndexScanner) Err

func (s *DiffIndexScanner) Err() error

Entry returns the last error that was encountered by the DiffIndexScanner.

func (*DiffIndexScanner) Scan

func (s *DiffIndexScanner) Scan() bool

Scan advances the scan line and yields either a new value for Entry(), or an Err(). It returns true or false, whether or not it can continue scanning for more entries.

type DiffIndexStatus

type DiffIndexStatus rune

Status represents the status of a file that appears in the output of `git diff-index`.

More information about each of its valid instances can be found: https://git-scm.com/docs/git-diff-index

const (
	StatusAddition     DiffIndexStatus = 'A'
	StatusCopy         DiffIndexStatus = 'C'
	StatusDeletion     DiffIndexStatus = 'D'
	StatusModification DiffIndexStatus = 'M'
	StatusRename       DiffIndexStatus = 'R'
	StatusTypeChange   DiffIndexStatus = 'T'
	StatusUnmerged     DiffIndexStatus = 'U'
	StatusUnknown      DiffIndexStatus = 'X'
)

func (DiffIndexStatus) Format

func (s DiffIndexStatus) Format(state fmt.State, c rune)

Format implements fmt.Formatter. If printed as "%+d", "%+s", or "%+v", the status will be written out as an English word: i.e., "addition", "copy", "deletion", etc.

If the '+' flag is not given, the shorthand will be used instead: 'A', 'C', and 'D', respectively.

If any other format verb is given, this function will panic().

func (DiffIndexStatus) String

func (s DiffIndexStatus) String() string

String implements fmt.Stringer by returning a human-readable name for each status.

type FetchPruneConfig

type FetchPruneConfig struct {
	// The number of days prior to current date for which (local) refs other than HEAD
	// will be fetched with --recent (default 7, 0 = only fetch HEAD)
	FetchRecentRefsDays int
	// Makes the FetchRecentRefsDays option apply to remote refs from fetch source as well (default true)
	FetchRecentRefsIncludeRemotes bool
	// number of days prior to latest commit on a ref that we'll fetch previous
	// LFS changes too (default 0 = only fetch at ref)
	FetchRecentCommitsDays int
	// Whether to always fetch recent even without --recent
	FetchRecentAlways bool
	// Number of days added to FetchRecent*; data outside combined window will be
	// deleted when prune is run. (default 3)
	PruneOffsetDays int
	// Always verify with remote before pruning reachable objects
	PruneVerifyRemoteAlways bool
	// When verifiying, always verify all reachable and unreachable objects with remote (default false)
	PruneVerifyUnreachableAlways bool
	// Name of remote to check for unpushed and verify checks
	PruneRemoteName string
	// Whether to ignore all recent options.
	PruneRecent bool
	// Whether to delete everything pushed.
	PruneForce bool
}

FetchPruneConfig collects together the config options that control fetching and pruning

func NewFetchPruneConfig

func NewFetchPruneConfig(git config.Environment) FetchPruneConfig

type FilterOptions

type FilterOptions struct {
	GitConfig  *git.Configuration
	Force      bool
	File       string
	Local      bool
	Worktree   bool
	System     bool
	SkipSmudge bool
}

FilterOptions serves as an argument to Install().

func (*FilterOptions) Install

func (o *FilterOptions) Install() error

func (*FilterOptions) Uninstall

func (o *FilterOptions) Uninstall() error

type GitFilter

type GitFilter struct {
	// contains filtered or unexported fields
}

GitFilter provides clean and smudge capabilities

func NewGitFilter

func NewGitFilter(cfg *config.Configuration) *GitFilter

NewGitFilter initializes a new *GitFilter

func (*GitFilter) Clean

func (f *GitFilter) Clean(reader io.Reader, fileName string, fileSize int64, cb tools.CopyCallback) (*cleanedAsset, error)

func (*GitFilter) CopyCallbackFile

func (f *GitFilter) CopyCallbackFile(event, filename string, index, totalFiles int) (tools.CopyCallback, *os.File, error)

func (*GitFilter) ObjectPath

func (f *GitFilter) ObjectPath(oid string) (string, error)

func (*GitFilter) RemoteRef

func (f *GitFilter) RemoteRef() *git.Ref

func (*GitFilter) Smudge

func (f *GitFilter) Smudge(writer io.Writer, ptr *Pointer, workingfile string, download bool, manifest tq.Manifest, cb tools.CopyCallback) (int64, error)

func (*GitFilter) SmudgeToFile

func (f *GitFilter) SmudgeToFile(filename string, ptr *Pointer, download bool, manifest tq.Manifest, cb tools.CopyCallback) error

type GitScanner

type GitScanner struct {
	Filter *filepathfilter.Filter
	// contains filtered or unexported fields
}

GitScanner scans objects in a Git repository for LFS pointers.

func NewGitScanner

func NewGitScanner(cfg *config.Configuration, cb GitScannerFoundPointer) *GitScanner

NewGitScanner initializes a *GitScanner for a Git repository in the current working directory.

func NewGitScannerForPush added in v3.4.0

func NewGitScannerForPush(cfg *config.Configuration, remote string, cb GitScannerFoundLockable, potentialLockables GitScannerSet) *GitScanner

NewGitScannerForPush initializes a *GitScanner for a Git repository in the current working directory, to scan for objects to push to the given remote and for locks on non-LFS objects held by other users. Needed for ScanMultiRangeToRemote(), and for ScanRefWithDeleted() when used for a "git lfs push --all" command.

func (*GitScanner) ScanAll

func (s *GitScanner) ScanAll(cb GitScannerFoundPointer) error

ScanAll scans through all unique objects in the repository, including objects that have been modified or deleted.

func (*GitScanner) ScanIndex

func (s *GitScanner) ScanIndex(ref string, workingDir string, cb GitScannerFoundPointer) error

ScanIndex scans the git index for modified LFS objects.

func (*GitScanner) ScanMultiRangeToRemote

func (s *GitScanner) ScanMultiRangeToRemote(include string, exclude []string, cb GitScannerFoundPointer) error

ScanMultiRangeToRemote scans through all unique objects reachable from the "include" ref but not reachable from any "exclude" refs and which the given remote does not have. See NewGitScannerForPush().

func (*GitScanner) ScanPreviousVersions

func (s *GitScanner) ScanPreviousVersions(ref string, since time.Time, cb GitScannerFoundPointer) error

ScanPreviousVersions scans changes reachable from ref (commit) back to since. Returns channel of pointers for *previous* versions that overlap that time. Does not include pointers which were still in use at ref (use ScanRefsToChan for that)

func (*GitScanner) ScanRef

func (s *GitScanner) ScanRef(ref string, cb GitScannerFoundPointer) error

ScanRef scans through all unique objects in the current ref, excluding objects that have been modified or deleted before the ref.

func (*GitScanner) ScanRefByTree

func (s *GitScanner) ScanRefByTree(ref string, cb GitScannerFoundPointer) error

ScanRefByTree scans through all objects in the current ref, excluding objects that have been modified or deleted before the ref. Objects which appear in multiple trees will be visited once per tree.

func (*GitScanner) ScanRefRange

func (s *GitScanner) ScanRefRange(include, exclude string, cb GitScannerFoundPointer) error

ScanRefRange scans through all unique objects reachable from the "include" ref but not reachable from the "exclude" ref, including objects that have been modified or deleted.

func (*GitScanner) ScanRefRangeByTree

func (s *GitScanner) ScanRefRangeByTree(include, exclude string, cb GitScannerFoundPointer) error

ScanRefRangeByTree scans through all objects reachable from the "include" ref but not reachable from the "exclude" ref, including objects that have been modified or deleted. Objects which appear in multiple trees will be visited once per tree.

func (*GitScanner) ScanRefWithDeleted

func (s *GitScanner) ScanRefWithDeleted(ref string, cb GitScannerFoundPointer) error

ScanRefWithDeleted scans through all unique objects in the given ref, including objects that have been modified or deleted.

func (*GitScanner) ScanRefs

func (s *GitScanner) ScanRefs(include, exclude []string, cb GitScannerFoundPointer) error

ScanRefs scans through all unique objects reachable from the "include" refs but not reachable from any "exclude" refs, including objects that have been modified or deleted.

func (*GitScanner) ScanStashed

func (s *GitScanner) ScanStashed(cb GitScannerFoundPointer) error

ScanStashed scans for all LFS pointers referenced solely by a stash

func (*GitScanner) ScanTree

func (s *GitScanner) ScanTree(ref string, cb GitScannerFoundPointer) error

ScanTree takes a ref and returns WrappedPointer objects in the tree at that ref. Differs from ScanRefs in that multiple files in the tree with the same content are all reported.

func (*GitScanner) ScanUnpushed

func (s *GitScanner) ScanUnpushed(remote string, cb GitScannerFoundPointer) error

ScanUnpushed scans history for all LFS pointers which have been added but not pushed to the named remote. remote can be left blank to mean 'any remote'.

type GitScannerFoundLockable

type GitScannerFoundLockable func(filename string)

type GitScannerFoundPointer

type GitScannerFoundPointer func(*WrappedPointer, error)

type GitScannerSet

type GitScannerSet interface {
	Contains(string) bool
}

type Hook

type Hook struct {
	Type     string
	Contents string
	Dir      string
	// contains filtered or unexported fields
}

A Hook represents a githook as described in http://git-scm.com/docs/githooks. Hooks have a type, which is the type of hook that they are, and a body, which represents the thing they will execute when invoked by Git.

func LoadHooks

func LoadHooks(hookDir string, cfg *config.Configuration) []*Hook

func NewStandardHook

func NewStandardHook(theType, hookDir string, upgradeables []string, cfg *config.Configuration) *Hook

NewStandardHook creates a new hook using the template script calling 'git lfs theType'

func (*Hook) Exists

func (h *Hook) Exists() bool

func (*Hook) Install

func (h *Hook) Install(force bool) error

Install installs this Git hook on disk, or upgrades it if it does exist, and is upgradeable. It will create a hooks directory relative to the local Git directory. It returns and halts at any errors, and returns nil if the operation was a success.

func (*Hook) Path

func (h *Hook) Path() string

Path returns the desired (or actual, if installed) location where this hook should be installed. It returns an absolute path in all cases.

func (*Hook) Uninstall

func (h *Hook) Uninstall() error

Uninstall removes the hook on disk so long as it matches the current version, or any of the past versions of this hook.

func (*Hook) Upgrade

func (h *Hook) Upgrade() error

Upgrade upgrades the (assumed to be) existing git hook to the current contents. A hook is considered "upgrade-able" if its contents are matched in the member variable `Upgradeables`. It halts and returns any errors as they arise.

type LogDiffDirection

type LogDiffDirection byte

When scanning diffs with parseScannerLogOutput(), the direction of diff to include data from, i.e., '+' or '-'. Depending on what you're scanning for either might be useful.

type PathConverter

type PathConverter interface {
	Convert(string) string
}

func NewCurrentToRepoPathConverter

func NewCurrentToRepoPathConverter(cfg *config.Configuration) (PathConverter, error)

Convert filenames expressed relative to the current directory to be relative to the repo root. Useful when calling git with arguments that requires them to be rooted but the user is in a subdir of their repo & expects to use relative args

func NewCurrentToRepoPatternConverter

func NewCurrentToRepoPatternConverter(cfg *config.Configuration) (PathConverter, error)

Convert filenames expressed relative to the current directory to be relative to the repo root and convert them into wildmatch patterns.

func NewRepoToCurrentPathConverter

func NewRepoToCurrentPathConverter(cfg *config.Configuration) (PathConverter, error)

Convert filenames expressed relative to the root of the repo relative to the current working dir. Useful when needing to calling git with results from a rooted command, but the user is in a subdir of their repo

type Platform

type Platform int

func GetPlatform

func GetPlatform() Platform

type Pointer

type Pointer struct {
	Version    string
	Oid        string
	Size       int64
	OidType    string
	Extensions []*PointerExtension
	Canonical  bool
}

func DecodeFrom

func DecodeFrom(reader io.Reader) (*Pointer, io.Reader, error)

DecodeFrom decodes an *lfs.Pointer from the given io.Reader, "reader". If the pointer encoded in the reader could successfully be read and decoded, it will be returned with a nil error.

If the pointer could not be decoded, an io.Reader containing the entire blob's data will be returned, along with a parse error.

func DecodePointer

func DecodePointer(reader io.Reader) (*Pointer, error)

func DecodePointerFromBlob

func DecodePointerFromBlob(b *gitobj.Blob) (*Pointer, error)

func DecodePointerFromFile

func DecodePointerFromFile(file string) (*Pointer, error)

func EmptyPointer

func EmptyPointer() *Pointer

func NewPointer

func NewPointer(oid string, size int64, exts []*PointerExtension) *Pointer

func (*Pointer) Encode

func (p *Pointer) Encode(writer io.Writer) (int, error)

func (*Pointer) Encoded

func (p *Pointer) Encoded() string

type PointerChannelWrapper

type PointerChannelWrapper struct {
	*tools.BaseChannelWrapper
	Results <-chan *WrappedPointer
}

ChannelWrapper for pointer Scan* functions to more easily return async error data via Wait() See NewPointerChannelWrapper for construction / use

func NewPointerChannelWrapper

func NewPointerChannelWrapper(pointerChan <-chan *WrappedPointer, errorChan <-chan error) *PointerChannelWrapper

Construct a new channel wrapper for WrappedPointer Caller can use s.Results directly for normal processing then call Wait() to finish & check for errors Scan function is required to create error channel large enough not to block (usually 1 is ok)

type PointerExtension

type PointerExtension struct {
	Name     string
	Priority int
	Oid      string
	OidType  string
}

A PointerExtension is parsed from the Git LFS Pointer file.

func NewPointerExtension

func NewPointerExtension(name string, priority int, oid string) *PointerExtension

type PointerScanner

type PointerScanner struct {
	// contains filtered or unexported fields
}

func NewPointerScanner

func NewPointerScanner(gitEnv, osEnv config.Environment) (*PointerScanner, error)

func (*PointerScanner) BlobSHA

func (s *PointerScanner) BlobSHA() string

func (*PointerScanner) Close

func (s *PointerScanner) Close() error

func (*PointerScanner) ContentsSha

func (s *PointerScanner) ContentsSha() string

func (*PointerScanner) Err

func (s *PointerScanner) Err() error

func (*PointerScanner) Pointer

func (s *PointerScanner) Pointer() *WrappedPointer

func (*PointerScanner) Scan

func (s *PointerScanner) Scan(sha string) bool

type ScanningMode

type ScanningMode int

type StringChannelWrapper

type StringChannelWrapper struct {
	*tools.BaseChannelWrapper
	Results <-chan string
}

ChannelWrapper for string channel functions to more easily return async error data via Wait() Caller can use s.Results directly for normal processing then call Wait() to finish & check for errors See NewStringChannelWrapper for construction / use

func NewStringChannelWrapper

func NewStringChannelWrapper(stringChan <-chan string, errorChan <-chan error) *StringChannelWrapper

Construct a new channel wrapper for string Caller can use s.Results directly for normal processing then call Wait() to finish & check for errors

type TreeBlobChannelWrapper

type TreeBlobChannelWrapper struct {
	*tools.BaseChannelWrapper
	Results <-chan git.TreeBlob
}

ChannelWrapper for TreeBlob channel functions to more easily return async error data via Wait() See NewTreeBlobChannelWrapper for construction / use

func NewTreeBlobChannelWrapper

func NewTreeBlobChannelWrapper(treeBlobChan <-chan git.TreeBlob, errorChan <-chan error) *TreeBlobChannelWrapper

Construct a new channel wrapper for TreeBlob Caller can use s.Results directly for normal processing then call Wait() to finish & check for errors

type WrappedPointer

type WrappedPointer struct {
	Sha1    string
	Name    string
	SrcName string
	Status  string
	*Pointer
}

WrappedPointer wraps a pointer.Pointer and provides the git sha1 and the file name associated with the object, taken from the rev-list output.

Jump to

Keyboard shortcuts

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