object

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BLOB_CURRENT_VERSION  uint16         = 1
	BLOB_CACHE_SIZE_LIMIT                = 1024 * 1024
	STORE                 CompressMethod = 0
	ZSTD                  CompressMethod = 1
	BROTLI                CompressMethod = 2
	DEFLATE               CompressMethod = 3
	XZ                    CompressMethod = 4
	BZ2                   CompressMethod = 5
)
View Source
const (
	BlobInlineMaxBytes = 4096
)
View Source
const DateFormat = "Mon Jan 02 15:04:05 2006 -0700"

DateFormat is the format being used in the original git implementation

View Source
const (
	// ZstandardMagic: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md#frames
	ZstandardMagic = 0xFD2FB528
)

Variables

View Source
var (
	BLOB_MAGIC       = [4]byte{'Z', 'B', 0x00, 0x01}
	BLANK_BLOB_BYTES = [16]byte{'Z', 'B', 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
)
View Source
var (
	ErrMismatchedMagic   = errors.New("mismatched magic")
	ErrMismatchedVersion = errors.New("mismatched version")
)
View Source
var (
	TREE_MAGIC      = [4]byte{'Z', 'T', 0x00, 0x01}
	ErrMaxTreeDepth = errors.New("maximum tree depth exceeded")
)

New errors defined by this package.

View Source
var (
	COMMIT_MAGIC = [4]byte{'Z', 'C', 0x00, 0x01}
)
View Source
var DefaultDiffTreeOptions = &DiffTreeOptions{
	DetectRenames:    true,
	RenameScore:      60,
	RenameLimit:      0,
	OnlyExactRenames: false,
}

DefaultDiffTreeOptions are the default and recommended options for the diff tree.

View Source
var (
	ErrCanceled = errors.New("operation canceled")
)
View Source
var (
	ErrMalformedChange = errors.New("malformed change: empty from and to")
)
View Source
var (
	ErrUnsupportedObject = errors.New("unsupported object type")
)
View Source
var (
	FRAGMENTS_MAGIC = [4]byte{'Z', 'F', 0x00, 0x01}
)
View Source
var (
	TAG_MAGIC = [4]byte{'Z', 'G', 0x00, 0x01}
)

Functions

func Base64Decode

func Base64Decode(input string, oid plumbing.Hash, b Backend) (any, error)

func Base64DecodeAs

func Base64DecodeAs[T Commit | Tree | Fragments | Tag](input string, oid plumbing.Hash, b Backend) (*T, error)

func Base64Encode

func Base64Encode(e Encoder) (string, error)

func Decode

func Decode(r io.Reader, oid plumbing.Hash, b Backend) (any, error)

func Hash

func Hash(e Encoder) plumbing.Hash

func HashFrom

func HashFrom(r io.Reader) (plumbing.Hash, error)

func IsErrDirectoryNotFound

func IsErrDirectoryNotFound(err error) bool

func IsErrEntryNotFound

func IsErrEntryNotFound(err error) bool

func NewTreeRootNode

func NewTreeRootNode(t *Tree, m noder.Matcher, conflictDetection bool) noder.Noder

NewTreeRootNode returns the root node of a Tree

func PathRenameCombine added in v0.16.0

func PathRenameCombine(from, to string) string

func StatsWriteTo

func StatsWriteTo(w io.Writer, fileStats []FileStat, color bool)

StatsWriteTo prints the stats of changes in content of files. Original implementation: https://github.com/git/git/blob/1a87c842ece327d03d08096395969aca5e0a6996/diff.c#L2615 Parts of the output: <pad><filename><pad>|<pad><changeNumber><pad><+++/---><newline> example: " main.go | 10 +++++++--- "

Types

type Backend

type Backend interface {
	Commit(ctx context.Context, oid plumbing.Hash) (*Commit, error)
	Tree(ctx context.Context, oid plumbing.Hash) (*Tree, error)
	Fragments(ctx context.Context, oid plumbing.Hash) (*Fragments, error)
	Tag(ctx context.Context, oid plumbing.Hash) (*Tag, error)
	Blob(ctx context.Context, oid plumbing.Hash) (*Blob, error)
}

type Blob

type Blob struct {
	Contents io.Reader
	Size     int64
	// contains filtered or unexported fields
}

func NewBlob

func NewBlob(raw io.ReadCloser) (*Blob, error)

func (*Blob) Close

func (b *Blob) Close() error

type Change

type Change struct {
	From ChangeEntry
	To   ChangeEntry
}

Change values represent a detected change between two git trees. For modifications, From is the original status of the node and To is its final status. For insertions, From is the zero value and for deletions To is the zero value.

func (*Change) Action

func (c *Change) Action() (merkletrie.Action, error)

Action returns the kind of action represented by the change, an insertion, a deletion or a modification.

func (*Change) Files

func (c *Change) Files() (from, to *File, err error)

Files returns the files before and after a change. For insertions from will be nil. For deletions to will be nil.

func (*Change) Name added in v0.15.0

func (c *Change) Name() string

func (*Change) String

func (c *Change) String() string

type ChangeEntry

type ChangeEntry struct {
	// Full path of the node using "/" as separator.
	Name string
	// Parent tree of the node that has changed.
	Tree *Tree
	// The entry of the node.
	TreeEntry TreeEntry
}

ChangeEntry values represent a node that has suffered a change.

func (*ChangeEntry) Equal

func (e *ChangeEntry) Equal(o *ChangeEntry) bool

type Changes

type Changes []*Change

Changes represents a collection of changes between two git trees. Implements sort.Interface lexicographically over the path of the changed files.

func DetectRenames

func DetectRenames(
	ctx context.Context,
	changes Changes,
	opts *DiffTreeOptions,
) (Changes, error)

DetectRenames detects the renames in the given changes on two trees with the given options. It will return the given changes grouping additions and deletions into modifications when possible. If options is nil, the default diff tree options will be used.

func DiffTree

func DiffTree(a, b *Tree, m noder.Matcher) (Changes, error)

DiffTree compares the content and mode of the blobs found via two tree objects. DiffTree does not perform rename detection, use DiffTreeWithOptions instead to detect renames.

func DiffTreeContext

func DiffTreeContext(ctx context.Context, a, b *Tree, m noder.Matcher) (Changes, error)

DiffTreeContext compares the content and mode of the blobs found via two tree objects. Provided context must be non-nil. An error will be returned if context expires.

func DiffTreeWithOptions

func DiffTreeWithOptions(
	ctx context.Context,
	a, b *Tree,
	opts *DiffTreeOptions,
	m noder.Matcher,
) (Changes, error)

DiffTreeWithOptions compares the content and mode of the blobs found via two tree objects with the given options. The provided context must be non-nil. If no options are passed, no rename detection will be performed. The recommended options are DefaultDiffTreeOptions. An error will be returned if the context expires. This function will be deprecated and removed in v6 so the default behaviour of DiffTree is to detect renames.

func (Changes) Len

func (c Changes) Len() int

func (Changes) Less

func (c Changes) Less(i, j int) bool

func (Changes) Patch

func (c Changes) Patch(ctx context.Context, opts *PatchOptions) ([]*diferenco.Unified, error)

Patch returns a Patch with all the changes in chunks. This representation can be used to create several diff outputs.

func (Changes) Stats added in v0.15.0

func (c Changes) Stats(ctx context.Context, opts *PatchOptions) (FileStats, error)

func (Changes) String

func (c Changes) String() string

func (Changes) Swap

func (c Changes) Swap(i, j int)

type Commit

type Commit struct {
	Hash plumbing.Hash `json:"hash"` // commit oid
	// Author is the Author this commit, or the original writer of the
	// contents.
	//
	// NOTE: this field is stored as a string to ensure any extra "cruft"
	// bytes are preserved through migration.
	Author Signature `json:"author"`
	// Committer is the individual or entity that added this commit to the
	// history.
	//
	// NOTE: this field is stored as a string to ensure any extra "cruft"
	// bytes are preserved through migration.
	Committer Signature `json:"committer"`
	// ParentIDs are the IDs of all parents for which this commit is a
	// linear child.
	Parents []plumbing.Hash `json:"parents"`
	// Tree is the root Tree associated with this commit.
	Tree plumbing.Hash `json:"tree"`
	// ExtraHeaders stores headers not listed above, for instance
	// "encoding", "gpgsig", or "mergetag" (among others).
	ExtraHeaders []*ExtraHeader `json:"-"`
	// Message is the commit message, including any signing information
	// associated with this commit.
	Message string `json:"message"`
	// contains filtered or unexported fields
}

func GetCommit

func GetCommit(ctx context.Context, b Backend, oid plumbing.Hash) (*Commit, error)

GetCommit gets a commit from an object storer and decodes it.

func Independents

func Independents(ctx context.Context, commits []*Commit) ([]*Commit, error)

Independents returns a subset of the passed commits, that are not reachable the others It mimics the behavior of `git merge-base --independent commit...`.

func NewSnapshotCommit

func NewSnapshotCommit(cc *Commit, b Backend) *Commit

func (*Commit) Decode

func (c *Commit) Decode(reader Reader) error

func (*Commit) Encode

func (c *Commit) Encode(w io.Writer) error

func (*Commit) File added in v0.16.0

func (c *Commit) File(ctx context.Context, path string) (*File, error)

File returns the file with the specified "path" in the commit and a nil error if the file exists. If the file does not exist, it returns a nil file and the ErrFileNotFound error.

func (*Commit) IsAncestor

func (c *Commit) IsAncestor(ctx context.Context, other *Commit) (bool, error)

IsAncestor returns true if the actual commit is ancestor of the passed one. It returns an error if the history is not transversable It mimics the behavior of `git merge --is-ancestor actual other`

func (*Commit) Less

func (c *Commit) Less(rhs *Commit) bool

Less defines a compare function to determine which commit is 'earlier' by: - First use Committer.When - If Committer.When are equal then use Author.When - If Author.When also equal then compare the string value of the hash

func (*Commit) MakeParents

func (c *Commit) MakeParents() CommitIter

Parents return a CommitIter to the parent Commits.

func (*Commit) MergeBase

func (c *Commit) MergeBase(ctx context.Context, other *Commit) ([]*Commit, error)

MergeBase mimics the behavior of `git merge-base actual other`, returning the best common ancestor between the actual and the passed one. The best common ancestors can not be reached from other common ancestors.

func (*Commit) NumParents

func (c *Commit) NumParents() int

NumParents returns the number of parents in a commit.

func (*Commit) Pretty

func (c *Commit) Pretty(w io.Writer) error

func (*Commit) Root

func (c *Commit) Root(ctx context.Context) (*Tree, error)

Root returns the Tree from the commit.

func (*Commit) StatsContext

func (c *Commit) StatsContext(ctx context.Context, m noder.Matcher, opts *PatchOptions) (FileStats, error)

StatsContext returns the stats of a commit. Error will be return if context expires. Provided context must be non-nil.

func (*Commit) String

func (c *Commit) String() string

func (*Commit) Subject

func (c *Commit) Subject() string

type CommitFilter

type CommitFilter func(*Commit) bool

CommitFilter returns a boolean for the passed Commit

type CommitIter

type CommitIter interface {
	Next(context.Context) (*Commit, error)
	ForEach(context.Context, func(*Commit) error) error
	Close()
}

CommitIter is a generic closable interface for iterating over commits.

func NewCommitAllIter

func NewCommitAllIter(ctx context.Context, rdb refs.Backend, odb Backend, commitIterFunc func(*Commit) CommitIter) (CommitIter, error)

NewCommitAllIter returns a new commit iterator for all refs. repoStorer is a repo Storer used to get commits and references. commitIterFunc is a commit iterator function, used to iterate through ref commits in chosen order

func NewCommitFileIterFromIter

func NewCommitFileIterFromIter(fileName string, commitIter CommitIter, checkParent bool) CommitIter

NewCommitFileIterFromIter is kept for compatibility, can be replaced with NewCommitPathIterFromIter

func NewCommitIter

func NewCommitIter(b Backend, hashes []plumbing.Hash) CommitIter

func NewCommitIterBSF

func NewCommitIterBSF(
	c *Commit,
	seenExternal map[plumbing.Hash]bool,
	ignore []plumbing.Hash,
) CommitIter

NewCommitIterBSF returns a CommitIter that walks the commit history, starting at the given commit and visiting its parents in pre-order. The given callback will be called for each visited commit. Each commit will be visited only once. If the callback returns an error, walking will stop and will return the error. Other errors might be returned if the history cannot be traversed (e.g. missing objects). Ignore allows to skip some commits from being iterated.

func NewCommitIterCTime

func NewCommitIterCTime(
	c *Commit,
	seenExternal map[plumbing.Hash]bool,
	ignore []plumbing.Hash,
) CommitIter

NewCommitIterCTime returns a CommitIter that walks the commit history, starting at the given commit and visiting its parents while preserving Committer Time order. this appears to be the closest order to `git log` The given callback will be called for each visited commit. Each commit will be visited only once. If the callback returns an error, walking will stop and will return the error. Other errors might be returned if the history cannot be traversed (e.g. missing objects). Ignore allows to skip some commits from being iterated.

func NewCommitLimitIterFromIter

func NewCommitLimitIterFromIter(commitIter CommitIter, limitOptions LogLimitOptions) CommitIter

func NewCommitPathIterFromIter

func NewCommitPathIterFromIter(pathFilter func(string) bool, commitIter CommitIter, checkParent bool) CommitIter

NewCommitPathIterFromIter returns a commit iterator which performs diffTree between successive trees returned from the commit iterator from the argument. The purpose of this is to find the commits that explain how the files that match the path came to be. If checkParent is true then the function double checks if potential parent (next commit in a path) is one of the parents in the tree (it's used by `git log --all`). pathFilter is a function that takes path of file as argument and returns true if we want it

func NewCommitPostorderIter

func NewCommitPostorderIter(c *Commit, ignore []plumbing.Hash) CommitIter

NewCommitPostorderIter returns a CommitIter that walks the commit history like WalkCommitHistory but in post-order. This means that after walking a merge commit, the merged commit will be walked before the base it was merged on. This can be useful if you wish to see the history in chronological order. Ignore allows to skip some commits from being iterated.

func NewCommitPreorderIter

func NewCommitPreorderIter(
	c *Commit,
	seenExternal map[plumbing.Hash]bool,
	ignore []plumbing.Hash,
) CommitIter

NewCommitPreorderIter returns a CommitIter that walks the commit history, starting at the given commit and visiting its parents in pre-order. The given callback will be called for each visited commit. Each commit will be visited only once. If the callback returns an error, walking will stop and will return the error. Other errors might be returned if the history cannot be traversed (e.g. missing objects). Ignore allows to skip some commits from being iterated.

func NewFilterCommitIter

func NewFilterCommitIter(
	from *Commit,
	isValid *CommitFilter,
	isLimit *CommitFilter,
) CommitIter

NewFilterCommitIter returns a CommitIter that walks the commit history, starting at the passed commit and visiting its parents in Breadth-first order. The commits returned by the CommitIter will validate the passed CommitFilter. The history won't be transversed beyond a commit if isLimit is true for it. Each commit will be visited only once. If the commit history can not be traversed, or the Close() method is called, the CommitIter won't return more commits. If no isValid is passed, all ancestors of from commit will be valid. If no isLimit is limit, all ancestors of all commits will be visited.

type CompressMethod

type CompressMethod uint16

type DiffTreeOptions

type DiffTreeOptions struct {
	// DetectRenames is whether the diff tree will use rename detection.
	DetectRenames bool
	// RenameScore is the threshold to of similarity between files to consider
	// that a pair of delete and insert are a rename. The number must be
	// exactly between 0 and 100.
	RenameScore uint
	// RenameLimit is the maximum amount of files that can be compared when
	// detecting renames. The number of comparisons that have to be performed
	// is equal to the number of deleted files * the number of added files.
	// That means, that if 100 files were deleted and 50 files were added, 5000
	// file comparisons may be needed. So, if the rename limit is 50, the number
	// of both deleted and added needs to be equal or less than 50.
	// A value of 0 means no limit.
	RenameLimit uint
	// OnlyExactRenames performs only detection of exact renames and will not perform
	// any detection of renames based on file similarity.
	OnlyExactRenames bool
}

DiffTreeOptions are the configurable options when performing a diff tree.

type Encoder

type Encoder interface {
	Encode(io.Writer) error
}

type ErrDirectoryNotFound

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

func (*ErrDirectoryNotFound) Error

func (e *ErrDirectoryNotFound) Error() string

type ErrEntryNotFound

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

func (*ErrEntryNotFound) Error

func (e *ErrEntryNotFound) Error() string

type ExtraHeader

type ExtraHeader struct {
	// K is the header key, or the first run of bytes up until a ' ' (\x20)
	// character.
	K string
	// V is the header value, or the remaining run of bytes in the line,
	// stripping off the above "K" field as a prefix.
	V string
}

ExtraHeader encapsulates a key-value pairing of header key to header value. It is stored as a struct{string, string} in memory as opposed to a map[string]string to maintain ordering in a byte-for-byte encode/decode round trip.

type File

type File struct {
	// Name is the path of the file. It might be relative to a tree,
	// depending of the function that generates it.
	Name string
	// path
	Path string
	// Mode is the file mode.
	Mode filemode.FileMode
	// Hash of the blob.
	Hash plumbing.Hash
	// Size of the (uncompressed) blob.
	Size int64
	// contains filtered or unexported fields
}

func (*File) IsFragments added in v0.15.0

func (f *File) IsFragments() bool

func (*File) OriginReader

func (f *File) OriginReader(ctx context.Context) (io.ReadCloser, int64, error)

OriginReader return ReadCloser

func (*File) Reader

func (f *File) Reader(ctx context.Context) (io.ReadCloser, bool, error)

func (*File) UnifiedText

func (f *File) UnifiedText(ctx context.Context, codecvt bool) (content string, err error)

type FileIter

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

FileIter provides an iterator for the files in a tree.

func NewFileIter

func NewFileIter(b Backend, t *Tree) *FileIter

NewFileIter takes a Backend and a Tree and returns a *FileIter that iterates over all files contained in the tree, recursively.

func (*FileIter) Close

func (iter *FileIter) Close()

func (*FileIter) ForEach

func (iter *FileIter) ForEach(ctx context.Context, cb func(*File) error) error

ForEach call the cb function for each file contained in this iter until an error happens or the end of the iter is reached. If plumbing.ErrStop is sent the iteration is stop but no error is returned. The iterator is closed.

func (*FileIter) Next

func (iter *FileIter) Next(ctx context.Context) (*File, error)

Next moves the iterator to the next file and returns a pointer to it. If there are no more files, it returns io.EOF.

type FileStat

type FileStat struct {
	Name     string `json:"name"`
	Addition int    `json:"addition"`
	Deletion int    `json:"deletion"`
}

FileStat stores the status of changes in content of a file.

func (FileStat) String

func (fs FileStat) String() string

type FileStats

type FileStats []FileStat

FileStats is a collection of FileStat.

func (FileStats) String

func (fileStats FileStats) String() string

type Fragment

type Fragment struct {
	Index uint32        `json:"index"`
	Size  uint64        `json:"size"`
	Hash  plumbing.Hash `json:"hash"`
}

type Fragments

type Fragments struct {
	Hash    plumbing.Hash // NOT Encode
	Size    uint64
	Origin  plumbing.Hash // origin file hash checksum
	Entries []*Fragment
	// contains filtered or unexported fields
}

func (*Fragments) Decode

func (f *Fragments) Decode(reader Reader) error

func (*Fragments) Encode

func (f *Fragments) Encode(w io.Writer) error

func (*Fragments) Pretty

func (f *Fragments) Pretty(w io.Writer) error

type FragmentsOrder

type FragmentsOrder []*Fragment

func (FragmentsOrder) Len

func (s FragmentsOrder) Len() int

Len implements sort.Interface.Len() and return the length of the underlying slice.

func (FragmentsOrder) Less

func (s FragmentsOrder) Less(i, j int) bool

Less implements sort.Interface.Less() and returns whether the element at "i" is compared as "less" than the element at "j". In other words, it returns if the element at "i" should be sorted ahead of that at "j".

It performs this comparison in lexicographic byte-order according to the rules above (see FragmentsOrder).

func (FragmentsOrder) Swap

func (s FragmentsOrder) Swap(i, j int)

Swap implements sort.Interface.Swap() and swaps the two elements at i and j.

type LogLimitOptions

type LogLimitOptions struct {
	Since *time.Time
	Until *time.Time
}

type ObjectType

type ObjectType int8
const (
	InvalidObject ObjectType = 0
	CommitObject  ObjectType = 1
	TreeObject    ObjectType = 2
	BlobObject    ObjectType = 3
	TagObject     ObjectType = 4
	// 5 reserved for future expansion
	OFSDeltaObject  ObjectType = 6
	REFDeltaObject  ObjectType = 7
	FragmentsObject ObjectType = 8 // File Fragmentation Extension

	AnyObject ObjectType = -127
)

func HashObject

func HashObject(r io.Reader) (plumbing.Hash, ObjectType, error)

func ObjectTypeFromString

func ObjectTypeFromString(s string) ObjectType

ObjectTypeFromString converts from a given string to an ObjectType enumeration instance.

func (ObjectType) MarshalJSON

func (t ObjectType) MarshalJSON() ([]byte, error)

func (ObjectType) String

func (t ObjectType) String() string

func (*ObjectType) UnmarshalJSON

func (t *ObjectType) UnmarshalJSON(b []byte) error

type PatchOptions added in v0.15.0

type PatchOptions struct {
	Algorithm diferenco.Algorithm
	Textconv  bool
	Match     func(string) bool
}

type Printer

type Printer interface {
	Pretty(io.Writer) error
}

type Reader

type Reader interface {
	io.Reader
	Hash() plumbing.Hash
	Type() ObjectType
}

type Signature

type Signature struct {
	Name  string    `json:"name"`
	Email string    `json:"email"`
	When  time.Time `json:"when"`
}

func (*Signature) Decode

func (s *Signature) Decode(b []byte)

Decode decodes a byte slice into a signature

func (*Signature) String

func (s *Signature) String() string

String implements the fmt.Stringer interface and formats a Signature as expected in the Git commit internal object format. For instance:

Taylor Blau <ttaylorr@github.com> 1494258422 -0600

type SubtreeOrder

type SubtreeOrder []*TreeEntry

SubtreeOrder is an implementation of sort.Interface that sorts a set of `*TreeEntry`'s according to "subtree" order. This ordering is required to write trees in a correct, readable format to the Git object database.

The format is as follows: entries are sorted lexicographically in byte-order, with subtrees (entries of Type() == object.TreeObjectType) being sorted as if their `Name` fields ended in a "/".

See: https://github.com/git/git/blob/v2.13.0/fsck.c#L492-L525 for more details.

func (SubtreeOrder) Len

func (s SubtreeOrder) Len() int

Len implements sort.Interface.Len() and return the length of the underlying slice.

func (SubtreeOrder) Less

func (s SubtreeOrder) Less(i, j int) bool

Less implements sort.Interface.Less() and returns whether the element at "i" is compared as "less" than the element at "j". In other words, it returns if the element at "i" should be sorted ahead of that at "j".

It performs this comparison in lexicographic byte-order according to the rules above (see SubtreeOrder).

func (SubtreeOrder) Name

func (s SubtreeOrder) Name(i int) string

Name returns the name for a given entry indexed at "i", which is a C-style string ('\0' terminated unless it's a subtree), optionally terminated with '/' if it's a subtree.

This is done because '/' sorts ahead of '\0', and is compatible with the tree order in upstream Git.

func (SubtreeOrder) Swap

func (s SubtreeOrder) Swap(i, j int)

Swap implements sort.Interface.Swap() and swaps the two elements at i and j.

type Tag

type Tag struct {
	Hash       plumbing.Hash `json:"hash"`
	Object     plumbing.Hash `json:"object"`
	ObjectType ObjectType    `json:"type"`
	Name       string        `json:"name"`
	Tagger     Signature     `json:"tagger"`

	Content string `json:"content"`
}

func (*Tag) Decode

func (t *Tag) Decode(reader Reader) error

Decode implements Object.Decode and decodes the uncompressed tag being read. It returns the number of uncompressed bytes being consumed off of the stream, which should be strictly equal to the size given.

If any error was encountered along the way it will be returned, and the receiving *Tag is considered invalid.

func (*Tag) Encode

func (t *Tag) Encode(w io.Writer) error

Encode encodes the Tag's contents to the given io.Writer, "w". If there was any error copying the Tag's contents, that error will be returned.

Otherwise, the number of bytes written will be returned.

func (*Tag) Equal

func (t *Tag) Equal(other *Tag) bool

Equal returns whether the receiving and given Tags are equal, or in other words, whether they are represented by the same SHA-1 when saved to the object database.

func (*Tag) Message

func (t *Tag) Message() string

func (*Tag) Pretty

func (t *Tag) Pretty(w io.Writer) error

type Tree

type Tree struct {
	Hash    plumbing.Hash `json:"hash"`
	Entries []*TreeEntry  `json:"entries"`
	// contains filtered or unexported fields
}

Tree is basically like a directory - it references a bunch of other trees and/or blobs (i.e. files and sub-directories)

func NewSnapshotTree

func NewSnapshotTree(t *Tree, b Backend) *Tree

func NewTree

func NewTree(entries []*TreeEntry) *Tree

func (*Tree) Append

func (t *Tree) Append(others *TreeEntry)

func (*Tree) Decode

func (t *Tree) Decode(reader Reader) error

func (*Tree) Diff

func (t *Tree) Diff(to *Tree, m noder.Matcher) (Changes, error)

Diff returns a list of changes between this tree and the provided one

func (*Tree) DiffContext

func (t *Tree) DiffContext(ctx context.Context, to *Tree, m noder.Matcher) (Changes, error)

DiffContext returns a list of changes between this tree and the provided one Error will be returned if context expires. Provided context must be non nil.

NOTE: Since version 5.1.0 the renames are correctly handled, the settings used are the recommended options DefaultDiffTreeOptions.

func (*Tree) Encode

func (t *Tree) Encode(w io.Writer) error

func (*Tree) Entry

func (t *Tree) Entry(name string) (*TreeEntry, error)

func (*Tree) Equal

func (t *Tree) Equal(other *Tree) bool

Equal returns whether the receiving and given trees are equal, or in other words, whether they are represented by the same BLAKE3 when saved to the object database.

func (*Tree) File added in v0.16.0

func (t *Tree) File(ctx context.Context, path string) (*File, error)

File returns the hash of the file identified by the `path` argument. The path is interpreted as relative to the tree receiver.

func (*Tree) Files

func (t *Tree) Files() *FileIter

Files returns a FileIter allowing to iterate over the Tree

func (*Tree) FindEntry

func (t *Tree) FindEntry(ctx context.Context, relativePath string) (*TreeEntry, error)

FindEntry search a TreeEntry in this tree or any subtree.

func (*Tree) Merge

func (t *Tree) Merge(others ...*TreeEntry) *Tree

Merge performs a merge operation against the given set of `*TreeEntry`'s by either replacing existing tree entries of the same name, or appending new entries in sub-tree order.

It returns a copy of the tree, and performs the merge in O(n*log(n)) time.

func (*Tree) Pretty

func (t *Tree) Pretty(w io.Writer) error

fragments

func (*Tree) SizePadding

func (t *Tree) SizePadding() int

func (*Tree) SpacePadding

func (t *Tree) SpacePadding() int

func (*Tree) StatsContext added in v0.15.0

func (t *Tree) StatsContext(ctx context.Context, to *Tree, m noder.Matcher, opts *PatchOptions) (FileStats, error)

StatsContext: stats

func (*Tree) Tree

func (t *Tree) Tree(ctx context.Context, path string) (*Tree, error)

Tree returns the tree identified by the `path` argument. The path is interpreted as relative to the tree receiver.

type TreeEntry

type TreeEntry struct {
	Name    string            `json:"name"`
	Size    int64             `json:"size"`
	Mode    filemode.FileMode `json:"mode"`
	Hash    plumbing.Hash     `json:"hash"`
	Payload []byte            `json:"-"`
}

TreeEntry represents a file

func (*TreeEntry) Chmod

func (e *TreeEntry) Chmod(other *TreeEntry) bool

func (*TreeEntry) Clone

func (e *TreeEntry) Clone() *TreeEntry

func (*TreeEntry) Equal

func (e *TreeEntry) Equal(other *TreeEntry) bool

Equal returns whether the receiving and given TreeEntry instances are identical in name, filemode, and OID.

func (*TreeEntry) IsFragments

func (e *TreeEntry) IsFragments() bool
func (e *TreeEntry) IsLink() bool

IsLink returns true if the given TreeEntry is a blob which represents a symbolic link (i.e., with a filemode of 0120000.

func (*TreeEntry) Modified

func (e *TreeEntry) Modified(other *TreeEntry) bool

entry with same name

func (*TreeEntry) OriginMode

func (e *TreeEntry) OriginMode() filemode.FileMode

func (*TreeEntry) Renamed

func (e *TreeEntry) Renamed(other *TreeEntry) bool

check if entry renamed

func (*TreeEntry) Type

func (e *TreeEntry) Type() ObjectType

type TreeNoder

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

A treenoder is a helper type that wraps git trees into merkletrie noders.

As a merkletrie noder doesn't understand the concept of modes (e.g. file permissions), the treenoder includes the mode of the git tree in the hash, so changes in the modes will be detected as modifications to the file contents by the merkletrie difftree algorithm. This is consistent with how the "git diff-tree" command works.

func (*TreeNoder) Children

func (t *TreeNoder) Children(ctx context.Context) ([]noder.Noder, error)

Children will return the children of a treenoder as treenoders, building them from the children of the wrapped git tree.

func (*TreeNoder) Hash

func (t *TreeNoder) Hash() []byte

func (*TreeNoder) HashRaw

func (t *TreeNoder) HashRaw() plumbing.Hash

func (*TreeNoder) IsDir

func (t *TreeNoder) IsDir() bool

func (*TreeNoder) IsFragments

func (t *TreeNoder) IsFragments() bool

func (*TreeNoder) Mode

func (t *TreeNoder) Mode() filemode.FileMode

func (*TreeNoder) Name

func (t *TreeNoder) Name() string

func (*TreeNoder) NumChildren

func (t *TreeNoder) NumChildren(ctx context.Context) (int, error)

len(t.tree.Entries) != the number of elements walked by treewalker for some reason because of empty directories, submodules, etc, so we have to walk here.

func (*TreeNoder) Size

func (t *TreeNoder) Size() int64

func (*TreeNoder) Skip

func (t *TreeNoder) Skip() bool

func (*TreeNoder) String

func (t *TreeNoder) String() string

func (*TreeNoder) TrueMode

func (t *TreeNoder) TrueMode() filemode.FileMode

type TreeWalker

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

TreeWalker provides a means of walking through all of the entries in a Tree.

func NewTreeWalker

func NewTreeWalker(t *Tree, recursive bool, seen map[plumbing.Hash]bool) *TreeWalker

NewTreeWalker returns a new TreeWalker for the given tree.

It is the caller's responsibility to call Close() when finished with the tree walker.

func (*TreeWalker) Close

func (w *TreeWalker) Close()

Close releases any resources used by the TreeWalker.

func (*TreeWalker) Next

func (w *TreeWalker) Next(ctx context.Context) (name string, entry *TreeEntry, err error)

Next returns the next object from the tree. Objects are returned in order and subtrees are included. After the last object has been returned further calls to Next() will return io.EOF.

In the current implementation any objects which cannot be found in the underlying repository will be skipped automatically. It is possible that this may change in future versions.

func (*TreeWalker) Tree

func (w *TreeWalker) Tree() *Tree

Tree returns the tree that the tree walker most recently operated on.

Jump to

Keyboard shortcuts

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