Documentation
¶
Overview ¶
Package furgit implements low-level Git operations.
Index ¶
- Variables
- type Blob
- type BytesDiffChunk
- type BytesDiffChunkKind
- type Commit
- type ExtraHeader
- type FileMode
- type Hash
- type Ident
- type Object
- type ObjectType
- type Ref
- type RefKind
- type Repository
- func (repo *Repository) Close() error
- func (repo *Repository) DiffTrees(a, b *StoredTree) ([]TreeDiffEntry, error)
- func (repo *Repository) ListRefs(pattern string) ([]Ref, error)
- func (repo *Repository) ParseHash(s string) (Hash, error)
- func (repo *Repository) ReadObject(id Hash) (StoredObject, error)
- func (repo *Repository) ReadObjectTypeRaw(id Hash) (ObjectType, []byte, error)
- func (repo *Repository) ReadObjectTypeSize(id Hash) (ObjectType, int64, error)
- func (repo *Repository) ResolveRef(path string) (Ref, error)
- func (repo *Repository) ResolveRefFully(path string) (Hash, error)
- func (repo *Repository) WriteLooseObject(obj Object) (Hash, error)
- type StoredBlob
- type StoredCommit
- type StoredObject
- type StoredTag
- type StoredTree
- type Tag
- type Tree
- type TreeDiffEntry
- type TreeDiffEntryKind
- type TreeEntry
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidObject indicates malformed serialized data. ErrInvalidObject = errors.New("furgit: invalid object encoding") // ErrInvalidRef indicates malformed refs. ErrInvalidRef = errors.New("furgit: invalid ref") // ErrNotFound indicates missing refs/objects. ErrNotFound = errors.New("furgit: not found") )
Functions ¶
This section is empty.
Types ¶
type Blob ¶
type Blob struct {
Data []byte
}
Blob represents a Git blob object.
func (*Blob) ObjectType ¶
func (blob *Blob) ObjectType() ObjectType
ObjectType returns the object type of the blob.
It always returns ObjectTypeBlob.
type BytesDiffChunk ¶
type BytesDiffChunk struct {
Kind BytesDiffChunkKind
Data []byte
}
BytesDiffChunk represents a contiguous region of bytes categorized as unchanged, deleted, or added.
func DiffBytes ¶
func DiffBytes(oldB, newB []byte) ([]BytesDiffChunk, error)
DiffBytes performs a line-based diff. Lines are bytes up to and including '\n' (final line may lack '\n').
type BytesDiffChunkKind ¶
type BytesDiffChunkKind int
BytesDiffChunkKind enumerates the type of diff chunk.
const ( BytesDiffChunkKindUnchanged BytesDiffChunkKind = iota BytesDiffChunkKindDeleted BytesDiffChunkKindAdded )
type Commit ¶
type Commit struct {
// Tree represents the tree hash referenced by the commit.
Tree Hash
// Parents represents the parent commit hashes.
// Commits that have 0 parents are root commits.
// Commits that have >= 2 parents are merge commits.
Parents []Hash
// Author represents the author of the commit.
Author Ident
// Committer represents the committer of the commit.
Committer Ident
// Message represents the commit message.
Message []byte
// ChangeID represents the change-id header used by
// Gerrit and Jujutsu.
ChangeID string
// ExtraHeaders holds any extra headers present in the commit.
ExtraHeaders []ExtraHeader
}
Commit represents a Git commit object.
func (*Commit) ObjectType ¶
func (commit *Commit) ObjectType() ObjectType
ObjectType returns the object type of the commit.
It always returns ObjectTypeCommit.
type ExtraHeader ¶
type ExtraHeader struct {
// Key represents the header key.
Key string
// Value represents the header value.
Value []byte
}
ExtraHeader represents an extra header in a Git object.
type FileMode ¶
type FileMode uint32
FileMode represents the mode of a file in a Git tree.
const ( // FileModeDir represents a directory (tree) in a Git tree. FileModeDir FileMode = 0o40000 // FileModeRegular represents a regular file (blob) in a Git tree. FileModeRegular FileMode = 0o100644 // FileModeExecutable represents an executable file (blob) in a Git tree. FileModeExecutable FileMode = 0o100755 // FileModeSymlink represents a symbolic link (blob) in a Git tree. FileModeSymlink FileMode = 0o120000 // FileModeGitlink represents a Git link (submodule) in a Git tree. FileModeGitlink FileMode = 0o160000 )
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash represents a Git object ID.
type Ident ¶
type Ident struct {
// Name represents the person's name.
Name []byte
// Email represents the person's email.
Email []byte
// WhenUnix represents the timestamp as a Unix time.
// This value is in UTC.
WhenUnix int64
// The timezone offset in minutes.
OffsetMinutes int32
}
Ident represents a Git identity (author/committer/tagger).
type Object ¶
type Object interface {
// ObjectType returns the object's type.
ObjectType() ObjectType
}
Object represents a Git object.
type ObjectType ¶
type ObjectType uint8
ObjectType mirrors Git's object type tags.
const ( // An invalid object. ObjectTypeInvalid ObjectType = 0 // A commit object. ObjectTypeCommit ObjectType = 1 // A tree object. ObjectTypeTree ObjectType = 2 // A blob object. ObjectTypeBlob ObjectType = 3 // An annotated tag object. ObjectTypeTag ObjectType = 4 // An object type reserved for future use. ObjectTypeFuture ObjectType = 5 // A packfile offset delta object. This is not typically exposed. ObjectTypeOfsDelta ObjectType = 6 // A packfile reference delta object. This is not typically exposed. ObjectTypeRefDelta ObjectType = 7 )
type Ref ¶
type Ref struct {
// Name is the fully qualified ref name (e.g., refs/heads/main).
// It may be empty for detached hashes that were not looked up
// by name (e.g., ResolveRef on a raw hash).
Name string
// Kind is the kind of the reference.
Kind RefKind
// When Kind is RefKindSymbolic, Ref is the fully qualified ref name.
// Otherwise the value is undefined.
Ref string
// When Kind is RefKindDetached, Hash is the commit hash.
// Otherwise the value is undefined.
Hash Hash
// When Kind is RefKindDetached, and the ref supposedly points to an
// annotated tag, Peeled is the peeled hash, i.e., the hash of the
// object that the tag points to.
Peeled Hash
}
Ref represents a reference.
func (*Ref) Short ¶
Short returns the shortest unambiguous shorthand for the ref name, following the rev-parse rules used by Git. The provided list of refs is used to test for ambiguity.
When strict is true, all other rules must fail to resolve to an existing ref; otherwise only rules prior to the matched rule must fail.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository represents a Git repository.
It is safe to access the same Repository from multiple goroutines without additional synchronization.
Objects derived from a Repository must not be used after the Repository has been closed.
func OpenRepository ¶
func OpenRepository(path string) (*Repository, error)
OpenRepository opens the repository at the provided path.
The path is expected to be the actual repository directory, i.e., the repository itself for bare repositories, or the .git subdirectory for non-bare repositories.
func (*Repository) Close ¶
func (repo *Repository) Close() error
Close closes the repository, releasing any resources associated with it.
It is safe to call Close multiple times; subsequent calls will have no effect.
Close invalidates any objects derived from the Repository as it; using them may cause segmentation faults or other undefined behavior.
func (*Repository) DiffTrees ¶
func (repo *Repository) DiffTrees(a, b *StoredTree) ([]TreeDiffEntry, error)
DiffTrees compares two trees rooted at a and b and returns all differences as a flat slice of TreeDiffEntry. Differences are discovered recursively.
func (*Repository) ListRefs ¶
func (repo *Repository) ListRefs(pattern string) ([]Ref, error)
ListRefs lists refs similarly to git-show-ref.
The pattern must be empty or begin with "refs/". An empty pattern is treated as "refs/*".
Loose refs are resolved using filesystem globbing relative to the repository root, then packed refs are read while skipping any names that already appeared as loose refs. Packed refs are filtered similarly.
func (*Repository) ParseHash ¶
func (repo *Repository) ParseHash(s string) (Hash, error)
ParseHash converts a hex string into a Hash, validating it matches the repository's hash size.
func (*Repository) ReadObject ¶
func (repo *Repository) ReadObject(id Hash) (StoredObject, error)
ReadObject resolves an ID.
func (*Repository) ReadObjectTypeRaw ¶
func (repo *Repository) ReadObjectTypeRaw(id Hash) (ObjectType, []byte, error)
ReadObjectTypeRaw reads the object type and raw body.
func (*Repository) ReadObjectTypeSize ¶
func (repo *Repository) ReadObjectTypeSize(id Hash) (ObjectType, int64, error)
ReadObjectTypeSize reports the object type and size.
Typicall, this is more efficient than reading the full object, as it avoids decompressing the entire object body.
func (*Repository) ResolveRef ¶
func (repo *Repository) ResolveRef(path string) (Ref, error)
ResolveRef reads the given fully qualified ref (such as "HEAD" or "refs/heads/main") and interprets its contents as either a symbolic ref ("ref: refs/..."), a detached hash, or invalid. If path is empty, it defaults to "HEAD". (While typically only HEAD may be a symbolic reference, others may be as well.)
func (*Repository) ResolveRefFully ¶
func (repo *Repository) ResolveRefFully(path string) (Hash, error)
ResolveRefFully resolves a ref by recursively following symbolic references until it reaches a detached ref. Symbolic cycles are detected and reported. Annotated tags are not peeled.
func (*Repository) WriteLooseObject ¶
func (repo *Repository) WriteLooseObject(obj Object) (Hash, error)
WriteLooseObject writes an object to the repository as a loose object.
type StoredBlob ¶
type StoredBlob struct {
Blob
// contains filtered or unexported fields
}
StoredBlob represents a blob stored in the object database.
func (*StoredBlob) Hash ¶
func (sBlob *StoredBlob) Hash() Hash
Hash returns the hash of the stored blob.
type StoredCommit ¶
type StoredCommit struct {
Commit
// contains filtered or unexported fields
}
StoredCommit represents a commit stored in the object database.
func (*StoredCommit) Hash ¶
func (sCommit *StoredCommit) Hash() Hash
Hash returns the hash of the stored commit.
type StoredObject ¶
StoredObject describes a Git object with a known hash, such as one read from storage.
type StoredTag ¶
type StoredTag struct {
Tag
// contains filtered or unexported fields
}
StoredTag represents a tag stored in the object database.
type StoredTree ¶
type StoredTree struct {
Tree
// contains filtered or unexported fields
}
StoredTree represents a tree stored in the object database.
func (*StoredTree) EntryRecursive ¶
func (sTree *StoredTree) EntryRecursive(repo *Repository, path [][]byte) (*TreeEntry, error)
EntryRecursive looks up a tree entry by path.
Lookups are recursive.
func (*StoredTree) Hash ¶
func (sTree *StoredTree) Hash() Hash
Hash returns the hash of the stored tree.
type Tag ¶
type Tag struct {
// Target represents the hash of the object being tagged.
Target Hash
// TargetType represents the type of the object being tagged.
TargetType ObjectType
// Name represents the name of the tag.
Name []byte
// Tagger represents the identity of the tagger.
Tagger *Ident
// Message represents the tag message.
Message []byte
}
Tag represents a Git annotated tag object.
func (*Tag) ObjectType ¶
func (tag *Tag) ObjectType() ObjectType
ObjectType returns the object type of the tag.
It always returns ObjectTypeTag.
type Tree ¶
type Tree struct {
// Entries represents the entries in the tree.
Entries []TreeEntry
}
Tree represents a Git tree object.
func (*Tree) Entry ¶
Entry looks up a tree entry by name.
Lookups are not recursive. It returns nil if no such entry exists.
func (*Tree) ObjectType ¶
func (tree *Tree) ObjectType() ObjectType
ObjectType returns the object type of the tree.
It always returns ObjectTypeTree.
type TreeDiffEntry ¶
type TreeDiffEntry struct {
// Path is the full slash-separated path relative to the root
// of the repository.
Path []byte
// Kind indicates the type of difference.
Kind TreeDiffEntryKind
// Old is the old tree entry (nil iff added).
Old *TreeEntry
// New is the new tree entry (nil iff deleted).
New *TreeEntry
}
TreeDiffEntry represents a difference between two tree entries.
type TreeDiffEntryKind ¶
type TreeDiffEntryKind int
TreeDiffEntryKind represents the type of difference between two tree entries.
const ( // TreeDiffEntryKindInvalid indicates an invalid difference type. TreeDiffEntryKindInvalid TreeDiffEntryKind = iota // TreeDiffEntryKindDeleted indicates that the entry was deleted. TreeDiffEntryKindDeleted // TreeDiffEntryKindAdded indicates that the entry was added. TreeDiffEntryKindAdded // TreeDiffEntryKindModified indicates that the entry was modified. TreeDiffEntryKindModified )
type TreeEntry ¶
type TreeEntry struct {
// Mode represents the file mode of the entry.
Mode FileMode
// Name represents the name of the entry.
Name []byte
// ID represents the hash of the entry. This is typically
// either a blob or a tree.
ID Hash
}
TreeEntry represents a single entry in a Git tree.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
show-object
command
|
|
|
internal
|
|
|
bufpool
Package bufpool provides a lightweight byte-buffer type with optional pooling.
|
Package bufpool provides a lightweight byte-buffer type with optional pooling. |
|
flatex
Package flatex implements the DEFLATE compressed data format, described in RFC 1951.
|
Package flatex implements the DEFLATE compressed data format, described in RFC 1951. |
|
zlib
Package zlib implements reading and writing of zlib format compressed data, as specified in RFC 1950.
|
Package zlib implements reading and writing of zlib format compressed data, as specified in RFC 1950. |
|
zlibx
Package zlibx implements reading of zlib format compressed data, as specified in RFC 1950.
|
Package zlibx implements reading of zlib format compressed data, as specified in RFC 1950. |