gitattr

package
v2.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attr

type Attr struct {
	// K is the name of the attribute. It is commonly, "filter", "diff",
	// "merge", or "text".
	//
	// It will never contain the special "false" shorthand ("-"), or the
	// unspecify declarative ("!").
	K string
	// V is the value held by that attribute. It is commonly "lfs", or
	// "false", indicating the special value given by a "-"-prefixed name.
	V string
	// Unspecified indicates whether or not this attribute was explicitly
	// unset by prefixing the keyname with "!".
	Unspecified bool
}

Attr is a single attribute that may be applied to a file.

type Line

type Line struct {
	// Pattern is a wildmatch pattern that, when matched, indicates that all
	// of the below attributes (Attrs) should be applied to that tree entry.
	//
	// Pattern is relative to the tree in which the .gitattributes was read
	// from. For example, /.gitattributes affects all blobs in the
	// repository, while /path/to/.gitattributes affects all blobs that are
	// direct or indirect children of /path/to.
	Pattern *wildmatch.Wildmatch
	// Attrs is the list of attributes to be applied when the above pattern
	// matches a given filename.
	//
	// It is populated in-order as it was written in the .gitattributes file
	// being read, from left to right.
	Attrs []*Attr
}

Line carries a single line from a repository's .gitattributes file, affecting a single pattern and applying zero or more attributes.

func ParseLines

func ParseLines(r io.Reader) ([]*Line, error)

ParseLines parses the given io.Reader "r" line-wise as if it were the contents of a .gitattributes file.

If an error was encountered, it will be returned and the []*Line should be considered unusable.

type Tree

type Tree struct {
	// Lines are the lines of the .gitattributes at this level of the tree.
	Lines []*Line
	// Children are the named child directories in the repository.
	Children map[string]*Tree
}

Tree represents the .gitattributes file at one layer of the tree in a Git repository.

func New

func New(db *gitobj.ObjectDatabase, t *gitobj.Tree) (*Tree, error)

New constructs a *Tree starting at the given tree "t" and reading objects from the given ObjectDatabase. If a tree was not able to be read, an error will be propagated up accordingly.

func (*Tree) Applied

func (t *Tree) Applied(to string) []*Attr

Applied returns a slice of attributes applied to the given path, relative to the receiving tree. It traverse through sub-trees in a topological ordering, if there are relevant .gitattributes matching that path.

Jump to

Keyboard shortcuts

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