diffsource

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxInputBytes = 16 * 1024 * 1024
	MaxFileBytes  = 2 * 1024 * 1024
)
View Source
const MaxCommits = review.MaxCommits

MaxCommits is how many of a branch's newest commits Commits captures, so object prefetchers cover exactly what collection reads.

Variables

View Source
var ErrComparisonUnavailable = errors.New("comparison source unavailable")

ErrComparisonUnavailable permits replaying an already captured comparison after its local refs disappear. It never masks process or cancellation errors.

View Source
var ErrNoDefaultBranch = errors.New("no default branch available for comparison")

ErrNoDefaultBranch means no existing default branch ref can be resolved.

View Source
var ErrNotRepository = errors.New("not a Git working tree")

Functions

func ActivityTime added in v0.2.1

func ActivityTime(ctx context.Context, source Source, head *string, gitDir string) (int64, error)

ActivityTime estimates code activity for the captured target. Objects-only comparisons never consult the unrelated checkout's files or index.

func BranchCheckoutKey

func BranchCheckoutKey(repositoryKey, branchID string) string

BranchCheckoutKey identifies an object-only branch source after its checkout disappears. It never depends on the surviving checkout's path or branch name.

func ContentHash

func ContentHash(ctx context.Context, source Source, snapshots []review.RepositoryDiff) (string, error)

ContentHash identifies complete Git contents independently of filesystem timestamps and preview limits. An empty hash means complete identity cannot be proven, so callers must not deduplicate changed snapshots by content.

func CurrentBranch

func CurrentBranch(ctx context.Context, root string) (string, error)

CurrentBranch returns the same branch label as a snapshot without reading checkout diffs or file contents.

func DefaultBaselines added in v0.2.1

func DefaultBaselines(ctx context.Context, root string) ([]string, error)

DefaultBaselines resolves existing refs for the first default branch name (`origin/HEAD`, `main`, then `master`) with a local or remote-tracking ref: the local branch first, then its remote-tracking upstream or origin counterpart. It never fetches or consults a feature branch's upstream, which may simply track that same feature branch.

func Error

func Error(status int, format string, values ...any) error

func GitRuntime added in v0.2.4

func GitRuntime(ctx context.Context) (path, version string)

GitRuntime reads only build/runtime facts through the same bounded runner.

func Message

func Message(value string) *string

func PatchContext

func PatchContext(patch, side string, start, end int) (string, bool)

func PrepareCommitSnapshots added in v0.2.4

func PrepareCommitSnapshots(ctx context.Context, source Source, commits []review.Commit) error

PrepareCommitSnapshots reads immutable commit metadata in two processes, retaining raw modes/OIDs without changing the stored source contract.

func PreviewUnavailable

func PreviewUnavailable(err error) bool

PreviewUnavailable distinguishes intentional preview limits from failures requiring collection to stop (including cancellation and concurrent edits).

func RemoteRepositoryName

func RemoteRepositoryName(remote, fallback string) string

RemoteRepositoryName extracts the display name from URL and SCP-style remotes.

func RepositoryIdentity

func RepositoryIdentity(ctx context.Context, root string) (commonDir, worktreeDir string, err error)

func WithCollectionDeadline added in v0.2.4

func WithCollectionDeadline(ctx, parent context.Context) context.Context

func WithCommandObserver added in v0.2.4

func WithCommandObserver(ctx context.Context, observer CommandObserver) context.Context

Types

type CollectionPreviews added in v0.2.4

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

CollectionPreviews owns only collection-local bounded reads. Stored Sources retain their scalar API; callers choose the bulk reader at collection time.

func NewCollectionPreviews added in v0.2.4

func NewCollectionPreviews(source Source) *CollectionPreviews

func (*CollectionPreviews) Contents added in v0.2.4

func (*CollectionPreviews) Patch added in v0.2.4

func (*CollectionPreviews) PreparePatches added in v0.2.4

func (reader *CollectionPreviews) PreparePatches(ctx context.Context, snapshots []review.RepositoryDiff, maximum, budget int) error

PreparePatches streams comparisons independently and immutable commits in one diff-tree process. The cache retains at most the request's preview budget; a cache miss later reads a small file batch, preserving allocator semantics.

type CommandObserver added in v0.2.4

type CommandObserver interface {
	BeginCommand(root, operation, scope string) func(CommandResult)
	Cleanup(string, error)
}

CommandObserver is supplied by composition, never by a global logger. Operations contain the Git subcommand only, never argv or process output.

type CommandResult added in v0.2.4

type CommandResult struct {
	QueueWait    time.Duration
	Elapsed      time.Duration
	StdoutBytes  int64
	StderrBytes  int64
	ExitStatus   *int
	DeadlineKind string
	Err          error
}

type CommitRange added in v0.2.2

type CommitRange struct {
	Commits []review.Commit
	Total   int
}

CommitRange is a branch comparison's captured commits, oldest first. Total counts the whole merge-base..HEAD range, including commits beyond the cap.

func Commits added in v0.2.2

func Commits(ctx context.Context, source Source) (CommitRange, bool, error)

Commits lists the newest MaxCommits commits of a branch comparison's merge-base..HEAD range, oldest first. False means the source has no branch baseline, so it has no commits to capture.

type Comparison

type Comparison struct {
	BaseRef     string
	BaseCommit  string
	BaseOID     string
	HeadOID     string
	ObjectsOnly bool
}

func ComparisonInfo

func ComparisonInfo(source Source) (Comparison, bool)

ComparisonInfo reports the captured comparison, including its merge base. A false result denotes ordinary checkout collection against HEAD.

type RepositoryMetadata

type RepositoryMetadata struct {
	CommonDir string
	GitDir    string
	RemoteURL string
}

RepositoryMetadata contains checkout facts without collecting its diff.

func Metadata

func Metadata(ctx context.Context, root string) (RepositoryMetadata, error)

type RequestError

type RequestError = review.RequestError

type Source

type Source = review.Source

func CommitSource added in v0.2.2

func CommitSource(ctx context.Context, source Source, commit review.Commit) (Source, error)

CommitSource reads one captured commit's diff against its first parent, within the branch comparison that listed it.

func OpenComparison

func OpenComparison(ctx context.Context, directory, base, branch string) (Source, error)

OpenComparison captures a branch comparison without switching or creating a checkout. An empty branch reads the current checkout; a named branch reads immutable objects only, ignoring the current checkout's index and files.

func OpenPatch

func OpenPatch(input string) (Source, error)

func OpenRepository

func OpenRepository(ctx context.Context, directory string) (Source, error)

type StableRepositoryIdentity

type StableRepositoryIdentity struct {
	RepositoryKey string
	CheckoutKey   string
	BranchID      string
}

StableRepositoryIdentity persists provenance independently of mutable labels.

func StableIdentity

func StableIdentity(ctx context.Context, root, sourceID, branch string) (StableRepositoryIdentity, error)

StableIdentity adopts existing repository/checkout keys once, then preserves them through directory moves, remote changes, and Git branch renames. Copying Git metadata also copies identities; an independent clone has new metadata.

type Support

type Support = review.Support

type Worktree

type Worktree struct {
	Root   string
	Branch string
	Linked bool
}

Worktree describes a checkout without reading its diff or file contents.

func RepositoryWorktrees

func RepositoryWorktrees(ctx context.Context, root string) (string, []Worktree, error)

type WorktreeChangeSummary

type WorktreeChangeSummary struct {
	LastChangedAt    int64
	ChangedFileCount int
}

func WorktreeChanges

func WorktreeChanges(ctx context.Context, root, gitDir string) (WorktreeChangeSummary, error)

WorktreeChanges reads local change counts and times without loading diffs.

Jump to

Keyboard shortcuts

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