deflect

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxLooseObjects is the threshold for "too many" loose objects (1000)
	MaxLooseObjects = 1000
	// MaxPacks is the threshold for "too many" pack files (3)
	MaxPacks = 3
	// MinPackSize is the minimum size (4GB) for considering packs as "small" in housekeeping
	MinPackSize = 4 * strengthen.GiByte
)
View Source
const (
	// DefaultFileSizeLimit is the default file size threshold (50 MiB) for identifying large files
	DefaultFileSizeLimit = strengthen.MiByte * 50
)
View Source
const (
	// ENV_GIT_QUARANTINE_PATH is the environment variable used by Git for incoming objects
	ENV_GIT_QUARANTINE_PATH = "GIT_QUARANTINE_PATH"
)
View Source
const (

	// VersionSupported is the only pack index version supported (v2)
	// Version 3 supports SHA1/SHA256 hybrid object storage but we only support v2
	VersionSupported uint32 = 2
)

Variables

View Source
var (
	// ErrUnsupportedVersion is returned when the pack index file version is not supported
	ErrUnsupportedVersion = errors.New("idxfile: Unsupported version")
	// ErrMalformedIdxFile is returned when the pack index file is corrupted or invalid
	ErrMalformedIdxFile = errors.New("idxfile: Malformed IDX file")
)

Functions

func Du

func Du(repoPath string) (int64, error)

Du is a convenience function that calculates the total disk usage of a Git repository Returns the total size in bytes and any error encountered

func ReadDir

func ReadDir(name string) ([]os.DirEntry, error)

ReadDir reads directory entries from the specified path Returns a slice of directory entries or an error

Types

type Auditor added in v0.22.0

type Auditor struct {
	*Option // Embedded auditing configuration
	// contains filtered or unexported fields
}

Auditor is the main analyzer for Git repository large file detection

func NewAuditor added in v0.22.0

func NewAuditor(repoPath string, shaFormat git.HashFormat, opts *Option) *Auditor

NewAuditor creates a new Auditor instance for analyzing a Git repository Parameters:

  • repoPath: path to the Git repository directory
  • shaFormat: the hash format (SHA1 or SHA256) used by the repository
  • opts: optional filtering configuration (nil for defaults)

func (*Auditor) Counts added in v0.22.0

func (a *Auditor) Counts() uint32

Counts returns the total number of objects analyzed

func (*Auditor) Delta added in v0.22.0

func (a *Auditor) Delta() int64

Delta returns the size increment for quarantine mode analysis

func (*Auditor) Du added in v0.22.0

func (a *Auditor) Du() error

Du performs disk usage analysis of the Git repository In quarantine mode, also analyzes incoming objects in GIT_QUARANTINE_PATH

func (*Auditor) Execute added in v0.22.0

func (a *Auditor) Execute() error

Execute performs the complete repository analysis: 1. Analyzes disk usage of loose objects and pack files 2. Calls the SizeReceiver callback with total size if provided 3. Analyzes each pack file for large objects

func (*Auditor) GarbageCount added in v0.27.0

func (a *Auditor) GarbageCount() uint32

GarbageCount returns the number of garbage files (tmp_* files in pack directory)

func (*Auditor) GarbageSize added in v0.27.0

func (a *Auditor) GarbageSize() int64

GarbageSize returns the total size of garbage files in bytes

func (*Auditor) HashLen added in v0.22.0

func (a *Auditor) HashLen() int64

HashLen returns the hash length in bytes (20 for SHA1, 32 for SHA256)

func (*Auditor) HugeSUM added in v0.22.0

func (a *Auditor) HugeSUM() int64

HugeSUM returns the total size of files exceeding hugeSizeLimit

func (*Auditor) Size added in v0.22.0

func (a *Auditor) Size() int64

Size returns the total size of all objects in bytes

type Option added in v0.22.0

type Option struct {
	// Limit is the file size threshold in bytes. Files larger than this will be rejected.
	Limit int64
	// OnOversized is a callback function called for each file that exceeds the limit.
	// Returns an error to stop processing, or nil to continue.
	OnOversized func(oid string, size int64) error
	// QuarantineMode enables analysis of incoming objects in Git quarantine mode.
	// When enabled, analyzes both the main repository and quarantine directory.
	QuarantineMode bool
}

Option configures the auditing behavior for repository analysis

type Pack

type Pack struct {
	Name string // Full path to pack file
	Size int64  // Size in bytes
}

Pack represents a Git pack file with its name and size

type Result

type Result struct {
	Size         int64   // Total repository size in bytes (excludes garbage files)
	LooseObjects int     // Number of loose objects
	Packs        []*Pack // List of pack files
	GarbageCount uint32  // Count of garbage files (tmp_* in pack directory)
	GarbageSize  int64   // Total size of garbage files in bytes
}

Result contains the results of repository housekeeping scan

func HousekeepingScan

func HousekeepingScan(repoPath string) (*Result, error)

HousekeepingScan performs a repository housekeeping analysis Returns Result struct with repository statistics and maintenance status This function is useful for determining if a repository needs git gc/repack

func (*Result) IsUntidy

func (r *Result) IsUntidy() bool

IsUntidy determines if the repository needs housekeeping/maintenance Returns true if any of these conditions are met: - Has garbage files (tmp_* in pack directory) - Has too many loose objects (> 1000) - Has many pack files (> 3) and at least one is small (< 4GB)

Jump to

Keyboard shortcuts

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