tally

package
v0.0.0-...-d1a71fa Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Handles summations over commits.

Index

Constants

View Source
const NoDiffPathname = ".git-who-no-diff-commits"

Variables

View Source
var EmptyTreeErr = errors.New("No commits; tree is empty.")

Functions

func TallyCommits

func TallyCommits(
	commits iter.Seq2[git.Commit, error],
	opts TallyOpts,
) (map[string]Tally, error)

Types

type FinalTally

type FinalTally struct {
	AuthorName     string
	AuthorEmail    string
	Commits        int // Num commits editing paths in tree by this author
	LinesAdded     int // Num lines added to paths in tree by author
	LinesRemoved   int // Num lines deleted from paths in tree by author
	FileCount      int // Num of file paths in working dir touched by author
	LastCommitTime time.Time
}

Metrics tallied for a single author while walking git log.

This kind of tally cannot be combined with others because intermediate information has been lost.

func Rank

func Rank(tallies map[string]Tally, mode TallyMode) []FinalTally

Sort tallies according to mode.

func (FinalTally) Compare

func (a FinalTally) Compare(b FinalTally, mode TallyMode) int

func (FinalTally) SortKey

func (t FinalTally) SortKey(mode TallyMode) int64

type Resolution

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

Resolution for a time series.

apply - Truncate time to its time bucket label - Format the date to a label for the bucket next - Get next time in series, given a time

func CalcResolution

func CalcResolution(start time.Time, end time.Time) Resolution

type TalliesByPath

type TalliesByPath map[string]map[string]Tally

func TallyCommitsByPath

func TallyCommitsByPath(
	commits iter.Seq2[git.Commit, error],
	opts TallyOpts,
) (TalliesByPath, error)

Tally metrics per author per path.

func (TalliesByPath) Combine

func (left TalliesByPath) Combine(right TalliesByPath) TalliesByPath

func (TalliesByPath) Reduce

func (byPath TalliesByPath) Reduce() map[string]Tally

Reduce by-path tallies to a single tally for each author.

type Tally

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

A non-final tally that can be combined with other tallies and then finalized

func (Tally) Combine

func (a Tally) Combine(b Tally) Tally

func (Tally) Final

func (t Tally) Final() FinalTally

type TallyMode

type TallyMode int

Whether we rank authors by commit, lines, or files.

const (
	CommitMode TallyMode = iota
	LinesMode
	FilesMode
	LastModifiedMode
)

type TallyOpts

type TallyOpts struct {
	Mode        TallyMode
	Key         func(c git.Commit) string // Unique ID for author
	CountMerges bool
}

func (TallyOpts) IsDiffMode

func (opts TallyOpts) IsDiffMode() bool

Whether we need --stat and --summary data from git log for this tally mode

type TimeBucket

type TimeBucket struct {
	Name       string
	Time       time.Time
	Tally      FinalTally // Winning author's tally
	TotalTally FinalTally // Overall tally for all authors
	// contains filtered or unexported fields
}

func Rebucket

func Rebucket(
	buckets []TimeBucket,
	resolution Resolution,
	end time.Time,
) []TimeBucket

func TallyCommitsByDate

func TallyCommitsByDate(
	commits iter.Seq2[git.Commit, error],
	opts TallyOpts,
	end time.Time,
) (_ []TimeBucket, err error)

Returns tallies grouped by calendar date.

func TallyCommitsTimeline

func TallyCommitsTimeline(
	commits iter.Seq2[git.Commit, error],
	opts TallyOpts,
	end time.Time,
) ([]TimeBucket, error)

Returns a list of "time buckets" with tallies for each date.

The resolution / size of the buckets is determined based on the duration between the first commit and end time.

func (TimeBucket) Combine

func (a TimeBucket) Combine(b TimeBucket) TimeBucket

func (TimeBucket) Rank

func (b TimeBucket) Rank(mode TallyMode) TimeBucket

func (TimeBucket) TotalValue

func (b TimeBucket) TotalValue(mode TallyMode) int

func (TimeBucket) Value

func (b TimeBucket) Value(mode TallyMode) int

type TimeSeries

type TimeSeries []TimeBucket

func (TimeSeries) Combine

func (a TimeSeries) Combine(b TimeSeries) TimeSeries

type TreeNode

type TreeNode struct {
	Tally      FinalTally
	Children   map[string]*TreeNode
	InWorkTree bool // In git working tree/directory
	// contains filtered or unexported fields
}

A file tree of edits to the repo

func TallyCommitsTree

func TallyCommitsTree(
	commits iter.Seq2[git.Commit, error],
	opts TallyOpts,
	worktreePaths map[string]bool,
	gitRootPath string,
) (*TreeNode, error)

* TallyCommitsTree() returns a tree of nodes mirroring the working directory * with a tally for each node.

func TallyCommitsTreeFromPaths

func TallyCommitsTreeFromPaths(
	talliesByPath TalliesByPath,
	worktreePaths map[string]bool,
	gitRootPath string,
) (*TreeNode, error)

func (*TreeNode) Rank

func (t *TreeNode) Rank(mode TallyMode) *TreeNode

func (*TreeNode) String

func (t *TreeNode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳