tools

package
v1.4.5-0...-b3ef71d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: MIT Imports: 16 Imported by: 6

Documentation

Overview

Package tools contains other helper functions too small to justify their own package NOTE: Subject to change, do not rely on this package from outside git-lfs source

Set is a modification of https://github.com/deckarep/golang-set The MIT License (MIT) Copyright (c) 2013 Ralph Caraveo (deckarep@gmail.com)

Index

Constants

View Source
const (
	BtrfsIocClone = C.BTRFS_IOC_CLONE
)

Variables

This section is empty.

Functions

func CleanPaths

func CleanPaths(paths, delim string) (cleaned []string)

CleanPaths splits the given `paths` argument by the delimiter argument, and then "cleans" that path according to the path.Clean function (see https://golang.org/pkg/path#Clean). Note always cleans to '/' path separators regardless of platform (git friendly)

func CloneFile

func CloneFile(writer io.Writer, reader io.Reader) (bool, error)

func CopyWithCallback

func CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb progress.CopyCallback) (int64, error)

CopyWithCallback copies reader to writer while performing a progress callback

func DirExists

func DirExists(path string) bool

DirExists determines if a dir (NOT file) exists.

func FastWalkGitRepo

func FastWalkGitRepo(dir string) (<-chan FastWalkInfo, <-chan error)

FastWalkGitRepo is a more optimal implementation of filepath.Walk for a Git repo It differs in the following ways:

  • Provides a channel of information instead of using a callback func
  • Uses goroutines to parallelise large dirs and descent into subdirs
  • Does not provide sorted output; parents will always be before children but there are no other guarantees. Use parentDir in the FastWalkInfo struct to determine absolute path rather than tracking it yourself like filepath.Walk
  • Automatically ignores any .git directories
  • Respects .gitignore contents and skips ignored files/dirs

func FileExists

func FileExists(path string) bool

FileExists determines if a file (NOT dir) exists.

func FileExistsOfSize

func FileExistsOfSize(path string, sz int64) bool

FileExistsOfSize determines if a file exists and is of a specific size.

func FileMatch

func FileMatch(pattern, name string) bool

FileMatch is a revised version of filepath.Match which makes it behave more like gitignore

func FileOrDirExists

func FileOrDirExists(path string) (exists bool, isDir bool)

FileOrDirExists determines if a file/dir exists, returns IsDir() results too.

func FilenamePassesIncludeExcludeFilter

func FilenamePassesIncludeExcludeFilter(filename string, includePaths, excludePaths []string) bool

FilenamePassesIncludeExcludeFilter returns whether a given filename passes the include / exclude path filters Only paths that are in includePaths and outside excludePaths are passed If includePaths is empty that filter always passes and the same with excludePaths Both path lists support wildcard matches

func NewLfsContentHash

func NewLfsContentHash() hash.Hash

Get a new Hash instance of the type used to hash LFS content

func NewReadSeekCloserWrapper

func NewReadSeekCloserWrapper(r io.ReadSeeker) io.ReadCloser

NewReadSeekCloserWrapper wraps an io.ReadSeeker and implements a no-op Close() function to make it an io.ReadCloser

func NewRetriableReader

func NewRetriableReader(r io.Reader) io.Reader

func RenameFileCopyPermissions

func RenameFileCopyPermissions(srcfile, destfile string) error

RenameFileCopyPermissions moves srcfile to destfile, replacing destfile if necessary and also copying the permissions of destfile if it already exists

func ResolveSymlinks(path string) string

ResolveSymlinks ensures that if the path supplied is a symlink, it is resolved to the actual concrete path

func VerifyFileHash

func VerifyFileHash(oid, path string) error

VerifyFileHash reads a file and verifies whether the SHA is correct Returns an error if there is a problem

Types

type FastWalkInfo

type FastWalkInfo struct {
	ParentDir string
	Info      os.FileInfo
}

Returned from FastWalk with parent directory context This is needed because FastWalk can provide paths out of order so the parent dir cannot be implied

type HashingReader

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

HashingReader wraps a reader and calculates the hash of the data as it is read

func NewHashingReader

func NewHashingReader(r io.Reader) *HashingReader

func NewHashingReaderPreloadHash

func NewHashingReaderPreloadHash(r io.Reader, hash hash.Hash) *HashingReader

func (*HashingReader) Hash

func (r *HashingReader) Hash() string

func (*HashingReader) Read

func (r *HashingReader) Read(b []byte) (int, error)

type RetriableReader

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

RetriableReader wraps a error response of reader as RetriableError()

func (*RetriableReader) Read

func (r *RetriableReader) Read(b []byte) (int, error)

type StringSet

type StringSet map[string]struct{}

The primary type that represents a set

func NewStringSet

func NewStringSet() StringSet

Creates and returns a reference to an empty set.

func NewStringSetFromSlice

func NewStringSetFromSlice(s []string) StringSet

Creates and returns a reference to a set from an existing slice

func NewStringSetWithCapacity

func NewStringSetWithCapacity(capacity int) StringSet

Creates and returns a reference to an empty set with a capacity.

func (StringSet) Add

func (set StringSet) Add(i string) bool

Adds an item to the current set if it doesn't already exist in the set.

func (StringSet) Cardinality

func (set StringSet) Cardinality() int

Cardinality returns how many items are currently in the set.

func (*StringSet) Clear

func (set *StringSet) Clear()

Clears the entire set to be the empty set.

func (StringSet) Clone

func (set StringSet) Clone() StringSet

Returns a clone of the set. Does NOT clone the underlying elements.

func (StringSet) Contains

func (set StringSet) Contains(i string) bool

Determines if a given item is already in the set.

func (StringSet) ContainsAll

func (set StringSet) ContainsAll(i ...string) bool

Determines if the given items are all in the set

func (StringSet) Difference

func (set StringSet) Difference(other StringSet) StringSet

Returns a new set with items in the current set but not in the other set

func (StringSet) Equal

func (set StringSet) Equal(other StringSet) bool

Equal determines if two sets are equal to each other. If they both are the same size and have the same items they are considered equal. Order of items is not relevent for sets to be equal.

func (StringSet) Intersect

func (set StringSet) Intersect(other StringSet) StringSet

Returns a new set with items that exist only in both sets.

func (StringSet) IsSubset

func (set StringSet) IsSubset(other StringSet) bool

Determines if every item in the other set is in this set.

func (StringSet) IsSuperset

func (set StringSet) IsSuperset(other StringSet) bool

Determines if every item of this set is in the other set.

func (StringSet) Iter

func (set StringSet) Iter() <-chan string

Iter() returns a channel of type string that you can range over.

func (StringSet) Remove

func (set StringSet) Remove(i string)

Allows the removal of a single item in the set.

func (StringSet) SymmetricDifference

func (set StringSet) SymmetricDifference(other StringSet) StringSet

Returns a new set with items in the current set or the other set but not in both.

func (StringSet) Union

func (set StringSet) Union(other StringSet) StringSet

Returns a new set with all items in both sets.

Jump to

Keyboard shortcuts

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