gitlib

package
v0.0.0-...-cd37b43 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package gitlib provides a unified interface for git operations using libgit2. This replaces go-git with the faster libgit2 C library.

Index

Constants

View Source
const (
	// HashSize is the size of a SHA-1 hash in bytes.
	HashSize = 20
	// HashHexSize is the size of a hex-encoded SHA-1 hash.
	HashHexSize = 40
)

Constants for hash operations.

Variables

View Source
var (
	ErrRepositoryPointer = cgoError("failed to get repository pointer")
	ErrBlobLookup        = cgoError("blob lookup failed")
	ErrBlobMemory        = cgoError("memory allocation failed for blob")
	ErrBlobBinary        = cgoError("blob is binary")
	ErrDiffLookup        = cgoError("diff blob lookup failed")
	ErrDiffMemory        = cgoError("memory allocation failed for diff")
	ErrDiffBinary        = cgoError("diff blob is binary")
	ErrDiffCompute       = cgoError("diff computation failed")
	ErrArenaFull         = cgoError("arena full")
	ErrConfigureMemory   = cgoError("cf_configure_memory failed")
)

CGO operation errors.

View Source
var ErrBinary = errors.New("binary")

ErrBinary is raised in CachedBlob.CountLines() if the file is binary.

View Source
var ErrInvalidTimeFormat = errors.New("cannot parse time")

ErrInvalidTimeFormat is returned when a time string cannot be parsed.

View Source
var ErrMockNotImplemented = errors.New("mock: operation not implemented")

ErrMockNotImplemented is returned by mock methods that are not implemented.

View Source
var ErrParentNotFound = errors.New("parent commit not found")

ErrParentNotFound is returned when the requested parent commit is not found.

View Source
var ErrRemoteNotSupported = errors.New("remote repositories not supported")

ErrRemoteNotSupported is returned when a remote repository URI is provided.

Functions

func ConfigureMemoryLimits

func ConfigureMemoryLimits(mwindowLimit, cacheLimit int64, mallocArenaMax int) error

ConfigureMemoryLimits sets libgit2 global memory limits and glibc malloc arena count. mwindowLimit caps mmap'd pack data (default 8 GiB on 64-bit). cacheLimit caps the decompressed object cache (default 256 MiB). mallocArenaMax caps glibc malloc arenas (default 8*cores, causes RSS bloat). Pass 0 for any to leave unchanged. Must be called before opening repos.

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime parses a time string in various formats: - Duration relative to now (e.g. "24h") - RFC3339 (e.g. "2024-01-01T00:00:00Z") - Date only (e.g. "2024-01-01").

func ReleaseNativeMemory

func ReleaseNativeMemory() bool

ReleaseNativeMemory returns free native memory pages to the OS. On glibc systems, calls malloc_trim(0) to release freed pages from all malloc arenas. This is the C-side equivalent of debug.FreeOSMemory() for Go heap. Should be called between streaming chunks after bulk libgit2 operations that allocate and free large amounts of native memory. Returns true if memory was actually released.

Types

type BatchConfig

type BatchConfig struct {
	// BlobBatchSize is the number of blobs to load per batch.
	// Default: 100.
	BlobBatchSize int

	// DiffBatchSize is the number of diffs to compute per batch.
	// Default: 50.
	DiffBatchSize int

	// Workers is the number of parallel workers for processing.
	// Default: 1 (sequential processing within gitlib).
	Workers int
}

BatchConfig configures batch processing parameters.

func DefaultBatchConfig

func DefaultBatchConfig() BatchConfig

DefaultBatchConfig returns the default batch configuration.

type Blob

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

Blob wraps a libgit2 blob.

func (*Blob) Contents

func (b *Blob) Contents() []byte

Contents returns the blob contents.

func (*Blob) Free

func (b *Blob) Free()

Free releases the blob resources.

func (*Blob) Hash

func (b *Blob) Hash() Hash

Hash returns the blob hash.

func (*Blob) Native

func (b *Blob) Native() *git2go.Blob

Native returns the underlying libgit2 blob.

func (*Blob) Reader

func (b *Blob) Reader() io.Reader

Reader returns a reader for the blob contents.

func (*Blob) Size

func (b *Blob) Size() int64

Size returns the blob size.

type BlobBatchRequest

type BlobBatchRequest struct {
	Hashes   []Hash
	Response chan<- BlobBatchResponse
	Arena    []byte
}

BlobBatchRequest asks to load a batch of blobs.

type BlobBatchResponse

type BlobBatchResponse struct {
	Blobs   []*CachedBlob
	Results []BlobResult
}

BlobBatchResponse is the response for a BlobBatchRequest.

type BlobResult

type BlobResult struct {
	Hash      Hash
	Data      []byte
	Size      int64
	IsBinary  bool
	LineCount int
	Error     error
	KeepAlive any
}

BlobResult represents the result of loading a single blob.

type CGOBridge

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

CGOBridge provides optimized batch operations using the C library. It minimizes CGO overhead by processing multiple items per call.

func NewCGOBridge

func NewCGOBridge(repo *Repository) *CGOBridge

NewCGOBridge creates a new CGO bridge for the given repository.

func (*CGOBridge) BatchDiffBlobs

func (b *CGOBridge) BatchDiffBlobs(requests []DiffRequest) []DiffResult

BatchDiffBlobs computes diffs for multiple blob pairs in a single CGO call. This minimizes CGO overhead by processing all requests together.

func (*CGOBridge) BatchLoadBlobs

func (b *CGOBridge) BatchLoadBlobs(hashes []Hash) []BlobResult

BatchLoadBlobs loads multiple blobs in a single CGO call. This minimizes CGO overhead by processing all requests together.

func (*CGOBridge) BatchLoadBlobsArena

func (b *CGOBridge) BatchLoadBlobsArena(hashes []Hash, arena []byte) []BlobResult

BatchLoadBlobsArena loads multiple blobs into a provided arena. It uses internal recycled buffers for C requests/results to avoid allocation.

func (*CGOBridge) TreeDiff

func (b *CGOBridge) TreeDiff(oldTreeHash, newTreeHash Hash) (Changes, error)

TreeDiff computes the difference between two trees in a single batch CGO call. Skips libgit2 diff when both tree OIDs are equal (e.g. metadata-only commits).

type CachedBlob

type CachedBlob struct {

	// Data is the read contents of the blob object.
	Data []byte
	// contains filtered or unexported fields
}

CachedBlob caches blob data for efficient repeated access.

func NewCachedBlobForTest

func NewCachedBlobForTest(data []byte) *CachedBlob

NewCachedBlobForTest creates a CachedBlob with the given data for testing purposes.

func NewCachedBlobFromRepo

func NewCachedBlobFromRepo(ctx context.Context, repo *Repository, blobHash Hash) (*CachedBlob, error)

NewCachedBlobFromRepo loads and caches a blob from the repository.

func NewCachedBlobWithHashForTest

func NewCachedBlobWithHashForTest(hash Hash, data []byte) *CachedBlob

NewCachedBlobWithHashForTest creates a CachedBlob with the given hash and data for testing.

func (*CachedBlob) Clone

func (b *CachedBlob) Clone() *CachedBlob

Clone creates a deep copy of the CachedBlob, detaching the Data slice. This is useful when the original Data slice is part of a larger Arena.

func (*CachedBlob) CountLines

func (b *CachedBlob) CountLines() (int, error)

CountLines returns the number of lines in the blob or (0, ErrBinary) if it is binary. The result is cached after the first call for efficiency.

func (*CachedBlob) Hash

func (b *CachedBlob) Hash() Hash

Hash returns the blob hash.

func (*CachedBlob) IsBinary

func (b *CachedBlob) IsBinary() bool

IsBinary returns true if the blob appears to be binary.

func (*CachedBlob) Reader

func (b *CachedBlob) Reader() io.ReadCloser

Reader returns a reader for the blob data.

func (*CachedBlob) Size

func (b *CachedBlob) Size() int64

Size returns the blob size.

type Change

type Change struct {
	Action ChangeAction
	From   ChangeEntry
	To     ChangeEntry
}

Change represents a single file change between two trees.

type ChangeAction

type ChangeAction int

ChangeAction represents the type of change in a diff.

const (
	// Insert indicates a new file was added.
	Insert ChangeAction = iota
	// Delete indicates a file was removed.
	Delete
	// Modify indicates a file was modified.
	Modify
)

type ChangeEntry

type ChangeEntry struct {
	Name string
	Hash Hash
	Size int64
	Mode uint16
}

ChangeEntry represents one side of a change (old or new file).

type Changes

type Changes []*Change

Changes is a collection of Change objects.

func InitialTreeChanges

func InitialTreeChanges(_ context.Context, repo *Repository, tree *Tree) (Changes, error)

InitialTreeChanges creates changes for an initial commit (all files are insertions).

func TreeDiff

func TreeDiff(_ context.Context, repo *Repository, oldTree, newTree *Tree) (Changes, error)

TreeDiff computes the changes between two trees using libgit2. Skips diff when both tree OIDs are equal (e.g. metadata-only commits).

type Commit

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

Commit wraps a libgit2 commit.

func LoadCommits

func LoadCommits(ctx context.Context, repository *Repository, opts CommitLoadOptions) ([]*Commit, error)

LoadCommits loads commits from a repository with the given options.

func NewCommitForTest

func NewCommitForTest(h Hash) *Commit

NewCommitForTest creates a Commit with the given hash for testing.

func (*Commit) Author

func (c *Commit) Author() Signature

Author returns the commit author. Zero value when commit is a test double (nil internal).

func (*Commit) Committer

func (c *Commit) Committer() Signature

Committer returns the commit committer. Zero value when commit is a test double (nil internal).

func (*Commit) File

func (c *Commit) File(path string) (*File, error)

File returns a specific file from the commit's tree.

func (*Commit) Files

func (c *Commit) Files() (*FileIter, error)

Files returns an iterator over all files in the commit's tree.

func (*Commit) FilesContext

func (c *Commit) FilesContext(_ context.Context) (*FileIter, error)

FilesContext returns an iterator over all files in the commit's tree, accepting a context for tracing.

func (*Commit) Free

func (c *Commit) Free()

Free releases the commit resources.

func (*Commit) Hash

func (c *Commit) Hash() Hash

Hash returns the commit hash.

func (*Commit) Message

func (c *Commit) Message() string

Message returns the commit message. Empty when commit is a test double (nil internal).

func (*Commit) Native

func (c *Commit) Native() *git2go.Commit

Native returns the underlying libgit2 commit.

func (*Commit) NumParents

func (c *Commit) NumParents() int

NumParents returns the number of parent commits. Zero when commit is a test double (nil internal).

func (*Commit) Parent

func (c *Commit) Parent(n int) (*Commit, error)

Parent returns the nth parent commit. ErrParentNotFound when commit is a test double (nil internal).

func (*Commit) ParentHash

func (c *Commit) ParentHash(n int) Hash

ParentHash returns the hash of the nth parent. Zero hash when commit is a test double (nil internal).

func (*Commit) Tree

func (c *Commit) Tree() (*Tree, error)

Tree returns the tree associated with this commit. Error when commit is a test double (nil internal).

func (*Commit) TreeHash

func (c *Commit) TreeHash() Hash

TreeHash returns the hash of the tree associated with this commit. Zero when commit is a test double (nil internal).

type CommitIter

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

CommitIter iterates over commits.

func (*CommitIter) Close

func (ci *CommitIter) Close()

Close releases resources.

func (*CommitIter) ForEach

func (ci *CommitIter) ForEach(cb func(*Commit) error) error

ForEach calls the callback for each commit.

func (*CommitIter) Next

func (ci *CommitIter) Next() (*Commit, error)

Next returns the next commit in the iteration.

func (*CommitIter) Skip

func (ci *CommitIter) Skip(n int) error

Skip advances the iterator by n commits without materializing Commit objects. Used for checkpoint resume to efficiently skip already-processed commits.

type CommitLoadOptions

type CommitLoadOptions struct {
	Limit       int
	FirstParent bool
	HeadOnly    bool
	Since       string
}

CommitLoadOptions configures how commits are loaded from a repository.

type ContextualRequest

type ContextualRequest struct {
	WorkerRequest
	// contains filtered or unexported fields
}

ContextualRequest wraps a WorkerRequest with an explicit context provider.

func WithContext

func WithContext(ctx context.Context, req WorkerRequest) ContextualRequest

WithContext wraps a WorkerRequest with an explicit context.

type Diff

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

Diff wraps a libgit2 diff.

func (*Diff) Delta

func (d *Diff) Delta(index int) (DiffDelta, error)

Delta returns the delta at the given index.

func (*Diff) ForEach

func (d *Diff) ForEach(
	fileCallback func(delta DiffDelta, progress float64) (git2go.DiffForEachHunkCallback, error),
	detail git2go.DiffDetail,
) error

ForEach iterates over the diff with callbacks for files, hunks, and lines.

func (*Diff) Free

func (d *Diff) Free()

Free releases the diff resources.

func (*Diff) NumDeltas

func (d *Diff) NumDeltas() (int, error)

NumDeltas returns the number of deltas in the diff.

func (*Diff) Stats

func (d *Diff) Stats() (*DiffStats, error)

Stats returns the diff stats.

type DiffBatchRequest

type DiffBatchRequest struct {
	Requests []DiffRequest
	Response chan<- DiffBatchResponse
}

DiffBatchRequest asks to compute diffs for a batch of pairs.

type DiffBatchResponse

type DiffBatchResponse struct {
	Results []DiffResult
}

DiffBatchResponse is the response for a DiffBatchRequest.

type DiffDelta

type DiffDelta struct {
	Status   git2go.Delta
	OldFile  DiffFile
	NewFile  DiffFile
	Flags    git2go.DiffFlag
	NumHunks int
}

DiffDelta represents a file change in a diff.

type DiffFile

type DiffFile struct {
	Path string
	Hash Hash
	Size int64
}

DiffFile represents a file in a diff delta.

type DiffOp

type DiffOp struct {
	Type      DiffOpType
	LineCount int
}

DiffOp represents a single diff operation.

type DiffOpType

type DiffOpType int

DiffOpType represents the type of diff operation.

const (
	DiffOpEqual  DiffOpType = 0
	DiffOpInsert DiffOpType = 1
	DiffOpDelete DiffOpType = 2
)

Diff operation types.

type DiffRequest

type DiffRequest struct {
	OldHash Hash
	NewHash Hash
	OldData []byte
	NewData []byte
	HasOld  bool
	HasNew  bool
}

DiffRequest represents a request to diff two blobs.

type DiffResult

type DiffResult struct {
	OldLines int
	NewLines int
	Ops      []DiffOp
	Error    error
}

DiffResult represents the result of diffing two blobs.

type DiffStats

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

DiffStats wraps libgit2 diff stats.

func (*DiffStats) Deletions

func (s *DiffStats) Deletions() int

Deletions returns the number of deletions.

func (*DiffStats) FilesChanged

func (s *DiffStats) FilesChanged() int

FilesChanged returns the number of files changed.

func (*DiffStats) Free

func (s *DiffStats) Free()

Free releases the stats resources.

func (*DiffStats) Insertions

func (s *DiffStats) Insertions() int

Insertions returns the number of insertions.

type File

type File struct {
	Name string
	Hash Hash
	Mode uint16
	// contains filtered or unexported fields
}

File represents a file in a tree with its content accessible.

func TreeFiles

func TreeFiles(repo *Repository, tree *Tree) ([]*File, error)

TreeFiles returns all files in a tree.

func (*File) Blob

func (f *File) Blob() (*Blob, error)

Blob returns the blob object for this file.

func (*File) BlobContext

func (f *File) BlobContext(ctx context.Context) (*Blob, error)

BlobContext returns the blob object for this file, accepting a context for tracing.

func (*File) Contents

func (f *File) Contents() ([]byte, error)

Contents returns the file contents.

func (*File) ContentsContext

func (f *File) ContentsContext(ctx context.Context) ([]byte, error)

ContentsContext returns the file contents, accepting a context for tracing.

func (*File) Reader

func (f *File) Reader() (io.ReadCloser, error)

Reader returns a reader for the file contents.

type FileIter

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

FileIter iterates over files in a tree.

func (*FileIter) Close

func (fi *FileIter) Close()

Close is a no-op for compatibility.

func (*FileIter) ForEach

func (fi *FileIter) ForEach(cb func(*File) error) error

ForEach calls the callback for each file.

func (*FileIter) Next

func (fi *FileIter) Next() (*File, error)

Next returns the next file in the iterator.

type Hash

type Hash [HashSize]byte

Hash represents a git object hash (SHA-1).

func HashFromOid

func HashFromOid(oid *git2go.Oid) Hash

HashFromOid converts a libgit2 Oid to Hash.

func NewHash

func NewHash(hexStr string) Hash

NewHash creates a Hash from a hex string. Used for testing and initialization.

func ZeroHash

func ZeroHash() Hash

ZeroHash returns the zero value hash.

func (Hash) IsZero

func (h Hash) IsZero() bool

IsZero returns true if the hash is all zeros.

func (Hash) String

func (h Hash) String() string

String returns the hex representation of the hash.

func (Hash) ToOid

func (h Hash) ToOid() *git2go.Oid

ToOid converts Hash back to libgit2 Oid.

type LogOptions

type LogOptions struct {
	Since       *time.Time // Only include commits after this time.
	FirstParent bool       // Follow only first parent (git log --first-parent).
	Reverse     bool       // Yield oldest commits first (adds git2go.SortReverse).
}

LogOptions configures the commit log iteration.

type Repository

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

Repository wraps a libgit2 repository.

func LoadRepository

func LoadRepository(uri string) (*Repository, error)

LoadRepository opens a local git repository. Returns an error for remote URIs.

func OpenRepository

func OpenRepository(path string) (*Repository, error)

OpenRepository opens a git repository at the given path.

func (*Repository) CommitCount

func (r *Repository) CommitCount(opts *LogOptions) (int, error)

CommitCount returns the number of commits matching the given log options. It walks the revision history counting OIDs without looking up full commit objects, making it O(N) in time but O(1) in memory. The Reverse option is ignored since ordering doesn't affect the count.

func (*Repository) DiffTreeToTree

func (r *Repository) DiffTreeToTree(oldTree, newTree *Tree) (*Diff, error)

DiffTreeToTree computes the diff between two trees.

func (*Repository) Free

func (r *Repository) Free()

Free releases the repository resources.

func (*Repository) Head

func (r *Repository) Head() (Hash, error)

Head returns the HEAD reference target.

func (*Repository) Log

func (r *Repository) Log(opts *LogOptions) (*CommitIter, error)

Log returns a commit iterator starting from HEAD.

func (*Repository) LookupBlob

func (r *Repository) LookupBlob(_ context.Context, hash Hash) (*Blob, error)

LookupBlob returns the blob with the given hash.

func (*Repository) LookupCommit

func (r *Repository) LookupCommit(_ context.Context, hash Hash) (*Commit, error)

LookupCommit returns the commit with the given hash.

func (*Repository) LookupTree

func (r *Repository) LookupTree(hash Hash) (*Tree, error)

LookupTree returns the tree with the given hash.

func (*Repository) Native

func (r *Repository) Native() *git2go.Repository

Native returns the underlying libgit2 repository for advanced operations.

func (*Repository) Path

func (r *Repository) Path() string

Path returns the repository path.

func (*Repository) ResolveTime

func (r *Repository) ResolveTime(s string) (time.Time, error)

ResolveTime resolves a time specification that may be a time string (duration, RFC3339, date-only) or a commit SHA/ref. When a SHA/ref is given, the commit's author timestamp is returned.

func (*Repository) Walk

func (r *Repository) Walk() (*RevWalk, error)

Walk creates a new revision walker starting from HEAD.

type RevWalk

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

RevWalk wraps a libgit2 revision walker.

func (*RevWalk) Close

func (w *RevWalk) Close()

Close releases the walker resources. Alias for Free to satisfy alg.Iterator.

func (*RevWalk) Free

func (w *RevWalk) Free()

Free releases the walker resources.

func (*RevWalk) Iterate

func (w *RevWalk) Iterate(cb func(*Commit) bool) error

Iterate calls the callback for each commit in the walk.

func (*RevWalk) Next

func (w *RevWalk) Next() (Hash, error)

Next returns the next commit hash in the walk.

func (*RevWalk) Push

func (w *RevWalk) Push(hash Hash) error

Push adds a commit to start walking from.

func (*RevWalk) PushHead

func (w *RevWalk) PushHead() error

PushHead adds HEAD to start walking from.

func (*RevWalk) Sorting

func (w *RevWalk) Sorting(mode git2go.SortType)

Sorting sets the sorting mode for the walker.

type Signature

type Signature struct {
	Name  string
	Email string
	When  time.Time
}

Signature represents a git signature (author/committer).

func TestSignature

func TestSignature(name, email string) Signature

TestSignature creates a signature for testing.

type TestCommit

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

TestCommit is a mock commit for testing purposes. This is used in unit tests where real git operations are not needed.

func NewTestCommit

func NewTestCommit(hash Hash, author Signature, message string, parentHashes ...Hash) *TestCommit

NewTestCommit creates a new mock commit for testing.

func (*TestCommit) Author

func (m *TestCommit) Author() Signature

Author returns the commit author.

func (*TestCommit) Committer

func (m *TestCommit) Committer() Signature

Committer returns the commit committer.

func (*TestCommit) File

func (m *TestCommit) File(_ string) (*File, error)

File returns an error for TestCommit (not implemented).

func (*TestCommit) Files

func (m *TestCommit) Files() (*FileIter, error)

Files returns an error for TestCommit (not implemented).

func (*TestCommit) Free

func (m *TestCommit) Free()

Free is a no-op for TestCommit.

func (*TestCommit) Hash

func (m *TestCommit) Hash() Hash

Hash returns the commit hash.

func (*TestCommit) Message

func (m *TestCommit) Message() string

Message returns the commit message.

func (*TestCommit) NumParents

func (m *TestCommit) NumParents() int

NumParents returns the number of parent commits.

func (*TestCommit) Parent

func (m *TestCommit) Parent(_ int) (*Commit, error)

Parent returns the nth parent (not implemented for TestCommit).

func (*TestCommit) Tree

func (m *TestCommit) Tree() (*Tree, error)

Tree returns an error for TestCommit (not implemented).

type Tree

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

Tree wraps a libgit2 tree.

func (*Tree) EntryByIndex

func (t *Tree) EntryByIndex(i uint64) *TreeEntry

EntryByIndex returns the tree entry at the given index.

func (*Tree) EntryByPath

func (t *Tree) EntryByPath(path string) (*TreeEntry, error)

EntryByPath returns the tree entry at the given path.

func (*Tree) EntryCount

func (t *Tree) EntryCount() uint64

EntryCount returns the number of entries in the tree.

func (*Tree) Files

func (t *Tree) Files() *FileIter

Files returns an iterator over all files in the tree.

func (*Tree) FilesContext

func (t *Tree) FilesContext(_ context.Context) *FileIter

FilesContext returns an iterator over all files in the tree, accepting a context for tracing.

func (*Tree) Free

func (t *Tree) Free()

Free releases the tree resources.

func (*Tree) Hash

func (t *Tree) Hash() Hash

Hash returns the tree hash.

func (*Tree) Native

func (t *Tree) Native() *git2go.Tree

Native returns the underlying libgit2 tree.

type TreeDiffRequest

type TreeDiffRequest struct {
	PreviousTree       *Tree // Optimization: Use existing tree if on same worker/repo.
	PreviousCommitHash Hash  // Fallback: Lookup previous tree by hash (safe for pool workers).
	CommitHash         Hash  // Hash of the commit to process.
	Response           chan<- TreeDiffResponse
}

TreeDiffRequest asks for a tree diff for a specific commit hash.

type TreeDiffResponse

type TreeDiffResponse struct {
	Changes     Changes
	CurrentTree *Tree // The tree of the processed commit. Caller must Free this or pass it back.
	Error       error
}

TreeDiffResponse is the response for a TreeDiffRequest.

type TreeEntry

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

TreeEntry wraps a libgit2 tree entry.

func (*TreeEntry) Hash

func (e *TreeEntry) Hash() Hash

Hash returns the entry object hash.

func (*TreeEntry) IsBlob

func (e *TreeEntry) IsBlob() bool

IsBlob returns true if the entry is a blob.

func (*TreeEntry) Name

func (e *TreeEntry) Name() string

Name returns the entry name.

func (*TreeEntry) Type

func (e *TreeEntry) Type() git2go.ObjectType

Type returns the entry type.

type Worker

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

Worker manages exclusive, sequential access to the libgit2 Repository. It ensures all CGO calls happen on a single OS thread.

func NewWorker

func NewWorker(repo *Repository, requests <-chan WorkerRequest) *Worker

NewWorker creates a new Gitlib Worker that consumes from the given channel.

func (*Worker) Start

func (w *Worker) Start()

Start runs the worker loop. This MUST be called. It locks the goroutine to the OS thread to satisfy libgit2 constraints.

func (*Worker) Stop

func (w *Worker) Stop()

Stop waits for the worker to finish. Note: The caller must close the requests channel to trigger shutdown.

type WorkerRequest

type WorkerRequest interface {
	// contains filtered or unexported methods
}

WorkerRequest is the interface for requests handled by the Gitlib Worker.

Jump to

Keyboard shortcuts

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