plumbing

package
v6.0.0-...-1f24ae8 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Overview

package plumbing implement the core interfaces and structs used by go-git

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrObjectNotFound = errors.New("object not found")
	// ErrInvalidType is returned when an invalid object type is provided.
	ErrInvalidType = errors.New("invalid object type")
)
View Source
var (
	ErrReferenceNotFound = errors.New("reference not found")

	// ErrInvalidReferenceName is returned when a reference name is invalid.
	ErrInvalidReferenceName = errors.New("invalid reference name")
)
View Source
var RefRevParseRules = []string{
	"%s",
	"refs/%s",
	"refs/tags/%s",
	"refs/heads/%s",
	"refs/remotes/%s",
	"refs/remotes/%s/HEAD",
}

RefRevParseRules are a set of rules to parse references into short names, or expand into a full reference. These are the same rules as used by git in shorten_unambiguous_ref and expand_ref. See: https://github.com/git/git/blob/e0aaa1b6532cfce93d87af9bc813fb2e7a7ce9d7/refs.c#L417

Functions

func HashesSort

func HashesSort(a []Hash)

HashesSort sorts a slice of Hashes in increasing order.

func IsHash

func IsHash(s string) bool

IsHash returns true if the given string is a valid hash.

Types

type DeltaObject

type DeltaObject interface {
	EncodedObject
	// BaseHash returns the hash of the object used as base for this delta.
	BaseHash() Hash
	// ActualHash returns the hash of the object after applying the delta.
	ActualHash() Hash
	// Size returns the size of the object after applying the delta.
	ActualSize() int64
}

DeltaObject is an EncodedObject representing a delta.

type EncodedObject

type EncodedObject interface {
	Hash() Hash
	Type() ObjectType
	SetType(ObjectType)
	Size() int64
	SetSize(int64)
	Reader() (io.ReadCloser, error)
	Writer() (io.WriteCloser, error)
}

Object is a generic representation of any git object

type Hash

type Hash = ObjectID

Hash SHA1 hashed content

func ComputeHash

func ComputeHash(t ObjectType, content []byte) Hash

ComputeHash compute the hash for a given ObjectType and content

func NewHash

func NewHash(s string) Hash

NewHash return a new Hash based on a hexadecimal hash representation. Invalid input results into an empty hash.

deprecated: Use the new FromHex instead.

type HashSlice

type HashSlice []Hash

HashSlice attaches the methods of sort.Interface to []Hash, sorting in increasing order.

func (HashSlice) Len

func (p HashSlice) Len() int

func (HashSlice) Less

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

func (HashSlice) Swap

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

type Hasher

type Hasher struct {
	hash.Hash
	// contains filtered or unexported fields
}

func NewHasher

func NewHasher(f format.ObjectFormat, t ObjectType, size int64) Hasher

func (Hasher) Reset

func (h Hasher) Reset(t ObjectType, size int64)

func (Hasher) Sum

func (h Hasher) Sum() (hash Hash)

type MemoryObject

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

MemoryObject on memory Object implementation

func (*MemoryObject) Close

func (o *MemoryObject) Close() error

Close releases any resources consumed by the object when it is acting as a ObjectWriter.

func (*MemoryObject) Hash

func (o *MemoryObject) Hash() Hash

Hash returns the object Hash, the hash is calculated on-the-fly the first time it's called, in all subsequent calls the same Hash is returned even if the type or the content have changed. The Hash is only generated if the size of the content is exactly the object size.

func (*MemoryObject) Reader

func (o *MemoryObject) Reader() (io.ReadCloser, error)

Reader returns an io.ReadCloser used to read the object's content.

For a MemoryObject, this reader is seekable.

func (*MemoryObject) SetSize

func (o *MemoryObject) SetSize(s int64)

SetSize set the object size, a content of the given size should be written afterwards

func (*MemoryObject) SetType

func (o *MemoryObject) SetType(t ObjectType)

SetType sets the ObjectType

func (*MemoryObject) Size

func (o *MemoryObject) Size() int64

Size returns the size of the object

func (*MemoryObject) Type

func (o *MemoryObject) Type() ObjectType

Type returns the ObjectType

func (*MemoryObject) Write

func (o *MemoryObject) Write(p []byte) (n int, err error)

func (*MemoryObject) Writer

func (o *MemoryObject) Writer() (io.WriteCloser, error)

Writer returns a ObjectWriter used to write the object's content.

type ObjectHasher

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

ObjectHasher computes hashes for Git objects. A few differences it has when compared to Hasher:

  • ObjectType awareness: produces either SHA1 or SHA256 hashes depending on the format needed.
  • Thread-safety.
  • API restricts ability of generating invalid hashes.

func FromHash

func FromHash(h hash.Hash) (*ObjectHasher, error)

FromHash returns the correct ObjectHasher for the given Hash.

If the hash type is not recognised, an ErrUnsupportedHashFunction error is returned.

func FromObjectFormat

func FromObjectFormat(f format.ObjectFormat) (*ObjectHasher, error)

FromObjectFormat returns the correct ObjectHasher for the given ObjectFormat.

If the format is not recognised, an ErrInvalidObjectFormat error is returned.

func (*ObjectHasher) Compute

func (h *ObjectHasher) Compute(ot ObjectType, d []byte) (ObjectID, error)

func (*ObjectHasher) Size

func (h *ObjectHasher) Size() int

func (*ObjectHasher) Write

func (h *ObjectHasher) Write(p []byte) (int, error)

type ObjectID

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

ObjectID represents the ID of a Git object. The object data is kept in its hexadecimal form.

var ZeroHash ObjectID

ZeroHash is an ObjectID with value zero.

func FromBytes

func FromBytes(in []byte) (ObjectID, bool)

FromBytes creates an ObjectID based off its hex representation in bytes. The object format is inferred from the length of the input.

If the size of [in] does not match the supported object formats, an empty ObjectID will be returned.

func FromHex

func FromHex(in string) (ObjectID, bool)

FromHex parses a hexadecimal string and returns an ObjectID and a boolean confirming whether the operation was successful. The object format is inferred from the length of the input.

For backwards compatibility, partial hashes will be handled as being SHA1.

func (ObjectID) Bytes

func (s ObjectID) Bytes() []byte

Bytes returns the slice of bytes representing the hash in hexadecimal.

func (ObjectID) Compare

func (s ObjectID) Compare(b []byte) int

Compare compares the hash's sum with a slice of bytes.

func (ObjectID) Equal

func (s ObjectID) Equal(in ObjectID) bool

Equal returns true if [in] equals the current object.

func (ObjectID) HasPrefix

func (s ObjectID) HasPrefix(prefix []byte) bool

HasPrefix checks whether the ObjectID starts with [prefix].

func (ObjectID) HexSize

func (s ObjectID) HexSize() int

HexSize returns the size for the hex representation of the current object.

func (ObjectID) IsZero

func (s ObjectID) IsZero() bool

IsZero returns true if the hash is zero.

func (*ObjectID) ReadFrom

func (s *ObjectID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the Big Endian representation of the ObjectID from reader [r].

func (*ObjectID) ResetBySize

func (s *ObjectID) ResetBySize(idSize int)

ResetBySize resets the current ObjectID. It sets the underlying format based on the [idSize], which defaults to SHA1 for backwards compatibility.

This enable complete reuse of this object without needing to create a new instance of ObjectID.

func (ObjectID) Size

func (s ObjectID) Size() int

Size returns the length of the resulting hash.

func (ObjectID) String

func (s ObjectID) String() string

String returns the hexadecimal representation of the ObjectID.

func (*ObjectID) Write

func (s *ObjectID) Write(in []byte) (int, error)

Write writes the hexadecimal representation of the ObjectID from [in] directly into the current object.

func (*ObjectID) WriteTo

func (s *ObjectID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Big Endian representation of the ObjectID into the writer [w].

type ObjectType

type ObjectType int8

ObjectType internal object type Integer values from 0 to 7 map to those exposed by git. AnyObject is used to represent any from 0 to 7.

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

	AnyObject ObjectType = -127
)

func ParseObjectType

func ParseObjectType(value string) (typ ObjectType, err error)

ParseObjectType parses a string representation of ObjectType. It returns an error on parse failure.

func (ObjectType) Bytes

func (t ObjectType) Bytes() []byte

func (ObjectType) IsDelta

func (t ObjectType) IsDelta() bool

IsDelta returns true for any ObjectType that represents a delta (i.e. REFDeltaObject or OFSDeltaObject).

func (ObjectType) String

func (t ObjectType) String() string

func (ObjectType) Valid

func (t ObjectType) Valid() bool

Valid returns true if t is a valid ObjectType.

type PermanentError

type PermanentError struct {
	Err error
}

func NewPermanentError

func NewPermanentError(err error) *PermanentError

func (*PermanentError) Error

func (e *PermanentError) Error() string

type Reference

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

Reference is a representation of git reference

func NewHashReference

func NewHashReference(n ReferenceName, h Hash) *Reference

NewHashReference creates a new HashReference reference

func NewReferenceFromStrings

func NewReferenceFromStrings(name, target string) *Reference

NewReferenceFromStrings creates a reference from name and target as string, the resulting reference can be a SymbolicReference or a HashReference base on the target provided

func NewSymbolicReference

func NewSymbolicReference(n, target ReferenceName) *Reference

NewSymbolicReference creates a new SymbolicReference reference

func (*Reference) Hash

func (r *Reference) Hash() Hash

Hash returns the hash of a hash reference

func (*Reference) Name

func (r *Reference) Name() ReferenceName

Name returns the name of a reference

func (*Reference) String

func (r *Reference) String() string

func (*Reference) Strings

func (r *Reference) Strings() [2]string

Strings dump a reference as a [2]string

func (*Reference) Target

func (r *Reference) Target() ReferenceName

Target returns the target of a symbolic reference

func (*Reference) Type

func (r *Reference) Type() ReferenceType

Type returns the type of a reference

type ReferenceName

type ReferenceName string

ReferenceName reference name's

const (
	HEAD   ReferenceName = "HEAD"
	Master ReferenceName = "refs/heads/master"
	Main   ReferenceName = "refs/heads/main"
)

func NewBranchReferenceName

func NewBranchReferenceName(name string) ReferenceName

NewBranchReferenceName returns a reference name describing a branch based on his short name.

func NewNoteReferenceName

func NewNoteReferenceName(name string) ReferenceName

NewNoteReferenceName returns a reference name describing a note based on his short name.

func NewRemoteHEADReferenceName

func NewRemoteHEADReferenceName(remote string) ReferenceName

NewRemoteHEADReferenceName returns a reference name describing a the HEAD branch of a remote.

func NewRemoteReferenceName

func NewRemoteReferenceName(remote, name string) ReferenceName

NewRemoteReferenceName returns a reference name describing a remote branch based on his short name and the remote name.

func NewTagReferenceName

func NewTagReferenceName(name string) ReferenceName

NewTagReferenceName returns a reference name describing a tag based on short his name.

func (ReferenceName) IsBranch

func (r ReferenceName) IsBranch() bool

IsBranch check if a reference is a branch

func (ReferenceName) IsNote

func (r ReferenceName) IsNote() bool

IsNote check if a reference is a note

func (ReferenceName) IsRemote

func (r ReferenceName) IsRemote() bool

IsRemote check if a reference is a remote

func (ReferenceName) IsTag

func (r ReferenceName) IsTag() bool

IsTag check if a reference is a tag

func (ReferenceName) Short

func (r ReferenceName) Short() string

Short returns the short name of a ReferenceName

func (ReferenceName) String

func (r ReferenceName) String() string

func (ReferenceName) Validate

func (r ReferenceName) Validate() error

Validate validates a reference name. This follows the git-check-ref-format rules. See https://git-scm.com/docs/git-check-ref-format

It is important to note that this function does not check if the reference exists in the repository. It only checks if the reference name is valid. This functions does not support the --refspec-pattern, --normalize, and --allow-onelevel options.

Git imposes the following rules on how references are named:

  1. They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.
  2. They must contain at least one /. This enforces the presence of a category like heads/, tags/ etc. but the actual names are not restricted. If the --allow-onelevel option is used, this rule is waived.
  3. They cannot have two consecutive dots .. anywhere.
  4. They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.
  5. They cannot have question-mark ?, asterisk *, or open bracket [ anywhere. See the --refspec-pattern option below for an exception to this rule.
  6. They cannot begin or end with a slash / or contain multiple consecutive slashes (see the --normalize option below for an exception to this rule).
  7. They cannot end with a dot ..
  8. They cannot contain a sequence @{.
  9. They cannot be the single character @.
  10. They cannot contain a \.

type ReferenceType

type ReferenceType int8

ReferenceType reference type's

const (
	InvalidReference  ReferenceType = 0
	HashReference     ReferenceType = 1
	SymbolicReference ReferenceType = 2
)

func (ReferenceType) String

func (r ReferenceType) String() string

type Revision

type Revision string

Revision represents a git revision to get more details about git revisions please check git manual page : https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html

func (Revision) String

func (r Revision) String() string

type TagMode

type TagMode int

TagMode defines how the tags will be fetched from the remote repository.

const (
	InvalidTagMode TagMode = iota
	// TagFollowing any tag that points into the histories being fetched is also
	// fetched. TagFollowing requires a server with `include-tag` capability
	// in order to fetch the annotated tags objects.
	TagFollowing
	// AllTags fetch all tags from the remote (i.e., fetch remote tags
	// refs/tags/* into local tags with the same name)
	AllTags
	// NoTags fetch no tags from the remote at all
	NoTags
)

type UnexpectedError

type UnexpectedError struct {
	Err error
}

func NewUnexpectedError

func NewUnexpectedError(err error) *UnexpectedError

func (*UnexpectedError) Error

func (e *UnexpectedError) Error() string

Directories

Path Synopsis
format
commitgraph
Package v2 implements encoding and decoding of commit-graph files.
Package v2 implements encoding and decoding of commit-graph files.
config
Package config implements encoding and decoding of git config files.
Package config implements encoding and decoding of git config files.
gitignore
Package gitignore implements matching file system paths to gitignore patterns that can be automatically read from a git repository tree in the order of definition priorities.
Package gitignore implements matching file system paths to gitignore patterns that can be automatically read from a git repository tree in the order of definition priorities.
idxfile
Package idxfile implements encoding and decoding of packfile idx files.
Package idxfile implements encoding and decoding of packfile idx files.
index
Package index implements encoding and decoding of index format files.
Package index implements encoding and decoding of index format files.
objfile
Package objfile implements encoding and decoding of object files.
Package objfile implements encoding and decoding of object files.
packfile
Package packfile implements encoding and decoding of packfile format.
Package packfile implements encoding and decoding of packfile format.
package hash provides a way for managing the underlying hash implementations used across go-git.
package hash provides a way for managing the underlying hash implementations used across go-git.
Package object contains implementations of all Git objects and utility functions to work with them.
Package object contains implementations of all Git objects and utility functions to work with them.
commitgraph
Package commitgraph provides an interface for efficient traversal over Git commit graph either through the regular object storage, or optionally with the index stored in commit-graph file (Git 2.18+).
Package commitgraph provides an interface for efficient traversal over Git commit graph either through the regular object storage, or optionally with the index stored in commit-graph file (Git 2.18+).
packp/capability
Package capability defines the server and client capabilities.
Package capability defines the server and client capabilities.
packp/sideband
Package sideband implements a sideband mutiplex/demultiplexer
Package sideband implements a sideband mutiplex/demultiplexer
Package revlist provides support to access the ancestors of commits, in a similar way as the git-rev-list command.
Package revlist provides support to access the ancestors of commits, in a similar way as the git-rev-list command.
Package storer defines the interfaces to store objects, references, etc.
Package storer defines the interfaces to store objects, references, etc.
Package transport implements the git pack protocol with a pluggable This is a low-level package to implement new transports.
Package transport implements the git pack protocol with a pluggable This is a low-level package to implement new transports.
file
Package file implements the file transport protocol.
Package file implements the file transport protocol.
git
Package git implements the git transport protocol.
Package git implements the git transport protocol.
http
Package http implements the HTTP transport protocol.
Package http implements the HTTP transport protocol.
ssh
Package ssh implements the SSH transport protocol.
Package ssh implements the SSH transport protocol.
ssh/knownhosts
Package knownhosts is a thin wrapper around golang.org/x/crypto/ssh/knownhosts, adding the ability to obtain the list of host key algorithms for a known host.
Package knownhosts is a thin wrapper around golang.org/x/crypto/ssh/knownhosts, adding the ability to obtain the list of host key algorithms for a known host.

Jump to

Keyboard shortcuts

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

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy