Add Makefile / .drone.yml, use go module with vendor (#20)
* add Makefile / .drone.yml, use go module with vendor * Update .drone.yml Co-Authored-By: lunny <xiaolunwen@gmail.com>
This commit is contained in:
35
vendor/gopkg.in/src-d/go-git.v4/plumbing/error.go
generated
vendored
Normal file
35
vendor/gopkg.in/src-d/go-git.v4/plumbing/error.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
package plumbing
|
||||
|
||||
import "fmt"
|
||||
|
||||
type PermanentError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func NewPermanentError(err error) *PermanentError {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &PermanentError{Err: err}
|
||||
}
|
||||
|
||||
func (e *PermanentError) Error() string {
|
||||
return fmt.Sprintf("permanent client error: %s", e.Err.Error())
|
||||
}
|
||||
|
||||
type UnexpectedError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func NewUnexpectedError(err error) *UnexpectedError {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &UnexpectedError{Err: err}
|
||||
}
|
||||
|
||||
func (e *UnexpectedError) Error() string {
|
||||
return fmt.Sprintf("unexpected client error: %s", e.Err.Error())
|
||||
}
|
||||
99
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/common.go
generated
vendored
Normal file
99
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/common.go
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
package config
|
||||
|
||||
// New creates a new config instance.
|
||||
func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
// Config contains all the sections, comments and includes from a config file.
|
||||
type Config struct {
|
||||
Comment *Comment
|
||||
Sections Sections
|
||||
Includes Includes
|
||||
}
|
||||
|
||||
// Includes is a list of Includes in a config file.
|
||||
type Includes []*Include
|
||||
|
||||
// Include is a reference to an included config file.
|
||||
type Include struct {
|
||||
Path string
|
||||
Config *Config
|
||||
}
|
||||
|
||||
// Comment string without the prefix '#' or ';'.
|
||||
type Comment string
|
||||
|
||||
const (
|
||||
// NoSubsection token is passed to Config.Section and Config.SetSection to
|
||||
// represent the absence of a section.
|
||||
NoSubsection = ""
|
||||
)
|
||||
|
||||
// Section returns a existing section with the given name or creates a new one.
|
||||
func (c *Config) Section(name string) *Section {
|
||||
for i := len(c.Sections) - 1; i >= 0; i-- {
|
||||
s := c.Sections[i]
|
||||
if s.IsName(name) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
s := &Section{Name: name}
|
||||
c.Sections = append(c.Sections, s)
|
||||
return s
|
||||
}
|
||||
|
||||
// AddOption adds an option to a given section and subsection. Use the
|
||||
// NoSubsection constant for the subsection argument if no subsection is wanted.
|
||||
func (c *Config) AddOption(section string, subsection string, key string, value string) *Config {
|
||||
if subsection == "" {
|
||||
c.Section(section).AddOption(key, value)
|
||||
} else {
|
||||
c.Section(section).Subsection(subsection).AddOption(key, value)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// SetOption sets an option to a given section and subsection. Use the
|
||||
// NoSubsection constant for the subsection argument if no subsection is wanted.
|
||||
func (c *Config) SetOption(section string, subsection string, key string, value string) *Config {
|
||||
if subsection == "" {
|
||||
c.Section(section).SetOption(key, value)
|
||||
} else {
|
||||
c.Section(section).Subsection(subsection).SetOption(key, value)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// RemoveSection removes a section from a config file.
|
||||
func (c *Config) RemoveSection(name string) *Config {
|
||||
result := Sections{}
|
||||
for _, s := range c.Sections {
|
||||
if !s.IsName(name) {
|
||||
result = append(result, s)
|
||||
}
|
||||
}
|
||||
|
||||
c.Sections = result
|
||||
return c
|
||||
}
|
||||
|
||||
// RemoveSubsection remove s a subsection from a config file.
|
||||
func (c *Config) RemoveSubsection(section string, subsection string) *Config {
|
||||
for _, s := range c.Sections {
|
||||
if s.IsName(section) {
|
||||
result := Subsections{}
|
||||
for _, ss := range s.Subsections {
|
||||
if !ss.IsName(subsection) {
|
||||
result = append(result, ss)
|
||||
}
|
||||
}
|
||||
s.Subsections = result
|
||||
}
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
37
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/decoder.go
generated
vendored
Normal file
37
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/decoder.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/src-d/gcfg"
|
||||
)
|
||||
|
||||
// A Decoder reads and decodes config files from an input stream.
|
||||
type Decoder struct {
|
||||
io.Reader
|
||||
}
|
||||
|
||||
// NewDecoder returns a new decoder that reads from r.
|
||||
func NewDecoder(r io.Reader) *Decoder {
|
||||
return &Decoder{r}
|
||||
}
|
||||
|
||||
// Decode reads the whole config from its input and stores it in the
|
||||
// value pointed to by config.
|
||||
func (d *Decoder) Decode(config *Config) error {
|
||||
cb := func(s string, ss string, k string, v string, bv bool) error {
|
||||
if ss == "" && k == "" {
|
||||
config.Section(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
if ss != "" && k == "" {
|
||||
config.Section(s).Subsection(ss)
|
||||
return nil
|
||||
}
|
||||
|
||||
config.AddOption(s, ss, k, v)
|
||||
return nil
|
||||
}
|
||||
return gcfg.ReadWithCallback(d, cb)
|
||||
}
|
||||
122
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/doc.go
generated
vendored
Normal file
122
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/doc.go
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
// Package config implements encoding and decoding of git config files.
|
||||
//
|
||||
// Configuration File
|
||||
// ------------------
|
||||
//
|
||||
// The Git configuration file contains a number of variables that affect
|
||||
// the Git commands' behavior. The `.git/config` file in each repository
|
||||
// is used to store the configuration for that repository, and
|
||||
// `$HOME/.gitconfig` is used to store a per-user configuration as
|
||||
// fallback values for the `.git/config` file. The file `/etc/gitconfig`
|
||||
// can be used to store a system-wide default configuration.
|
||||
//
|
||||
// The configuration variables are used by both the Git plumbing
|
||||
// and the porcelains. The variables are divided into sections, wherein
|
||||
// the fully qualified variable name of the variable itself is the last
|
||||
// dot-separated segment and the section name is everything before the last
|
||||
// dot. The variable names are case-insensitive, allow only alphanumeric
|
||||
// characters and `-`, and must start with an alphabetic character. Some
|
||||
// variables may appear multiple times; we say then that the variable is
|
||||
// multivalued.
|
||||
//
|
||||
// Syntax
|
||||
// ~~~~~~
|
||||
//
|
||||
// The syntax is fairly flexible and permissive; whitespaces are mostly
|
||||
// ignored. The '#' and ';' characters begin comments to the end of line,
|
||||
// blank lines are ignored.
|
||||
//
|
||||
// The file consists of sections and variables. A section begins with
|
||||
// the name of the section in square brackets and continues until the next
|
||||
// section begins. Section names are case-insensitive. Only alphanumeric
|
||||
// characters, `-` and `.` are allowed in section names. Each variable
|
||||
// must belong to some section, which means that there must be a section
|
||||
// header before the first setting of a variable.
|
||||
//
|
||||
// Sections can be further divided into subsections. To begin a subsection
|
||||
// put its name in double quotes, separated by space from the section name,
|
||||
// in the section header, like in the example below:
|
||||
//
|
||||
// --------
|
||||
// [section "subsection"]
|
||||
//
|
||||
// --------
|
||||
//
|
||||
// Subsection names are case sensitive and can contain any characters except
|
||||
// newline (doublequote `"` and backslash can be included by escaping them
|
||||
// as `\"` and `\\`, respectively). Section headers cannot span multiple
|
||||
// lines. Variables may belong directly to a section or to a given subsection.
|
||||
// You can have `[section]` if you have `[section "subsection"]`, but you
|
||||
// don't need to.
|
||||
//
|
||||
// There is also a deprecated `[section.subsection]` syntax. With this
|
||||
// syntax, the subsection name is converted to lower-case and is also
|
||||
// compared case sensitively. These subsection names follow the same
|
||||
// restrictions as section names.
|
||||
//
|
||||
// All the other lines (and the remainder of the line after the section
|
||||
// header) are recognized as setting variables, in the form
|
||||
// 'name = value' (or just 'name', which is a short-hand to say that
|
||||
// the variable is the boolean "true").
|
||||
// The variable names are case-insensitive, allow only alphanumeric characters
|
||||
// and `-`, and must start with an alphabetic character.
|
||||
//
|
||||
// A line that defines a value can be continued to the next line by
|
||||
// ending it with a `\`; the backquote and the end-of-line are
|
||||
// stripped. Leading whitespaces after 'name =', the remainder of the
|
||||
// line after the first comment character '#' or ';', and trailing
|
||||
// whitespaces of the line are discarded unless they are enclosed in
|
||||
// double quotes. Internal whitespaces within the value are retained
|
||||
// verbatim.
|
||||
//
|
||||
// Inside double quotes, double quote `"` and backslash `\` characters
|
||||
// must be escaped: use `\"` for `"` and `\\` for `\`.
|
||||
//
|
||||
// The following escape sequences (beside `\"` and `\\`) are recognized:
|
||||
// `\n` for newline character (NL), `\t` for horizontal tabulation (HT, TAB)
|
||||
// and `\b` for backspace (BS). Other char escape sequences (including octal
|
||||
// escape sequences) are invalid.
|
||||
//
|
||||
// Includes
|
||||
// ~~~~~~~~
|
||||
//
|
||||
// You can include one config file from another by setting the special
|
||||
// `include.path` variable to the name of the file to be included. The
|
||||
// variable takes a pathname as its value, and is subject to tilde
|
||||
// expansion.
|
||||
//
|
||||
// The included file is expanded immediately, as if its contents had been
|
||||
// found at the location of the include directive. If the value of the
|
||||
// `include.path` variable is a relative path, the path is considered to be
|
||||
// relative to the configuration file in which the include directive was
|
||||
// found. See below for examples.
|
||||
//
|
||||
//
|
||||
// Example
|
||||
// ~~~~~~~
|
||||
//
|
||||
// # Core variables
|
||||
// [core]
|
||||
// ; Don't trust file modes
|
||||
// filemode = false
|
||||
//
|
||||
// # Our diff algorithm
|
||||
// [diff]
|
||||
// external = /usr/local/bin/diff-wrapper
|
||||
// renames = true
|
||||
//
|
||||
// [branch "devel"]
|
||||
// remote = origin
|
||||
// merge = refs/heads/devel
|
||||
//
|
||||
// # Proxy settings
|
||||
// [core]
|
||||
// gitProxy="ssh" for "kernel.org"
|
||||
// gitProxy=default-proxy ; for the rest
|
||||
//
|
||||
// [include]
|
||||
// path = /path/to/foo.inc ; include by absolute path
|
||||
// path = foo ; expand "foo" relative to the current file
|
||||
// path = ~/foo ; expand "foo" in your `$HOME` directory
|
||||
//
|
||||
package config
|
||||
77
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/encoder.go
generated
vendored
Normal file
77
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/encoder.go
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// An Encoder writes config files to an output stream.
|
||||
type Encoder struct {
|
||||
w io.Writer
|
||||
}
|
||||
|
||||
// NewEncoder returns a new encoder that writes to w.
|
||||
func NewEncoder(w io.Writer) *Encoder {
|
||||
return &Encoder{w}
|
||||
}
|
||||
|
||||
// Encode writes the config in git config format to the stream of the encoder.
|
||||
func (e *Encoder) Encode(cfg *Config) error {
|
||||
for _, s := range cfg.Sections {
|
||||
if err := e.encodeSection(s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeSection(s *Section) error {
|
||||
if len(s.Options) > 0 {
|
||||
if err := e.printf("[%s]\n", s.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := e.encodeOptions(s.Options); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, ss := range s.Subsections {
|
||||
if err := e.encodeSubsection(s.Name, ss); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeSubsection(sectionName string, s *Subsection) error {
|
||||
//TODO: escape
|
||||
if err := e.printf("[%s \"%s\"]\n", sectionName, s.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return e.encodeOptions(s.Options)
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeOptions(opts Options) error {
|
||||
for _, o := range opts {
|
||||
pattern := "\t%s = %s\n"
|
||||
if strings.Contains(o.Value, "\\") {
|
||||
pattern = "\t%s = %q\n"
|
||||
}
|
||||
|
||||
if err := e.printf(pattern, o.Key, o.Value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Encoder) printf(msg string, args ...interface{}) error {
|
||||
_, err := fmt.Fprintf(e.w, msg, args...)
|
||||
return err
|
||||
}
|
||||
117
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/option.go
generated
vendored
Normal file
117
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/option.go
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Option defines a key/value entity in a config file.
|
||||
type Option struct {
|
||||
// Key preserving original caseness.
|
||||
// Use IsKey instead to compare key regardless of caseness.
|
||||
Key string
|
||||
// Original value as string, could be not normalized.
|
||||
Value string
|
||||
}
|
||||
|
||||
type Options []*Option
|
||||
|
||||
// IsKey returns true if the given key matches
|
||||
// this option's key in a case-insensitive comparison.
|
||||
func (o *Option) IsKey(key string) bool {
|
||||
return strings.ToLower(o.Key) == strings.ToLower(key)
|
||||
}
|
||||
|
||||
func (opts Options) GoString() string {
|
||||
var strs []string
|
||||
for _, opt := range opts {
|
||||
strs = append(strs, fmt.Sprintf("%#v", opt))
|
||||
}
|
||||
|
||||
return strings.Join(strs, ", ")
|
||||
}
|
||||
|
||||
// Get gets the value for the given key if set,
|
||||
// otherwise it returns the empty string.
|
||||
//
|
||||
// Note that there is no difference
|
||||
//
|
||||
// This matches git behaviour since git v1.8.1-rc1,
|
||||
// if there are multiple definitions of a key, the
|
||||
// last one wins.
|
||||
//
|
||||
// See: http://article.gmane.org/gmane.linux.kernel/1407184
|
||||
//
|
||||
// In order to get all possible values for the same key,
|
||||
// use GetAll.
|
||||
func (opts Options) Get(key string) string {
|
||||
for i := len(opts) - 1; i >= 0; i-- {
|
||||
o := opts[i]
|
||||
if o.IsKey(key) {
|
||||
return o.Value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetAll returns all possible values for the same key.
|
||||
func (opts Options) GetAll(key string) []string {
|
||||
result := []string{}
|
||||
for _, o := range opts {
|
||||
if o.IsKey(key) {
|
||||
result = append(result, o.Value)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (opts Options) withoutOption(key string) Options {
|
||||
result := Options{}
|
||||
for _, o := range opts {
|
||||
if !o.IsKey(key) {
|
||||
result = append(result, o)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (opts Options) withAddedOption(key string, value string) Options {
|
||||
return append(opts, &Option{key, value})
|
||||
}
|
||||
|
||||
func (opts Options) withSettedOption(key string, values ...string) Options {
|
||||
var result Options
|
||||
var added []string
|
||||
for _, o := range opts {
|
||||
if !o.IsKey(key) {
|
||||
result = append(result, o)
|
||||
continue
|
||||
}
|
||||
|
||||
if contains(values, o.Value) {
|
||||
added = append(added, o.Value)
|
||||
result = append(result, o)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
for _, value := range values {
|
||||
if contains(added, value) {
|
||||
continue
|
||||
}
|
||||
|
||||
result = result.withAddedOption(key, value)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func contains(haystack []string, needle string) bool {
|
||||
for _, s := range haystack {
|
||||
if s == needle {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
146
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/section.go
generated
vendored
Normal file
146
vendor/gopkg.in/src-d/go-git.v4/plumbing/format/config/section.go
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Section is the representation of a section inside git configuration files.
|
||||
// Each Section contains Options that are used by both the Git plumbing
|
||||
// and the porcelains.
|
||||
// Sections can be further divided into subsections. To begin a subsection
|
||||
// put its name in double quotes, separated by space from the section name,
|
||||
// in the section header, like in the example below:
|
||||
//
|
||||
// [section "subsection"]
|
||||
//
|
||||
// All the other lines (and the remainder of the line after the section header)
|
||||
// are recognized as option variables, in the form "name = value" (or just name,
|
||||
// which is a short-hand to say that the variable is the boolean "true").
|
||||
// The variable names are case-insensitive, allow only alphanumeric characters
|
||||
// and -, and must start with an alphabetic character:
|
||||
//
|
||||
// [section "subsection1"]
|
||||
// option1 = value1
|
||||
// option2
|
||||
// [section "subsection2"]
|
||||
// option3 = value2
|
||||
//
|
||||
type Section struct {
|
||||
Name string
|
||||
Options Options
|
||||
Subsections Subsections
|
||||
}
|
||||
|
||||
type Subsection struct {
|
||||
Name string
|
||||
Options Options
|
||||
}
|
||||
|
||||
type Sections []*Section
|
||||
|
||||
func (s Sections) GoString() string {
|
||||
var strs []string
|
||||
for _, ss := range s {
|
||||
strs = append(strs, fmt.Sprintf("%#v", ss))
|
||||
}
|
||||
|
||||
return strings.Join(strs, ", ")
|
||||
}
|
||||
|
||||
type Subsections []*Subsection
|
||||
|
||||
func (s Subsections) GoString() string {
|
||||
var strs []string
|
||||
for _, ss := range s {
|
||||
strs = append(strs, fmt.Sprintf("%#v", ss))
|
||||
}
|
||||
|
||||
return strings.Join(strs, ", ")
|
||||
}
|
||||
|
||||
// IsName checks if the name provided is equals to the Section name, case insensitive.
|
||||
func (s *Section) IsName(name string) bool {
|
||||
return strings.ToLower(s.Name) == strings.ToLower(name)
|
||||
}
|
||||
|
||||
// Option return the value for the specified key. Empty string is returned if
|
||||
// key does not exists.
|
||||
func (s *Section) Option(key string) string {
|
||||
return s.Options.Get(key)
|
||||
}
|
||||
|
||||
// AddOption adds a new Option to the Section. The updated Section is returned.
|
||||
func (s *Section) AddOption(key string, value string) *Section {
|
||||
s.Options = s.Options.withAddedOption(key, value)
|
||||
return s
|
||||
}
|
||||
|
||||
// SetOption adds a new Option to the Section. If the option already exists, is replaced.
|
||||
// The updated Section is returned.
|
||||
func (s *Section) SetOption(key string, value string) *Section {
|
||||
s.Options = s.Options.withSettedOption(key, value)
|
||||
return s
|
||||
}
|
||||
|
||||
// Remove an option with the specified key. The updated Section is returned.
|
||||
func (s *Section) RemoveOption(key string) *Section {
|
||||
s.Options = s.Options.withoutOption(key)
|
||||
return s
|
||||
}
|
||||
|
||||
// Subsection returns a Subsection from the specified Section. If the
|
||||
// Subsection does not exists, new one is created and added to Section.
|
||||
func (s *Section) Subsection(name string) *Subsection {
|
||||
for i := len(s.Subsections) - 1; i >= 0; i-- {
|
||||
ss := s.Subsections[i]
|
||||
if ss.IsName(name) {
|
||||
return ss
|
||||
}
|
||||
}
|
||||
|
||||
ss := &Subsection{Name: name}
|
||||
s.Subsections = append(s.Subsections, ss)
|
||||
return ss
|
||||
}
|
||||
|
||||
// HasSubsection checks if the Section has a Subsection with the specified name.
|
||||
func (s *Section) HasSubsection(name string) bool {
|
||||
for _, ss := range s.Subsections {
|
||||
if ss.IsName(name) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsName checks if the name of the subsection is exactly the specified name.
|
||||
func (s *Subsection) IsName(name string) bool {
|
||||
return s.Name == name
|
||||
}
|
||||
|
||||
// Option returns an option with the specified key. If the option does not exists,
|
||||
// empty spring will be returned.
|
||||
func (s *Subsection) Option(key string) string {
|
||||
return s.Options.Get(key)
|
||||
}
|
||||
|
||||
// AddOption adds a new Option to the Subsection. The updated Subsection is returned.
|
||||
func (s *Subsection) AddOption(key string, value string) *Subsection {
|
||||
s.Options = s.Options.withAddedOption(key, value)
|
||||
return s
|
||||
}
|
||||
|
||||
// SetOption adds a new Option to the Subsection. If the option already exists, is replaced.
|
||||
// The updated Subsection is returned.
|
||||
func (s *Subsection) SetOption(key string, value ...string) *Subsection {
|
||||
s.Options = s.Options.withSettedOption(key, value...)
|
||||
return s
|
||||
}
|
||||
|
||||
// RemoveOption removes the option with the specified key. The updated Subsection is returned.
|
||||
func (s *Subsection) RemoveOption(key string) *Subsection {
|
||||
s.Options = s.Options.withoutOption(key)
|
||||
return s
|
||||
}
|
||||
73
vendor/gopkg.in/src-d/go-git.v4/plumbing/hash.go
generated
vendored
Normal file
73
vendor/gopkg.in/src-d/go-git.v4/plumbing/hash.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
package plumbing
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"hash"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Hash SHA1 hased content
|
||||
type Hash [20]byte
|
||||
|
||||
// ZeroHash is Hash with value zero
|
||||
var ZeroHash Hash
|
||||
|
||||
// ComputeHash compute the hash for a given ObjectType and content
|
||||
func ComputeHash(t ObjectType, content []byte) Hash {
|
||||
h := NewHasher(t, int64(len(content)))
|
||||
h.Write(content)
|
||||
return h.Sum()
|
||||
}
|
||||
|
||||
// NewHash return a new Hash from a hexadecimal hash representation
|
||||
func NewHash(s string) Hash {
|
||||
b, _ := hex.DecodeString(s)
|
||||
|
||||
var h Hash
|
||||
copy(h[:], b)
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (h Hash) IsZero() bool {
|
||||
var empty Hash
|
||||
return h == empty
|
||||
}
|
||||
|
||||
func (h Hash) String() string {
|
||||
return hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
type Hasher struct {
|
||||
hash.Hash
|
||||
}
|
||||
|
||||
func NewHasher(t ObjectType, size int64) Hasher {
|
||||
h := Hasher{sha1.New()}
|
||||
h.Write(t.Bytes())
|
||||
h.Write([]byte(" "))
|
||||
h.Write([]byte(strconv.FormatInt(size, 10)))
|
||||
h.Write([]byte{0})
|
||||
return h
|
||||
}
|
||||
|
||||
func (h Hasher) Sum() (hash Hash) {
|
||||
copy(hash[:], h.Hash.Sum(nil))
|
||||
return
|
||||
}
|
||||
|
||||
// HashesSort sorts a slice of Hashes in increasing order.
|
||||
func HashesSort(a []Hash) {
|
||||
sort.Sort(HashSlice(a))
|
||||
}
|
||||
|
||||
// HashSlice attaches the methods of sort.Interface to []Hash, sorting in
|
||||
// increasing order.
|
||||
type HashSlice []Hash
|
||||
|
||||
func (p HashSlice) Len() int { return len(p) }
|
||||
func (p HashSlice) Less(i, j int) bool { return bytes.Compare(p[i][:], p[j][:]) < 0 }
|
||||
func (p HashSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||
61
vendor/gopkg.in/src-d/go-git.v4/plumbing/memory.go
generated
vendored
Normal file
61
vendor/gopkg.in/src-d/go-git.v4/plumbing/memory.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
package plumbing
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// MemoryObject on memory Object implementation
|
||||
type MemoryObject struct {
|
||||
t ObjectType
|
||||
h Hash
|
||||
cont []byte
|
||||
sz int64
|
||||
}
|
||||
|
||||
// Hash returns the object Hash, the hash is calculated on-the-fly the first
|
||||
// time it's called, in all subsequent calls the same Hash is returned even
|
||||
// if the type or the content have changed. The Hash is only generated if the
|
||||
// size of the content is exactly the object size.
|
||||
func (o *MemoryObject) Hash() Hash {
|
||||
if o.h == ZeroHash && int64(len(o.cont)) == o.sz {
|
||||
o.h = ComputeHash(o.t, o.cont)
|
||||
}
|
||||
|
||||
return o.h
|
||||
}
|
||||
|
||||
// Type return the ObjectType
|
||||
func (o *MemoryObject) Type() ObjectType { return o.t }
|
||||
|
||||
// SetType sets the ObjectType
|
||||
func (o *MemoryObject) SetType(t ObjectType) { o.t = t }
|
||||
|
||||
// Size return the size of the object
|
||||
func (o *MemoryObject) Size() int64 { return o.sz }
|
||||
|
||||
// SetSize set the object size, a content of the given size should be written
|
||||
// afterwards
|
||||
func (o *MemoryObject) SetSize(s int64) { o.sz = s }
|
||||
|
||||
// Reader returns a ObjectReader used to read the object's content.
|
||||
func (o *MemoryObject) Reader() (io.ReadCloser, error) {
|
||||
return ioutil.NopCloser(bytes.NewBuffer(o.cont)), nil
|
||||
}
|
||||
|
||||
// Writer returns a ObjectWriter used to write the object's content.
|
||||
func (o *MemoryObject) Writer() (io.WriteCloser, error) {
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func (o *MemoryObject) Write(p []byte) (n int, err error) {
|
||||
o.cont = append(o.cont, p...)
|
||||
o.sz = int64(len(o.cont))
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// Close releases any resources consumed by the object when it is acting as a
|
||||
// ObjectWriter.
|
||||
func (o *MemoryObject) Close() error { return nil }
|
||||
111
vendor/gopkg.in/src-d/go-git.v4/plumbing/object.go
generated
vendored
Normal file
111
vendor/gopkg.in/src-d/go-git.v4/plumbing/object.go
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// package plumbing implement the core interfaces and structs used by go-git
|
||||
package plumbing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrObjectNotFound = errors.New("object not found")
|
||||
// ErrInvalidType is returned when an invalid object type is provided.
|
||||
ErrInvalidType = errors.New("invalid object type")
|
||||
)
|
||||
|
||||
// Object is a generic representation of any git object
|
||||
type EncodedObject interface {
|
||||
Hash() Hash
|
||||
Type() ObjectType
|
||||
SetType(ObjectType)
|
||||
Size() int64
|
||||
SetSize(int64)
|
||||
Reader() (io.ReadCloser, error)
|
||||
Writer() (io.WriteCloser, error)
|
||||
}
|
||||
|
||||
// DeltaObject is an EncodedObject representing a delta.
|
||||
type DeltaObject interface {
|
||||
EncodedObject
|
||||
// BaseHash returns the hash of the object used as base for this delta.
|
||||
BaseHash() Hash
|
||||
// ActualHash returns the hash of the object after applying the delta.
|
||||
ActualHash() Hash
|
||||
// Size returns the size of the object after applying the delta.
|
||||
ActualSize() int64
|
||||
}
|
||||
|
||||
// ObjectType internal object type
|
||||
// Integer values from 0 to 7 map to those exposed by git.
|
||||
// AnyObject is used to represent any from 0 to 7.
|
||||
type ObjectType int8
|
||||
|
||||
const (
|
||||
InvalidObject ObjectType = 0
|
||||
CommitObject ObjectType = 1
|
||||
TreeObject ObjectType = 2
|
||||
BlobObject ObjectType = 3
|
||||
TagObject ObjectType = 4
|
||||
// 5 reserved for future expansion
|
||||
OFSDeltaObject ObjectType = 6
|
||||
REFDeltaObject ObjectType = 7
|
||||
|
||||
AnyObject ObjectType = -127
|
||||
)
|
||||
|
||||
func (t ObjectType) String() string {
|
||||
switch t {
|
||||
case CommitObject:
|
||||
return "commit"
|
||||
case TreeObject:
|
||||
return "tree"
|
||||
case BlobObject:
|
||||
return "blob"
|
||||
case TagObject:
|
||||
return "tag"
|
||||
case OFSDeltaObject:
|
||||
return "ofs-delta"
|
||||
case REFDeltaObject:
|
||||
return "ref-delta"
|
||||
case AnyObject:
|
||||
return "any"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func (t ObjectType) Bytes() []byte {
|
||||
return []byte(t.String())
|
||||
}
|
||||
|
||||
// Valid returns true if t is a valid ObjectType.
|
||||
func (t ObjectType) Valid() bool {
|
||||
return t >= CommitObject && t <= REFDeltaObject
|
||||
}
|
||||
|
||||
// IsDelta returns true for any ObjectTyoe that represents a delta (i.e.
|
||||
// REFDeltaObject or OFSDeltaObject).
|
||||
func (t ObjectType) IsDelta() bool {
|
||||
return t == REFDeltaObject || t == OFSDeltaObject
|
||||
}
|
||||
|
||||
// ParseObjectType parses a string representation of ObjectType. It returns an
|
||||
// error on parse failure.
|
||||
func ParseObjectType(value string) (typ ObjectType, err error) {
|
||||
switch value {
|
||||
case "commit":
|
||||
typ = CommitObject
|
||||
case "tree":
|
||||
typ = TreeObject
|
||||
case "blob":
|
||||
typ = BlobObject
|
||||
case "tag":
|
||||
typ = TagObject
|
||||
case "ofs-delta":
|
||||
typ = OFSDeltaObject
|
||||
case "ref-delta":
|
||||
typ = REFDeltaObject
|
||||
default:
|
||||
err = ErrInvalidType
|
||||
}
|
||||
return
|
||||
}
|
||||
209
vendor/gopkg.in/src-d/go-git.v4/plumbing/reference.go
generated
vendored
Normal file
209
vendor/gopkg.in/src-d/go-git.v4/plumbing/reference.go
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
package plumbing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
refPrefix = "refs/"
|
||||
refHeadPrefix = refPrefix + "heads/"
|
||||
refTagPrefix = refPrefix + "tags/"
|
||||
refRemotePrefix = refPrefix + "remotes/"
|
||||
refNotePrefix = refPrefix + "notes/"
|
||||
symrefPrefix = "ref: "
|
||||
)
|
||||
|
||||
// RefRevParseRules are a set of rules to parse references into short names.
|
||||
// These are the same rules as used by git in shorten_unambiguous_ref.
|
||||
// See: https://github.com/git/git/blob/e0aaa1b6532cfce93d87af9bc813fb2e7a7ce9d7/refs.c#L417
|
||||
var RefRevParseRules = []string{
|
||||
"refs/%s",
|
||||
"refs/tags/%s",
|
||||
"refs/heads/%s",
|
||||
"refs/remotes/%s",
|
||||
"refs/remotes/%s/HEAD",
|
||||
}
|
||||
|
||||
var (
|
||||
ErrReferenceNotFound = errors.New("reference not found")
|
||||
)
|
||||
|
||||
// ReferenceType reference type's
|
||||
type ReferenceType int8
|
||||
|
||||
const (
|
||||
InvalidReference ReferenceType = 0
|
||||
HashReference ReferenceType = 1
|
||||
SymbolicReference ReferenceType = 2
|
||||
)
|
||||
|
||||
func (r ReferenceType) String() string {
|
||||
switch r {
|
||||
case InvalidReference:
|
||||
return "invalid-reference"
|
||||
case HashReference:
|
||||
return "hash-reference"
|
||||
case SymbolicReference:
|
||||
return "symbolic-reference"
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// ReferenceName reference name's
|
||||
type ReferenceName string
|
||||
|
||||
// NewBranchReferenceName returns a reference name describing a branch based on
|
||||
// his short name.
|
||||
func NewBranchReferenceName(name string) ReferenceName {
|
||||
return ReferenceName(refHeadPrefix + name)
|
||||
}
|
||||
|
||||
// NewNoteReferenceName returns a reference name describing a note based on his
|
||||
// short name.
|
||||
func NewNoteReferenceName(name string) ReferenceName {
|
||||
return ReferenceName(refNotePrefix + name)
|
||||
}
|
||||
|
||||
// NewRemoteReferenceName returns a reference name describing a remote branch
|
||||
// based on his short name and the remote name.
|
||||
func NewRemoteReferenceName(remote, name string) ReferenceName {
|
||||
return ReferenceName(refRemotePrefix + fmt.Sprintf("%s/%s", remote, name))
|
||||
}
|
||||
|
||||
// NewRemoteHEADReferenceName returns a reference name describing a the HEAD
|
||||
// branch of a remote.
|
||||
func NewRemoteHEADReferenceName(remote string) ReferenceName {
|
||||
return ReferenceName(refRemotePrefix + fmt.Sprintf("%s/%s", remote, HEAD))
|
||||
}
|
||||
|
||||
// NewTagReferenceName returns a reference name describing a tag based on short
|
||||
// his name.
|
||||
func NewTagReferenceName(name string) ReferenceName {
|
||||
return ReferenceName(refTagPrefix + name)
|
||||
}
|
||||
|
||||
// IsBranch check if a reference is a branch
|
||||
func (r ReferenceName) IsBranch() bool {
|
||||
return strings.HasPrefix(string(r), refHeadPrefix)
|
||||
}
|
||||
|
||||
// IsNote check if a reference is a note
|
||||
func (r ReferenceName) IsNote() bool {
|
||||
return strings.HasPrefix(string(r), refNotePrefix)
|
||||
}
|
||||
|
||||
// IsRemote check if a reference is a remote
|
||||
func (r ReferenceName) IsRemote() bool {
|
||||
return strings.HasPrefix(string(r), refRemotePrefix)
|
||||
}
|
||||
|
||||
// IsTag check if a reference is a tag
|
||||
func (r ReferenceName) IsTag() bool {
|
||||
return strings.HasPrefix(string(r), refTagPrefix)
|
||||
}
|
||||
|
||||
func (r ReferenceName) String() string {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
// Short returns the short name of a ReferenceName
|
||||
func (r ReferenceName) Short() string {
|
||||
s := string(r)
|
||||
res := s
|
||||
for _, format := range RefRevParseRules {
|
||||
_, err := fmt.Sscanf(s, format, &res)
|
||||
if err == nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
const (
|
||||
HEAD ReferenceName = "HEAD"
|
||||
Master ReferenceName = "refs/heads/master"
|
||||
)
|
||||
|
||||
// Reference is a representation of git reference
|
||||
type Reference struct {
|
||||
t ReferenceType
|
||||
n ReferenceName
|
||||
h Hash
|
||||
target ReferenceName
|
||||
}
|
||||
|
||||
// NewReferenceFromStrings creates a reference from name and target as string,
|
||||
// the resulting reference can be a SymbolicReference or a HashReference base
|
||||
// on the target provided
|
||||
func NewReferenceFromStrings(name, target string) *Reference {
|
||||
n := ReferenceName(name)
|
||||
|
||||
if strings.HasPrefix(target, symrefPrefix) {
|
||||
target := ReferenceName(target[len(symrefPrefix):])
|
||||
return NewSymbolicReference(n, target)
|
||||
}
|
||||
|
||||
return NewHashReference(n, NewHash(target))
|
||||
}
|
||||
|
||||
// NewSymbolicReference creates a new SymbolicReference reference
|
||||
func NewSymbolicReference(n, target ReferenceName) *Reference {
|
||||
return &Reference{
|
||||
t: SymbolicReference,
|
||||
n: n,
|
||||
target: target,
|
||||
}
|
||||
}
|
||||
|
||||
// NewHashReference creates a new HashReference reference
|
||||
func NewHashReference(n ReferenceName, h Hash) *Reference {
|
||||
return &Reference{
|
||||
t: HashReference,
|
||||
n: n,
|
||||
h: h,
|
||||
}
|
||||
}
|
||||
|
||||
// Type return the type of a reference
|
||||
func (r *Reference) Type() ReferenceType {
|
||||
return r.t
|
||||
}
|
||||
|
||||
// Name return the name of a reference
|
||||
func (r *Reference) Name() ReferenceName {
|
||||
return r.n
|
||||
}
|
||||
|
||||
// Hash return the hash of a hash reference
|
||||
func (r *Reference) Hash() Hash {
|
||||
return r.h
|
||||
}
|
||||
|
||||
// Target return the target of a symbolic reference
|
||||
func (r *Reference) Target() ReferenceName {
|
||||
return r.target
|
||||
}
|
||||
|
||||
// Strings dump a reference as a [2]string
|
||||
func (r *Reference) Strings() [2]string {
|
||||
var o [2]string
|
||||
o[0] = r.Name().String()
|
||||
|
||||
switch r.Type() {
|
||||
case HashReference:
|
||||
o[1] = r.Hash().String()
|
||||
case SymbolicReference:
|
||||
o[1] = symrefPrefix + r.Target().String()
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (r *Reference) String() string {
|
||||
s := r.Strings()
|
||||
return fmt.Sprintf("%s %s", s[1], s[0])
|
||||
}
|
||||
11
vendor/gopkg.in/src-d/go-git.v4/plumbing/revision.go
generated
vendored
Normal file
11
vendor/gopkg.in/src-d/go-git.v4/plumbing/revision.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
package plumbing
|
||||
|
||||
// Revision represents a git revision
|
||||
// to get more details about git revisions
|
||||
// please check git manual page :
|
||||
// https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html
|
||||
type Revision string
|
||||
|
||||
func (r Revision) String() string {
|
||||
return string(r)
|
||||
}
|
||||
Reference in New Issue
Block a user