languages

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBreakdown

func FormatBreakdown(breakdown []LanguageBreakdown) string

FormatBreakdown formats a language breakdown slice into a human-readable string. Example output: "Go: 12345 bytes (67%) | Python: 5678 bytes (33%)"

func GetHeadCommit

func GetHeadCommit(repoPath string) (string, error)

GetHeadCommit returns the HEAD commit SHA for a git repository.

func LanguageForFile

func LanguageForFile(filePath string) string

LanguageForFile returns the language name for a given file path, or empty string if the file type is not recognized. It checks exact filename first, then falls back to extension matching.

Types

type LanguageBreakdown

type LanguageBreakdown struct {
	Name    string `json:"name"`
	Size    int64  `json:"size"`
	Percent int    `json:"percent"` // floor of (size/total * 100)
}

LanguageBreakdown represents one language's share of a repository.

func DetectLanguages

func DetectLanguages(repoPath string) ([]LanguageBreakdown, error)

DetectLanguages analyzes a git repository at the given path and returns a sorted list of language breakdowns (most bytes first). It uses `git ls-tree -r -l HEAD` to enumerate tracked files with their sizes.

func ParseLsTree

func ParseLsTree(output string) ([]LanguageBreakdown, error)

ParseLsTree parses the output of `git ls-tree -r -l HEAD` and returns language breakdowns. Exported for testability.

Each line has the format:

<mode> <type> <hash> <size>\t<path>

Example:

100644 blob abc123  1234\tmain.go

Jump to

Keyboard shortcuts

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