stats

package
v15.9.0-rc44 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const StaleObjectsGracePeriod = -14 * 24 * time.Hour

StaleObjectsGracePeriod is time delta that is used to indicate cutoff wherein an object would be considered old. Currently this is set to being 2 weeks (2 * 7days * 24hours).

Variables

This section is empty.

Functions

func Bands

func Bands() []string

Bands returns the slice of bands which git uses to transport different kinds of data in a multiplexed way. See https://git-scm.com/docs/protocol-capabilities/2.24.0#_side_band_side_band_64k for more information about the different bands.

func IsPoolRepository added in v15.9.0

func IsPoolRepository(repo repository.GitRepo) bool

IsPoolRepository returns whether the repository is an object pool.

func IsRailsPoolRepository added in v15.9.0

func IsRailsPoolRepository(repo repository.GitRepo) bool

IsRailsPoolRepository returns whether the repository is a pool repository generated by Rails.

func LogRepositoryInfo added in v15.7.0

func LogRepositoryInfo(ctx context.Context, repo *localrepo.Repo)

LogRepositoryInfo derives RepositoryInfo and calls its `Log()` function, if successful. Otherwise it logs an error.

func LooseObjects

func LooseObjects(repo *localrepo.Repo) (uint64, error)

LooseObjects returns the number of loose objects that are not in a packfile.

func PackfilesCount

func PackfilesCount(repo *localrepo.Repo) (uint64, error)

PackfilesCount returns the number of packfiles a repository has.

Types

type BitmapInfo added in v15.9.0

type BitmapInfo struct {
	// Exists indicates whether the bitmap exists. This field would usually always be `true`
	// when read via `BitmapInfoForPath()`, but helps when the bitmap info is embedded into
	// another structure where it may only be conditionally read.
	Exists bool `json:"exists"`
	// Version is the version of the bitmap. Currently, this is expected to always be 1.
	Version uint16 `json:"version"`
	// HasHashCache indicates whether the name hash cache extension exists in the bitmap. This
	// extension records hashes of the path at which trees or blobs are found at the time of
	// writing the packfile so that it becomes possible to quickly find objects stored at the
	// same path. This mechanism is fed into the delta compression machinery to make the delta
	// heuristics more effective.
	HasHashCache bool `json:"has_hash_cache"`
	// HasLookupTable indicates whether the lookup table exists in the bitmap. Lookup tables
	// allow to defer loading bitmaps until required and thus speed up read-only bitmap
	// preparations.
	HasLookupTable bool `json:"has_lookup_table"`
}

BitmapInfo contains information about a packfile or multi-pack-index bitmap.

func BitmapInfoForPath added in v15.9.0

func BitmapInfoForPath(path string) (BitmapInfo, error)

BitmapInfoForPath reads the bitmap at the given path and returns information on that bitmap.

type CommitGraphInfo added in v15.7.0

type CommitGraphInfo struct {
	// Exists tells whether a commit-graph exists.
	Exists bool `json:"exists"`
	// CommitGraphChainLength is the length of the commit-graph chain, if it exists. If the
	// repository does not have a commit-graph chain but a monolithic commit-graph, then this
	// field will be set to 0.
	CommitGraphChainLength uint64 `json:"commit_graph_chain_length"`
	// HasBloomFilters tells whether the commit-graph has bloom filters. Bloom filters are used
	// to answer the question whether a certain path has been changed in the commit the bloom
	// filter applies to.
	HasBloomFilters bool `json:"has_bloom_filters"`
	// HasGenerationData tells whether the commit-graph has generation data. Generation
	// data is stored as the corrected committer date, which is defined as the maximum
	// of the commit's own committer date or the corrected committer date of any of its
	// parents. This data can be used to determine whether a commit A comes after a
	// certain commit B.
	HasGenerationData bool `json:"has_generation_data"`
	// HasGenerationDataOverflow stores overflow data in case the corrected committer
	// date takes more than 31 bits to represent.
	HasGenerationDataOverflow bool `json:"has_generation_data_overflow"`
}

CommitGraphInfo returns information about the commit-graph of a repository.

func CommitGraphInfoForRepository added in v15.7.0

func CommitGraphInfoForRepository(repoPath string) (CommitGraphInfo, error)

CommitGraphInfoForRepository derives information about commit-graphs in the repository.

Please refer to https://git-scm.com/docs/commit-graph#_file_layout for further information about the commit-graph format.

type FetchPack

type FetchPack struct {
	// ReportProgress is an optional callback set by the caller. If set, this function
	// will be called for all received progress packets.
	ReportProgress func([]byte)
	// contains filtered or unexported fields
}

FetchPack is used to parse the response body of a git-fetch-pack(1) request.

func (*FetchPack) Parse

func (f *FetchPack) Parse(body io.Reader) error

Parse parses the server response from a git-fetch-pack(1) request.

type HTTPClone

type HTTPClone struct {
	// ReferenceDiscovery is the reference discovery performed as part of the clone.
	ReferenceDiscovery HTTPReferenceDiscovery
	// FetchPack is the response to a git-fetch-pack(1) request which computes and transmits the
	// packfile.
	FetchPack HTTPFetchPack
}

HTTPClone hosts information about a typical HTTP-based clone.

func PerformHTTPClone

func PerformHTTPClone(ctx context.Context, url, user, password string, interactive bool) (HTTPClone, error)

PerformHTTPClone does a Git HTTP clone, discarding cloned data to /dev/null.

type HTTPFetchPack

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

HTTPFetchPack is a FetchPack obtained via a clone of a target repository via HTTP. It contains additional information about the cloning process like status codes and timings.

func (*HTTPFetchPack) BandFirstPacket

func (p *HTTPFetchPack) BandFirstPacket(b string) time.Duration

BandFirstPacket returns how long it took to receive the first packet on a specific sideband.

func (*HTTPFetchPack) BandPackets

func (p *HTTPFetchPack) BandPackets(b string) int

BandPackets returns how many packets were received on a specific sideband.

func (*HTTPFetchPack) BandPayloadSize

func (p *HTTPFetchPack) BandPayloadSize(b string) int64

BandPayloadSize returns how many bytes were received on a specific sideband.

func (*HTTPFetchPack) HTTPStatus

func (p *HTTPFetchPack) HTTPStatus() int

HTTPStatus returns the HTTP status code.

func (*HTTPFetchPack) LargestPacketSize

func (p *HTTPFetchPack) LargestPacketSize() int

LargestPacketSize returns the largest packet size received.

func (*HTTPFetchPack) NAK

func (p *HTTPFetchPack) NAK() time.Duration

NAK returns how long it took to receive the NAK which signals that negotiation has concluded.

func (*HTTPFetchPack) Packets

func (p *HTTPFetchPack) Packets() int

Packets returns the number of Git packets received.

func (*HTTPFetchPack) RefsWanted

func (p *HTTPFetchPack) RefsWanted() int

RefsWanted returns the number of references sent to the remote repository as "want"s.

func (*HTTPFetchPack) ResponseBody

func (p *HTTPFetchPack) ResponseBody() time.Duration

ResponseBody returns how long it took to receive the first bytes of the response body.

func (*HTTPFetchPack) ResponseHeader

func (p *HTTPFetchPack) ResponseHeader() time.Duration

ResponseHeader returns how long it took to receive the response header.

type HTTPPush

type HTTPPush struct {
	// SendPack is the upload of the packfile performed as part of the clone.
	SendPack HTTPSendPack
}

HTTPPush hosts information about a typical HTTP-based push.

func PerformHTTPPush

func PerformHTTPPush(
	ctx context.Context,
	url, user, password string,
	objectHash git.ObjectHash,
	commands []PushCommand,
	packfile io.Reader,
	interactive bool,
) (HTTPPush, error)

PerformHTTPPush emulates a git-push(1) over the HTTP protocol.

type HTTPReferenceDiscovery

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

HTTPReferenceDiscovery is a ReferenceDiscovery obtained via a clone of a target repository via HTTP. It contains additional information about the cloning process like status codes and timings.

func (HTTPReferenceDiscovery) Caps

func (d HTTPReferenceDiscovery) Caps() []string

Caps returns all announced capabilities.

func (HTTPReferenceDiscovery) FirstGitPacket

func (d HTTPReferenceDiscovery) FirstGitPacket() time.Duration

FirstGitPacket returns how long it took to receive the first Git packet.

func (HTTPReferenceDiscovery) HTTPStatus

func (d HTTPReferenceDiscovery) HTTPStatus() int

HTTPStatus returns the HTTP status code.

func (HTTPReferenceDiscovery) Packets

func (d HTTPReferenceDiscovery) Packets() int

Packets returns the number of Git packets received.

func (HTTPReferenceDiscovery) PayloadSize

func (d HTTPReferenceDiscovery) PayloadSize() int64

PayloadSize returns the total size of all pktlines' data.

func (HTTPReferenceDiscovery) Refs

func (d HTTPReferenceDiscovery) Refs() []Reference

Refs returns all announced references.

func (HTTPReferenceDiscovery) ResponseBody

func (d HTTPReferenceDiscovery) ResponseBody() time.Duration

ResponseBody returns how long it took to receive the first bytes of the response body.

func (HTTPReferenceDiscovery) ResponseHeader

func (d HTTPReferenceDiscovery) ResponseHeader() time.Duration

ResponseHeader returns how long it took to receive the response header.

type HTTPSendPack

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

HTTPSendPack encapsulates statistics about an emulated git-send-pack(1) request.

func (*HTTPSendPack) BandFirstPacket

func (p *HTTPSendPack) BandFirstPacket(b string) time.Duration

BandFirstPacket returns how long it took to receive the first packet on a specific sideband.

func (*HTTPSendPack) BandPayloadSize

func (p *HTTPSendPack) BandPayloadSize(b string) int64

BandPayloadSize returns how many bytes were received on a specific sideband.

func (*HTTPSendPack) ResponseBody

func (p *HTTPSendPack) ResponseBody() time.Duration

ResponseBody returns how long it took to receive the last bytes of the response body.

type LooseObjectsInfo added in v15.7.0

type LooseObjectsInfo struct {
	// Count is the number of loose objects.
	Count uint64 `json:"count"`
	// Size is the total size of all loose objects in bytes.
	Size uint64 `json:"size"`
	// StaleCount is the number of stale loose objects when taking into account the specified cutoff
	// date.
	StaleCount uint64 `json:"stale_count"`
	// StaleSize is the total size of stale loose objects when taking into account the specified
	// cutoff date.
	StaleSize uint64 `json:"stale_size"`
	// GarbageCount is the number of garbage files in the loose-objects shards.
	GarbageCount uint64 `json:"garbage_count"`
	// GarbageSize is the total size of garbage in the loose-objects shards.
	GarbageSize uint64 `json:"garbage_size"`
}

LooseObjectsInfo contains information about loose objects.

func LooseObjectsInfoForRepository added in v15.7.0

func LooseObjectsInfoForRepository(repo *localrepo.Repo, cutoffDate time.Time) (LooseObjectsInfo, error)

LooseObjectsInfoForRepository derives information about loose objects in the repository. If a cutoff date is given, then this function will only take into account objects which are older than the given point in time.

type PackfileNegotiation

type PackfileNegotiation struct {
	// Total size of all pktlines' data
	PayloadSize int64
	// Total number of packets
	Packets int
	// Capabilities announced by the client
	Caps []string
	// Wants is the number of objects the client announced it wants
	Wants int
	// Haves is the number of objects the client announced it has
	Haves int
	// Shallows is the number of shallow boundaries announced by the client
	Shallows int
	// Deepen-filter. One of "deepen <depth>", "deepen-since <timestamp>", "deepen-not <ref>".
	Deepen string
	// Filter-spec specified by the client.
	Filter string
}

func ParsePackfileNegotiation

func ParsePackfileNegotiation(body io.Reader) (PackfileNegotiation, error)

func (*PackfileNegotiation) Parse

func (n *PackfileNegotiation) Parse(body io.Reader) error

Parse parses a packfile negotiation. It expects the following format:

want <OID> <capabilities\n [want <OID>...] [shallow <OID>] [deepen <depth>|deepen-since <timestamp>|deepen-not <ref>] [filter <filter-spec>] flush have <OID> flush|done

func (*PackfileNegotiation) UpdateMetrics

func (n *PackfileNegotiation) UpdateMetrics(metrics *prometheus.CounterVec)

UpdateMetrics updates Prometheus counters with features that have been used during a packfile negotiation.

type PackfilesInfo added in v15.7.0

type PackfilesInfo struct {
	// Count is the number of loose objects, including stale ones.
	Count uint64 `json:"count"`
	// Size is the total size of all loose objects in bytes, including stale ones.
	Size uint64 `json:"size"`
	// ReverseIndexCount is the number of reverse indices.
	ReverseIndexCount uint64 `json:"reverse_index_count"`
	// CruftCount is the number of cruft packfiles which have a .mtimes file.
	CruftCount uint64 `json:"cruft_count"`
	// CruftSize is the size of cruft packfiles which have a .mtimes file.
	CruftSize uint64 `json:"cruft_size"`
	// KeepCount is the number of .keep packfiles.
	KeepCount uint64 `json:"keep_count"`
	// KeepSize is the size of .keep packfiles.
	KeepSize uint64 `json:"keep_size"`
	// GarbageCount is the number of garbage files.
	GarbageCount uint64 `json:"garbage_count"`
	// GarbageSize is the total size of all garbage files in bytes.
	GarbageSize uint64 `json:"garbage_size"`
	// Bitmap contains information about the bitmap, if any exists.
	Bitmap BitmapInfo `json:"bitmap"`
	// HasMultiPackIndex indicates whether there is a multi-pack-index.
	HasMultiPackIndex bool `json:"has_multi_pack_index"`
	// MultiPackIndexBitmap contains information about the bitmap for the multi-pack-index, if
	// any exists.
	MultiPackIndexBitmap BitmapInfo `json:"multi_pack_index_bitmap"`
}

PackfilesInfo contains information about packfiles.

func PackfilesInfoForRepository added in v15.7.0

func PackfilesInfoForRepository(repo *localrepo.Repo) (PackfilesInfo, error)

PackfilesInfoForRepository derives various information about packfiles for the given repository.

type PushCommand

type PushCommand struct {
	// Reference is the reference that shall be updated.
	Reference git.ReferenceName
	// OldOID is the expected state of the reference before being updated.
	OldOID git.ObjectID
	// NewOID is the expected state of the reference after being updated.
	NewOID git.ObjectID
}

PushCommand is a command updating remote references.

type Reference

type Reference struct {
	// Oid is the object ID the reference points to
	Oid string
	// Name of the reference. The name will be suffixed with ^{} in case
	// the reference is the peeled commit.
	Name string
}

Reference as used by the reference discovery protocol

type ReferenceDiscovery

type ReferenceDiscovery struct {
	// FirstPacket tracks the time when the first pktline was received
	FirstPacket time.Time
	// LastPacket tracks the time when the last pktline was received
	LastPacket time.Time
	// PayloadSize tracks the size of all pktlines' data
	PayloadSize int64
	// Packets tracks the total number of packets consumed
	Packets int
	// Refs contains all announced references
	Refs []Reference
	// Caps contains all supported capabilities
	Caps []string
}

ReferenceDiscovery contains information about a reference discovery session.

func ParseReferenceDiscovery

func ParseReferenceDiscovery(body io.Reader) (ReferenceDiscovery, error)

ParseReferenceDiscovery parses a client's reference discovery stream and returns either information about the reference discovery or an error in case it couldn't make sense of the client's request.

func (*ReferenceDiscovery) Parse

func (d *ReferenceDiscovery) Parse(body io.Reader) error

Parse parses a client's reference discovery stream into the given ReferenceDiscovery struct or returns an error in case it couldn't make sense of the client's request.

Expected protocol: - "# service=git-upload-pack\n" - FLUSH - "<OID> <ref>\x00<capabilities>\n" - "<OID> <ref>\n" - ... - FLUSH

type ReferencesInfo added in v15.7.0

type ReferencesInfo struct {
	// LooseReferencesCount is the number of unpacked, loose references that exist.
	LooseReferencesCount uint64 `json:"loose_references_count"`
	// PackedReferencesSize is the size of the packed-refs file in bytes.
	PackedReferencesSize uint64 `json:"packed_references_size"`
}

ReferencesInfo contains information about references.

func ReferencesInfoForRepository added in v15.7.0

func ReferencesInfoForRepository(repo *localrepo.Repo) (ReferencesInfo, error)

ReferencesInfoForRepository derives information about references in the repository.

type RepositoryInfo added in v15.7.0

type RepositoryInfo struct {
	// IsObjectPool determines whether the repository is an object pool or a normal repository.
	IsObjectPool bool `json:"is_object_pool"`
	// LooseObjects contains information about loose objects.
	LooseObjects LooseObjectsInfo `json:"loose_objects"`
	// Packfiles contains information about packfiles.
	Packfiles PackfilesInfo `json:"packfiles"`
	// References contains information about the repository's references.
	References ReferencesInfo `json:"references"`
	// CommitGraph contains information about the repository's commit-graphs.
	CommitGraph CommitGraphInfo `json:"commit_graph"`
	// Alternates is the list of absolute paths of alternate object databases this repository is
	// connected to.
	Alternates []string `json:"alternates"`
}

RepositoryInfo contains information about the repository.

func RepositoryInfoForRepository added in v15.7.0

func RepositoryInfoForRepository(repo *localrepo.Repo) (RepositoryInfo, error)

RepositoryInfoForRepository computes the RepositoryInfo for a repository.

func (RepositoryInfo) Log added in v15.7.0

func (i RepositoryInfo) Log(ctx context.Context)

Log logs the repository information as a structured entry under the `repository_info` field.

type SendPack

type SendPack struct {
	// ReportProgress is an optional callback set by the caller. If set, this function
	// will be called for all received progress packets.
	ReportProgress func([]byte)
	// contains filtered or unexported fields
}

SendPack is used to parse the response body of a git-send-pack(1) request.

func (*SendPack) Parse

func (s *SendPack) Parse(body io.Reader) error

Parse parses the server response from a git-send-pack(1) request. The expected response is documented in git.git:Documentation/techincal/pack-protocol.txt. We expect that the report-status capability is active and thus don't support the report-status-v2 protocol.

Jump to

Keyboard shortcuts

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