githash

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package githash provides types for Git object identifiers.

Index

Constants

View Source
const SHA1Size = 20

SHA1Size is the number of bytes in a SHA-1 hash.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ref added in v0.9.0

type Ref string

A Ref is a Git reference to a commit.

const (
	// Head names the commit on which the changes in the working tree
	// are based.
	Head Ref = "HEAD"

	// FetchHead records the branch which was fetched from a remote
	// repository with the last git fetch invocation.
	FetchHead Ref = "FETCH_HEAD"
)

Top-level refs.

func BranchRef added in v0.9.0

func BranchRef(b string) Ref

BranchRef returns a ref for the given branch name.

func TagRef added in v0.9.0

func TagRef(t string) Ref

TagRef returns a ref for the given tag name.

func (Ref) Branch added in v0.9.0

func (r Ref) Branch() string

Branch returns the string after "refs/heads/" or an empty string if the ref does not start with "refs/heads/".

func (Ref) IsBranch added in v0.9.0

func (r Ref) IsBranch() bool

IsBranch reports whether r starts with "refs/heads/".

func (Ref) IsTag added in v0.9.0

func (r Ref) IsTag() bool

IsTag reports whether r starts with "refs/tags/".

func (Ref) IsValid added in v0.9.0

func (r Ref) IsValid() bool

IsValid reports whether r is a valid reference name. See https://git-scm.com/docs/git-check-ref-format for rules.

func (Ref) String added in v0.9.0

func (r Ref) String() string

String returns the ref as a string.

func (Ref) Tag added in v0.9.0

func (r Ref) Tag() string

Tag returns the string after "refs/tags/" or an empty string if the ref does not start with "refs/tags/".

type SHA1

type SHA1 [SHA1Size]byte

A SHA1 is the SHA-1 hash of a Git object.

func ParseSHA1

func ParseSHA1(s string) (SHA1, error)

ParseSHA1 parses a hex-encoded SHA-1 hash. It is the same as calling UnmarshalText on a new SHA1.

func (SHA1) Format

func (h SHA1) Format(f fmt.State, c rune)

Format implements the fmt.Formatter interface. Specifically, it ensures that %x does not double-hex-encode the data.

func (SHA1) MarshalBinary

func (h SHA1) MarshalBinary() ([]byte, error)

MarshalBinary returns the hash as a byte slice.

func (SHA1) MarshalText

func (h SHA1) MarshalText() ([]byte, error)

MarshalText returns the hex-encoded hash.

func (SHA1) Short

func (h SHA1) Short() string

Short returns the first 4 hex-encoded bytes of the hash.

func (SHA1) String

func (h SHA1) String() string

String returns the hex-encoded hash.

func (*SHA1) UnmarshalBinary

func (h *SHA1) UnmarshalBinary(b []byte) error

UnmarshalBinary copies the bytes from b into h. It returns an error if len(b) != len(*h).

func (*SHA1) UnmarshalText

func (h *SHA1) UnmarshalText(s []byte) error

UnmarshalText decodes a hex-encoded hash into h.

Jump to

Keyboard shortcuts

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