git

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: 15 Imported by: 0

Documentation

Overview

* Wraps access to data needed from Git. * * We invoke Git directly as a subprocess and parse the output rather than using * git2go/libgit2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommitsWithOpts

func CommitsWithOpts(
	ctx context.Context,
	revs []string,
	paths []string,
	filters LogFilters,
	populateDiffs bool,
) (
	iter.Seq2[Commit, error],
	func() error,
	error,
)

Returns an iterator over commits identified by the given revisions and paths.

Also returns a closer() function for cleanup and an error when encountered.

func GetRoot

func GetRoot() (_ string, err error)

func NumCommits

func NumCommits(
	revs []string,
	paths []string,
	filters LogFilters,
) (_ int, err error)

func ParseArgs

func ParseArgs(args []string) (revs []string, paths []string, err error)

Handles splitting the Git revisions from the paths given a list of args.

We call git rev-parse to disambiguate.

func ParseCommits

func ParseCommits(lines iter.Seq2[string, error]) iter.Seq2[Commit, error]

Turns an iterator over lines from git log into an iterator of commits

func RevList

func RevList(
	ctx context.Context,
	revranges []string,
	paths []string,
	filters LogFilters,
) (_ []string, err error)

func WorkingTreeFiles

func WorkingTreeFiles(paths []string) (_ map[string]bool, err error)

Returns all paths in the working tree under the given paths.

Types

type Commit

type Commit struct {
	Hash        string
	ShortHash   string
	IsMerge     bool
	AuthorName  string
	AuthorEmail string
	Date        time.Time
	Subject     string
	FileDiffs   []FileDiff
}

func (Commit) Name

func (c Commit) Name() string

func (Commit) String

func (c Commit) String() string

type FileAction

type FileAction int
const (
	NoAction FileAction = iota
	Create
	Delete
	Rename
)

type FileDiff

type FileDiff struct {
	Path         string
	Action       FileAction
	LinesAdded   int
	LinesRemoved int
	MoveDest     string // Empty unless the file was renamed
}

A file that was changed in a Commit.

func (FileDiff) String

func (d FileDiff) String() string

type LogFilters

type LogFilters struct {
	Since    string
	Authors  []string
	Nauthors []string
}

func (LogFilters) ToArgs

func (f LogFilters) ToArgs() []string

Turn into CLI args we can pass to `git log`

type Subprocess

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

func RunLog

func RunLog(
	ctx context.Context,
	revs []string,
	paths []string,
	filters LogFilters,
	needDiffs bool,
) (*Subprocess, error)

Runs git log

func RunLsFiles

func RunLsFiles(ctx context.Context, paths []string) (*Subprocess, error)

func RunRevList

func RunRevList(
	ctx context.Context,
	revs []string,
	paths []string,
	filters LogFilters,
	countOnly bool,
) (*Subprocess, error)

Runs git rev-list. When countOnly is true, passes --count, which is much faster than printing then getting all the revisions when all you need is the count.

func RunRevParse

func RunRevParse(ctx context.Context, args []string) (*Subprocess, error)

Runs git rev-parse

func RunStdinLog

func RunStdinLog(
	ctx context.Context,
	paths []string,
	needDiffs bool,
) (*Subprocess, error)

Runs git log --stdin

func (Subprocess) StdinWriter

func (s Subprocess) StdinWriter() (_ *bufio.Writer, closer func() error)

func (Subprocess) StdoutLines

func (s Subprocess) StdoutLines() iter.Seq2[string, error]

Returns a single-use iterator over the output of the command, line by line.

func (Subprocess) Wait

func (s Subprocess) Wait() error

type SubprocessErr

type SubprocessErr struct {
	ExitCode int
	Stderr   string
	Err      error
}

func (SubprocessErr) Error

func (err SubprocessErr) Error() string

func (SubprocessErr) Unwrap

func (err SubprocessErr) Unwrap() error

Jump to

Keyboard shortcuts

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