aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-19 17:58:15 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-19 17:58:15 +0200
commit9f04fc2f7b31aeefa8281aff0d1d40a698f4b627 (patch)
tree23386ccbd3b53f51af8b35a144b1e9563d5ee621
parentf42cf79443fd08f61385761f86ddeb0f914257e6 (diff)
downloadgit-bug-9f04fc2f7b31aeefa8281aff0d1d40a698f4b627.tar.gz
bug: replace the uuid based id with the hash of the first commit
-rw-r--r--Gopkg.lock8
-rw-r--r--Gopkg.toml4
-rw-r--r--bug/bug.go61
-rw-r--r--tests/bug_test.go16
-rw-r--r--vendor/github.com/kevinburke/go.uuid/.travis.yml14
-rw-r--r--vendor/github.com/kevinburke/go.uuid/LICENSE20
-rw-r--r--vendor/github.com/kevinburke/go.uuid/Makefile21
-rw-r--r--vendor/github.com/kevinburke/go.uuid/README.md68
-rw-r--r--vendor/github.com/kevinburke/go.uuid/codec.go206
-rw-r--r--vendor/github.com/kevinburke/go.uuid/generator.go256
-rw-r--r--vendor/github.com/kevinburke/go.uuid/sql.go78
-rw-r--r--vendor/github.com/kevinburke/go.uuid/uuid.go161
12 files changed, 44 insertions, 869 deletions
diff --git a/Gopkg.lock b/Gopkg.lock
index e3f3fe0c..f8652af2 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -50,12 +50,6 @@
version = "v1.0"
[[projects]]
- name = "github.com/kevinburke/go.uuid"
- packages = ["."]
- revision = "24443c65ec63d9e040fd4cedf0f1048b5d3544f7"
- version = "v1.2.0"
-
-[[projects]]
name = "github.com/mattn/go-colorable"
packages = ["."]
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
@@ -112,6 +106,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
- inputs-digest = "ca22621dbddb833057afb8794a9b87598a6bec5fa0db620d3368c3d235e04c3c"
+ inputs-digest = "5a351932dcea8228cf9d53ff1e41c2865fc8a643e0f5959508057b3684cbcb0d"
solver-name = "gps-cdcl"
solver-version = 1
diff --git a/Gopkg.toml b/Gopkg.toml
index e1854aa7..78a557f2 100644
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -30,10 +30,6 @@
version = "1.6.2"
[[constraint]]
- name = "github.com/kevinburke/go.uuid"
- version = "1.2.0"
-
-[[constraint]]
name = "github.com/phayes/freeport"
version = "1.0.2"
diff --git a/bug/bug.go b/bug/bug.go
index 88a0ff8b..3632d6f2 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -1,12 +1,10 @@
package bug
import (
- "crypto/sha256"
"errors"
"fmt"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util"
- "github.com/kevinburke/go.uuid"
"strings"
)
@@ -14,6 +12,8 @@ const BugsRefPattern = "refs/bugs/"
const BugsRemoteRefPattern = "refs/remote/%s/bugs/"
const OpsEntryName = "ops"
const RootEntryName = "root"
+
+const IdLength = 40
const HumanIdLength = 7
// Bug hold the data of a bug thread, organized in a way close to
@@ -24,7 +24,7 @@ type Bug struct {
id string
lastCommit util.Hash
- root util.Hash
+ rootPack util.Hash
// TODO: need a way to order bugs, probably a Lamport clock
@@ -35,24 +35,8 @@ type Bug struct {
// Create a new Bug
func NewBug() (*Bug, error) {
- // TODO: replace with commit hash of (first commit + some random)
-
- // Creating UUID Version 4
- unique, err := uuid.ID4()
-
- if err != nil {
- return nil, err
- }
-
- // Use it as source of uniqueness
- hash := sha256.New().Sum(unique.Bytes())
-
- // format in hex and truncate to 40 char
- id := fmt.Sprintf("%.40s", fmt.Sprintf("%x", hash))
-
- return &Bug{
- id: id,
- }, nil
+ // No id yet
+ return &Bug{}, nil
}
// Find an existing Bug matching a prefix
@@ -94,6 +78,10 @@ func ReadBug(repo repository.Repo, ref string) (*Bug, error) {
refSplitted := strings.Split(ref, "/")
id := refSplitted[len(refSplitted)-1]
+ if len(id) != IdLength {
+ return nil, fmt.Errorf("Invalid ref length")
+ }
+
bug := Bug{
id: id,
}
@@ -133,8 +121,8 @@ func ReadBug(repo repository.Repo, ref string) (*Bug, error) {
return nil, errors.New("Invalid tree, missing the root entry")
}
- if bug.root == "" {
- bug.root = rootEntry.Hash
+ if bug.rootPack == "" {
+ bug.rootPack = rootEntry.Hash
}
data, err := repo.ReadData(opsEntry.Hash)
@@ -212,7 +200,7 @@ func (bug *Bug) Append(op Operation) {
// Write the staging area in Git and move the operations to the packs
func (bug *Bug) Commit(repo repository.Repo) error {
if bug.staging.IsEmpty() {
- return nil
+ return fmt.Errorf("can't commit an empty bug")
}
// Write the Ops as a Git blob containing the serialized array
@@ -221,17 +209,18 @@ func (bug *Bug) Commit(repo repository.Repo) error {
return err
}
- root := bug.root
- if root == "" {
- root = hash
- bug.root = hash
+ if bug.rootPack == "" {
+ bug.rootPack = hash
}
// Write a Git tree referencing this blob
hash, err = repo.StoreTree([]repository.TreeEntry{
- {repository.Blob, hash, OpsEntryName}, // the last pack of ops
- {repository.Blob, root, RootEntryName}, // always the first pack of ops (might be the same)
+ // the last pack of ops
+ {repository.Blob, hash, OpsEntryName},
+ // always the first pack of ops (might be the same)
+ {repository.Blob, bug.rootPack, RootEntryName},
})
+
if err != nil {
return err
}
@@ -249,6 +238,11 @@ func (bug *Bug) Commit(repo repository.Repo) error {
bug.lastCommit = hash
+ // if it was the first commit, use the commit hash as bug id
+ if bug.id == "" {
+ bug.id = string(hash)
+ }
+
// Create or update the Git reference for this bug
ref := fmt.Sprintf("%s%s", BugsRefPattern, bug.id)
err = repo.UpdateRef(ref, hash)
@@ -343,13 +337,18 @@ func (bug *Bug) Merge(repo repository.Repo, other *Bug) (bool, error) {
// Return the Bug identifier
func (bug *Bug) Id() string {
+ if bug.id == "" {
+ // simply panic as it would be a coding error
+ // (using an id of a bug not stored yet)
+ panic("no id yet")
+ }
return bug.id
}
// Return the Bug identifier truncated for human consumption
func (bug *Bug) HumanId() string {
format := fmt.Sprintf("%%.%ds", HumanIdLength)
- return fmt.Sprintf(format, bug.id)
+ return fmt.Sprintf(format, bug.Id())
}
// Lookup for the very first operation of the bug.
diff --git a/tests/bug_test.go b/tests/bug_test.go
index 175df1a8..e0737d1c 100644
--- a/tests/bug_test.go
+++ b/tests/bug_test.go
@@ -11,9 +11,15 @@ func TestBugId(t *testing.T) {
t.Error(err)
}
- if len(bug1.Id()) == 0 {
- t.Fatal("Bug doesn't have a human readable identifier")
+ bug1.Append(createOp)
+
+ err = bug1.Commit(mockRepo)
+
+ if err != nil {
+ t.Fatal(err)
}
+
+ bug1.Id()
}
func TestBugValidity(t *testing.T) {
@@ -38,7 +44,11 @@ func TestBugValidity(t *testing.T) {
t.Fatal("Bug with multiple CreateOp should be invalid")
}
- bug1.Commit(mockRepo)
+ err = bug1.Commit(mockRepo)
+
+ if err != nil {
+ t.Fatal(err)
+ }
if bug1.IsValid() {
t.Fatal("Bug with multiple CreateOp should be invalid")
diff --git a/vendor/github.com/kevinburke/go.uuid/.travis.yml b/vendor/github.com/kevinburke/go.uuid/.travis.yml
deleted file mode 100644
index 58cf5628..00000000
--- a/vendor/github.com/kevinburke/go.uuid/.travis.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-language: go
-sudo: false
-go:
- - 1.5.x
- - 1.6.x
- - 1.7.x
- - 1.8.x
- - 1.9.x
- - master
-
-before_script:
- - go get -t ./...
-script:
- - make lint test
diff --git a/vendor/github.com/kevinburke/go.uuid/LICENSE b/vendor/github.com/kevinburke/go.uuid/LICENSE
deleted file mode 100644
index 926d5498..00000000
--- a/vendor/github.com/kevinburke/go.uuid/LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/github.com/kevinburke/go.uuid/Makefile b/vendor/github.com/kevinburke/go.uuid/Makefile
deleted file mode 100644
index 344b2381..00000000
--- a/vendor/github.com/kevinburke/go.uuid/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-MEGACHECK := $(GOPATH)/bin/megacheck
-UNAME = $(shell uname -s)
-export GOROOT = $(shell go env GOROOT)
-
-test:
- go test ./...
-
-race-test:
- go test -race ./...
-
-$(MEGACHECK):
-ifeq ($(UNAME),Darwin)
- curl --silent --location --output $(MEGACHECK) https://github.com/kevinburke/go-tools/releases/download/2018-01-25/megacheck-darwin-amd64
-else
- curl --silent --location --output $(MEGACHECK) https://github.com/kevinburke/go-tools/releases/download/2018-01-25/megacheck-linux-amd64
-endif
- chmod +x $(MEGACHECK)
-
-lint: $(MEGACHECK)
- $(MEGACHECK) ./...
- go vet ./...
diff --git a/vendor/github.com/kevinburke/go.uuid/README.md b/vendor/github.com/kevinburke/go.uuid/README.md
deleted file mode 100644
index 7c46f66c..00000000
--- a/vendor/github.com/kevinburke/go.uuid/README.md
+++ /dev/null
@@ -1,68 +0,0 @@
-# UUID package for Go language
-
-This is a fork of satori/go.uuid that won't change the existing API.
-
-[![Build Status](https://travis-ci.org/kevinburke/go.uuid.png?branch=master)](https://travis-ci.org/kevinburke/go.uuid)
-[![Coverage Status](https://coveralls.io/repos/github/kevinburke/go.uuid/badge.svg?branch=master)](https://coveralls.io/github/kevinburke/go.uuid)
-[![GoDoc](http://godoc.org/github.com/kevinburke/go.uuid?status.png)](http://godoc.org/github.com/kevinburke/go.uuid)
-
-This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing of UUIDs.
-
-With 100% test coverage and benchmarks out of box.
-
-Supported versions:
-* Version 1, based on timestamp and MAC address (RFC 4122)
-* Version 2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1)
-* Version 3, based on MD5 hashing (RFC 4122)
-* Version 4, based on random numbers (RFC 4122)
-* Version 5, based on SHA-1 hashing (RFC 4122)
-
-## Installation
-
-Use the `go` command:
-
- $ go get github.com/kevinburke/go.uuid
-
-## Requirements
-
-UUID package requires Go >= 1.5.
-
-## Example
-
-```go
-package main
-
-import (
- "fmt"
-
- "github.com/kevinburke/go.uuid"
-)
-
-func main() {
- // Creating UUID Version 4
- u1 := uuid.NewV4()
- fmt.Printf("UUIDv4: %s\n", u1)
-
- // Parsing UUID from string input
- u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
- if err != nil {
- fmt.Printf("Something gone wrong: %s", err)
- }
- fmt.Printf("Successfully parsed: %s", u2)
-}
-```
-
-## Documentation
-
-[Documentation](http://godoc.org/github.com/kevinburke/go.uuid) is hosted at GoDoc project.
-
-## Links
-* [RFC 4122](http://tools.ietf.org/html/rfc4122)
-* [DCE 1.1: Authentication and Security Services](http://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01)
-
-## Copyright
-
-Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>.
-
-UUID package released under MIT License.
-See [LICENSE](https://github.com/kevinburke/go.uuid/blob/master/LICENSE) for details.
diff --git a/vendor/github.com/kevinburke/go.uuid/codec.go b/vendor/github.com/kevinburke/go.uuid/codec.go
deleted file mode 100644
index 656892c5..00000000
--- a/vendor/github.com/kevinburke/go.uuid/codec.go
+++ /dev/null
@@ -1,206 +0,0 @@
-// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package uuid
-
-import (
- "bytes"
- "encoding/hex"
- "fmt"
-)
-
-// FromBytes returns UUID converted from raw byte slice input.
-// It will return error if the slice isn't 16 bytes long.
-func FromBytes(input []byte) (u UUID, err error) {
- err = u.UnmarshalBinary(input)
- return
-}
-
-// FromBytesOrNil returns UUID converted from raw byte slice input.
-// Same behavior as FromBytes, but returns a Nil UUID on error.
-func FromBytesOrNil(input []byte) UUID {
- uuid, err := FromBytes(input)
- if err != nil {
- return Nil
- }
- return uuid
-}
-
-// FromString returns UUID parsed from string input.
-// Input is expected in a form accepted by UnmarshalText.
-func FromString(input string) (u UUID, err error) {
- err = u.UnmarshalText([]byte(input))
- return
-}
-
-// FromStringOrNil returns UUID parsed from string input.
-// Same behavior as FromString, but returns a Nil UUID on error.
-func FromStringOrNil(input string) UUID {
- uuid, err := FromString(input)
- if err != nil {
- return Nil
- }
- return uuid
-}
-
-// MarshalText implements the encoding.TextMarshaler interface.
-// The encoding is the same as returned by String.
-func (u UUID) MarshalText() (text []byte, err error) {
- text = []byte(u.String())
- return
-}
-
-// UnmarshalText implements the encoding.TextUnmarshaler interface.
-// Following formats are supported:
-// "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
-// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}",
-// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
-// "6ba7b8109dad11d180b400c04fd430c8"
-// ABNF for supported UUID text representation follows:
-// uuid := canonical | hashlike | braced | urn
-// plain := canonical | hashlike
-// canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct
-// hashlike := 12hexoct
-// braced := '{' plain '}'
-// urn := URN ':' UUID-NID ':' plain
-// URN := 'urn'
-// UUID-NID := 'uuid'
-// 12hexoct := 6hexoct 6hexoct
-// 6hexoct := 4hexoct 2hexoct
-// 4hexoct := 2hexoct 2hexoct
-// 2hexoct := hexoct hexoct
-// hexoct := hexdig hexdig
-// hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
-// 'a' | 'b' | 'c' | 'd' | 'e' | 'f' |
-// 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
-func (u *UUID) UnmarshalText(text []byte) (err error) {
- switch len(text) {
- case 32:
- return u.decodeHashLike(text)
- case 36:
- return u.decodeCanonical(text)
- case 38:
- return u.decodeBraced(text)
- case 41:
- fallthrough
- case 45:
- return u.decodeURN(text)
- default:
- return fmt.Errorf("uuid: incorrect UUID length: %s", text)
- }
-}
-
-// decodeCanonical decodes UUID string in format
-// "6ba7b810-9dad-11d1-80b4-00c04fd430c8".
-func (u *UUID) decodeCanonical(t []byte) (err error) {
- if t[8] != '-' || t[13] != '-' || t[18] != '-' || t[23] != '-' {
- return fmt.Errorf("uuid: incorrect UUID format %s", t)
- }
-
- src := t[:]
- dst := u[:]
-
- for i, byteGroup := range byteGroups {
- if i > 0 {
- src = src[1:] // skip dash
- }
- _, err = hex.Decode(dst[:byteGroup/2], src[:byteGroup])
- if err != nil {
- return
- }
- src = src[byteGroup:]
- dst = dst[byteGroup/2:]
- }
-
- return
-}
-
-// decodeHashLike decodes UUID string in format
-// "6ba7b8109dad11d180b400c04fd430c8".
-func (u *UUID) decodeHashLike(t []byte) (err error) {
- src := t[:]
- dst := u[:]
-
- if _, err = hex.Decode(dst, src); err != nil {
- return err
- }
- return
-}
-
-// decodeBraced decodes UUID string in format
-// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}" or in format
-// "{6ba7b8109dad11d180b400c04fd430c8}".
-func (u *UUID) decodeBraced(t []byte) (err error) {
- l := len(t)
-
- if t[0] != '{' || t[l-1] != '}' {
- return fmt.Errorf("uuid: incorrect UUID format %s", t)
- }
-
- return u.decodePlain(t[1 : l-1])
-}
-
-// decodeURN decodes UUID string in format
-// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" or in format
-// "urn:uuid:6ba7b8109dad11d180b400c04fd430c8".
-func (u *UUID) decodeURN(t []byte) (err error) {
- total := len(t)
-
- urn_uuid_prefix := t[:9]
-
- if !bytes.Equal(urn_uuid_prefix, urnPrefix) {
- return fmt.Errorf("uuid: incorrect UUID format: %s", t)
- }
-
- return u.decodePlain(t[9:total])
-}
-
-// decodePlain decodes UUID string in canonical format
-// "6ba7b810-9dad-11d1-80b4-00c04fd430c8" or in hash-like format
-// "6ba7b8109dad11d180b400c04fd430c8".
-func (u *UUID) decodePlain(t []byte) (err error) {
- switch len(t) {
- case 32:
- return u.decodeHashLike(t)
- case 36:
- return u.decodeCanonical(t)
- default:
- return fmt.Errorf("uuid: incorrrect UUID length: %s", t)
- }
-}
-
-// MarshalBinary implements the encoding.BinaryMarshaler interface.
-func (u UUID) MarshalBinary() (data []byte, err error) {
- data = u.Bytes()
- return
-}
-
-// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
-// It will return error if the slice isn't 16 bytes long.
-func (u *UUID) UnmarshalBinary(data []byte) (err error) {
- if len(data) != Size {
- err = fmt.Errorf("uuid: UUID must be exactly 16 bytes long, got %d bytes", len(data))
- return
- }
- copy(u[:], data)
-
- return
-}
diff --git a/vendor/github.com/kevinburke/go.uuid/generator.go b/vendor/github.com/kevinburke/go.uuid/generator.go
deleted file mode 100644
index 83abbcfd..00000000
--- a/vendor/github.com/kevinburke/go.uuid/generator.go
+++ /dev/null
@@ -1,256 +0,0 @@
-// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package uuid
-
-import (
- "crypto/md5"
- "crypto/rand"
- "crypto/sha1"
- "encoding/binary"
- "hash"
- "net"
- "os"
- "sync"
- "time"
-)
-
-// Difference in 100-nanosecond intervals between
-// UUID epoch (October 15, 1582) and Unix epoch (January 1, 1970).
-const epochStart = 122192928000000000
-
-var (
- global = newDefaultGenerator()
-
- epochFunc = unixTimeFunc
- posixUID = uint32(os.Getuid())
- posixGID = uint32(os.Getgid())
-)
-
-// NewV1 returns UUID based on current timestamp and MAC address.
-func NewV1() UUID {
- return global.NewV1()
-}
-
-// NewV2 returns DCE Security UUID based on POSIX UID/GID.
-func NewV2(domain byte) UUID {
- return global.NewV2(domain)
-}
-
-// NewV3 returns a UUID based on the MD5 hash of namespace UUID and name.
-func NewV3(ns UUID, name string) UUID {
- return global.NewV3(ns, name)
-}
-
-// NewV4 returns a randomly generated UUID.
-func NewV4() UUID {
- u, err := ID4()
- if err != nil {
- panic(err)
- }
- return u
-}
-
-// ID4 returns a randomly generated UUID, or an error if there was not enough
-// entropy.
-func ID4() (UUID, error) {
- return global.NewV4()
-}
-
-// NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.
-func NewV5(ns UUID, name string) UUID {
- return global.NewV5(ns, name)
-}
-
-// Generator provides interface for generating UUIDs.
-type Generator interface {
- NewV1() UUID
- NewV2(domain byte) UUID
- NewV3(ns UUID, name string) UUID
- NewV4() UUID
- NewV5(ns UUID, name string) UUID
-}
-
-// Default generator implementation.
-type generator struct {
- storageOnce sync.Once
- storageMutex sync.Mutex
-
- lastTime uint64
- clockSequence uint16
- hardwareAddr [6]byte
-}
-
-func newDefaultGenerator() *generator {
- return &generator{}
-}
-
-// NewV1 returns UUID based on current timestamp and MAC address.
-func (g *generator) NewV1() UUID {
- u := UUID{}
-
- timeNow, clockSeq, hardwareAddr := g.getStorage()
-
- binary.BigEndian.PutUint32(u[0:], uint32(timeNow))
- binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
- binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
- binary.BigEndian.PutUint16(u[8:], clockSeq)
-
- copy(u[10:], hardwareAddr)
-
- u.SetVersion(V1)
- u.SetVariant(VariantRFC4122)
-
- return u
-}
-
-// NewV2 returns DCE Security UUID based on POSIX UID/GID.
-func (g *generator) NewV2(domain byte) UUID {
- u := UUID{}
-
- timeNow, clockSeq, hardwareAddr := g.getStorage()
-
- switch domain {
- case DomainPerson:
- binary.BigEndian.PutUint32(u[0:], posixUID)
- case DomainGroup:
- binary.BigEndian.PutUint32(u[0:], posixGID)
- }
-
- binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
- binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
- binary.BigEndian.PutUint16(u[8:], clockSeq)
- u[9] = domain
-
- copy(u[10:], hardwareAddr)
-
- u.SetVersion(V2)
- u.SetVariant(VariantRFC4122)
-
- return u
-}
-
-// NewV3 returns UUID based on MD5 hash of namespace UUID and name.
-func (g *generator) NewV3(ns UUID, name string) UUID {
- u := newFromHash(md5.New(), ns, name)
- u.SetVersion(V3)
- u.SetVariant(VariantRFC4122)
-
- return u
-}
-
-// NewV4 returns random generated UUID.
-func (g *generator) NewV4() (UUID, error) {
- u := UUID{}
- if err := g.random(u[:]); err != nil {
- return u, err
- }
- u.SetVersion(V4)
- u.SetVariant(VariantRFC4122)
-
- return u, nil
-}
-
-// NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.
-func (g *generator) NewV5(ns UUID, name string) UUID {
- u := newFromHash(sha1.New(), ns, name)
- u.SetVersion(V5)
- u.SetVariant(VariantRFC4122)
-
- return u
-}
-
-func (g *generator) initStorage() {
- g.initClockSequence()
- g.initHardwareAddr()
-}
-
-func (g *generator) initClockSequence() error {
- buf := make([]byte, 2)
- if err := g.random(buf); err != nil {
- return err
- }
- g.clockSequence = binary.BigEndian.Uint16(buf)
- return nil
-}
-
-func (g *generator) initHardwareAddr() error {
- interfaces, err := net.Interfaces()
- if err == nil {
- for _, iface := range interfaces {
- if len(iface.HardwareAddr) >= 6 {
- copy(g.hardwareAddr[:], iface.HardwareAddr)
- return nil
- }
- }
- }
-
- // Initialize hardwareAddr randomly in case
- // of real network interfaces absence
- if err := g.random(g.hardwareAddr[:]); err != nil {
- return err
- }
-
- // Set multicast bit as recommended in RFC 4122
- g.hardwareAddr[0] |= 0x01
- return nil
-}
-
-func (g *generator) random(dest []byte) error {
- _, err := rand.Read(dest)
- return err
-}
-
-// Returns UUID v1/v2 storage state.
-// Returns epoch timestamp, clock sequence, and hardware address.
-func (g *generator) getStorage() (uint64, uint16, []byte) {
- g.storageOnce.Do(g.initStorage)
-
- g.storageMutex.Lock()
- defer g.storageMutex.Unlock()
-
- timeNow := epochFunc()
- // Clock changed backwards since last UUID generation.
- // Should increase clock sequence.
- if timeNow <= g.lastTime {
- g.clockSequence++
- }
- g.lastTime = timeNow
-
- return timeNow, g.clockSequence, g.hardwareAddr[:]
-}
-
-// Returns difference in 100-nanosecond intervals between
-// UUID epoch (October 15, 1582) and current time.
-// This is default epoch calculation function.
-func unixTimeFunc() uint64 {
- return epochStart + uint64(time.Now().UnixNano()/100)
-}
-
-// Returns UUID based on hashing of namespace UUID and name.
-func newFromHash(h hash.Hash, ns UUID, name string) UUID {
- u := UUID{}
- h.Write(ns[:])
- h.Write([]byte(name))
- copy(u[:], h.Sum(nil))
-
- return u
-}
diff --git a/vendor/github.com/kevinburke/go.uuid/sql.go b/vendor/github.com/kevinburke/go.uuid/sql.go
deleted file mode 100644
index 56759d39..00000000
--- a/vendor/github.com/kevinburke/go.uuid/sql.go
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package uuid
-
-import (
- "database/sql/driver"
- "fmt"
-)
-
-// Value implements the driver.Valuer interface.
-func (u UUID) Value() (driver.Value, error) {
- return u.String(), nil
-}
-
-// Scan implements the sql.Scanner interface.
-// A 16-byte slice is handled by UnmarshalBinary, while
-// a longer byte slice or a string is handled by UnmarshalText.
-func (u *UUID) Scan(src interface{}) error {
- switch src := src.(type) {
- case []byte:
- if len(src) == Size {
- return u.UnmarshalBinary(src)
- }
- return u.UnmarshalText(src)
-
- case string:
- return u.UnmarshalText([]byte(src))
- }
-
- return fmt.Errorf("uuid: cannot convert %T to UUID", src)
-}
-
-// NullUUID can be used with the standard sql package to represent a
-// UUID value that can be NULL in the database
-type NullUUID struct {
- UUID UUID
- Valid bool
-}
-
-// Value implements the driver.Valuer interface.
-func (u NullUUID) Value() (driver.Value, error) {
- if !u.Valid {
- return nil, nil
- }
- // Delegate to UUID Value function
- return u.UUID.Value()
-}
-
-// Scan implements the sql.Scanner interface.
-func (u *NullUUID) Scan(src interface{}) error {
- if src == nil {
- u.UUID, u.Valid = Nil, false
- return nil
- }
-
- // Delegate to UUID Scan function
- u.Valid = true
- return u.UUID.Scan(src)
-}
diff --git a/vendor/github.com/kevinburke/go.uuid/uuid.go b/vendor/github.com/kevinburke/go.uuid/uuid.go
deleted file mode 100644
index a2b8e2ca..00000000
--- a/vendor/github.com/kevinburke/go.uuid/uuid.go
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-// Package uuid provides implementation of Universally Unique Identifier (UUID).
-// Supported versions are 1, 3, 4 and 5 (as specified in RFC 4122) and
-// version 2 (as specified in DCE 1.1).
-package uuid
-
-import (
- "bytes"
- "encoding/hex"
-)
-
-// Size of a UUID in bytes.
-const Size = 16
-
-// UUID representation compliant with specification
-// described in RFC 4122.
-type UUID [Size]byte
-
-// UUID versions
-const (
- _ byte = iota
- V1
- V2
- V3
- V4
- V5
-)
-
-// UUID layout variants.
-const (
- VariantNCS byte = iota
- VariantRFC4122
- VariantMicrosoft
- VariantFuture
-)
-
-// UUID DCE domains.
-const (
- DomainPerson = iota
- DomainGroup
- DomainOrg
-)
-
-// String parse helpers.
-var (
- urnPrefix = []byte("urn:uuid:")
- byteGroups = []int{8, 4, 4, 4, 12}
-)
-
-// Nil is special form of UUID that is specified to have all
-// 128 bits set to zero.
-var Nil = UUID{}
-
-// Predefined namespace UUIDs.
-var (
- NamespaceDNS = Must(FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
- NamespaceURL = Must(FromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
- NamespaceOID = Must(FromString("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
- NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
-)
-
-// Equal returns true if u1 and u2 equals, otherwise returns false.
-func Equal(u1 UUID, u2 UUID) bool {
- return bytes.Equal(u1[:], u2[:])
-}
-
-// Version returns algorithm version used to generate UUID.
-func (u UUID) Version() byte {
- return u[6] >> 4
-}
-
-// Variant returns UUID layout variant.
-func (u UUID) Variant() byte {
- switch {
- case (u[8] >> 7) == 0x00:
- return VariantNCS
- case (u[8] >> 6) == 0x02:
- return VariantRFC4122
- case (u[8] >> 5) == 0x06:
- return VariantMicrosoft
- case (u[8] >> 5) == 0x07:
- fallthrough
- default:
- return VariantFuture
- }
-}
-
-// Bytes returns bytes slice representation of UUID.
-func (u UUID) Bytes() []byte {
- return u[:]
-}
-
-// Returns canonical string representation of UUID:
-// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
-func (u UUID) String() string {
- buf := make([]byte, 36)
-
- hex.Encode(buf[0:8], u[0:4])
- buf[8] = '-'
- hex.Encode(buf[9:13], u[4:6])
- buf[13] = '-'
- hex.Encode(buf[14:18], u[6:8])
- buf[18] = '-'
- hex.Encode(buf[19:23], u[8:10])
- buf[23] = '-'
- hex.Encode(buf[24:], u[10:])
-
- return string(buf)
-}
-
-// SetVersion sets version bits.
-func (u *UUID) SetVersion(v byte) {
- u[6] = (u[6] & 0x0f) | (v << 4)
-}
-
-// SetVariant sets variant bits.
-func (u *UUID) SetVariant(v byte) {
- switch v {
- case VariantNCS:
- u[8] = (u[8]&(0xff>>1) | (0x00 << 7))
- case VariantRFC4122:
- u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
- case VariantMicrosoft:
- u[8] = (u[8]&(0xff>>3) | (0x06 << 5))
- case VariantFuture:
- fallthrough
- default:
- u[8] = (u[8]&(0xff>>3) | (0x07 << 5))
- }
-}
-
-// Must is a helper that wraps a call to a function returning (UUID, error)
-// and panics if the error is non-nil. It is intended for use in variable
-// initializations such as
-// var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000"));
-func Must(u UUID, err error) UUID {
- if err != nil {
- panic(err)
- }
- return u
-}