mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-13 03:10:03 -05:00
Merge pull request #447 from willhite/empty-ref
Add IsEmpty() function on ref.Ref.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
noms.iml
|
||||
@@ -72,7 +72,7 @@ func (suite *ChunkStoreTestSuite) TestChunkStoreChunkCloses() {
|
||||
|
||||
func (suite *ChunkStoreTestSuite) TestChunkStoreRoot() {
|
||||
oldRoot := suite.Store.Root()
|
||||
suite.Equal(oldRoot, ref.Ref{})
|
||||
suite.True(oldRoot.IsEmpty())
|
||||
|
||||
bogusRoot := ref.Parse("sha1-81c870618113ba29b6f2b396ea3a69c6f1d626c5") // sha1("Bogus, Dude")
|
||||
newRoot := ref.Parse("sha1-907d14fb3af2b0d4f18c2d46abe8aedce17367bd") // sha1("Hello, World")
|
||||
|
||||
@@ -193,7 +193,7 @@ func (c *HttpStore) postRefs(chs []Chunk) {
|
||||
func (c *HttpStore) requestRef(r ref.Ref, method string, body io.Reader) *http.Response {
|
||||
url := *c.host
|
||||
url.Path = constants.RefPath
|
||||
if (r != ref.Ref{}) {
|
||||
if !r.IsEmpty() {
|
||||
url.Path = path.Join(url.Path, r.String())
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ func (c *HttpStore) requestRoot(method string, current, last ref.Ref) *http.Resp
|
||||
u := *c.host
|
||||
u.Path = constants.RootPath
|
||||
if method == "POST" {
|
||||
d.Exp.True(current != ref.Ref{})
|
||||
d.Exp.False(current.IsEmpty())
|
||||
params := url.Values{}
|
||||
params.Add("last", last.String())
|
||||
params.Add("current", current.String())
|
||||
|
||||
@@ -49,14 +49,14 @@ func (ds *dataStoreCommon) doCommit(datasetID string, commit Commit) bool {
|
||||
var currentDatasets MapOfStringToCommit
|
||||
if ds.datasets != nil && currentRootRef == ds.datasets.Ref() {
|
||||
currentDatasets = *ds.datasets
|
||||
} else if currentRootRef != (ref.Ref{}) {
|
||||
} else if !currentRootRef.IsEmpty() {
|
||||
currentDatasets = *datasetsFromRef(currentRootRef, ds)
|
||||
} else {
|
||||
currentDatasets = NewMapOfStringToCommit()
|
||||
}
|
||||
|
||||
// First commit in store is always fast-foward.
|
||||
if currentRootRef != (ref.Ref{}) {
|
||||
if !currentRootRef.IsEmpty() {
|
||||
var currentHead Commit
|
||||
currentHead, hasHead := currentDatasets.MaybeGet(datasetID)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ type LocalDataStore struct {
|
||||
|
||||
func newLocalDataStore(cs chunks.ChunkStore) *LocalDataStore {
|
||||
rootRef := cs.Root()
|
||||
if rootRef == (ref.Ref{}) {
|
||||
if rootRef.IsEmpty() {
|
||||
return &LocalDataStore{dataStoreCommon{cs, nil}}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (lds *LocalDataStore) CopyReachableChunksP(r, exclude ref.Ref, sink chunks.
|
||||
return excludeRefs[r]
|
||||
}
|
||||
|
||||
if exclude != (ref.Ref{}) {
|
||||
if !exclude.IsEmpty() {
|
||||
refChan := make(chan ref.Ref, 1024)
|
||||
addRef := func(r ref.Ref) {
|
||||
refChan <- r
|
||||
|
||||
@@ -22,7 +22,7 @@ type RemoteDataStore struct {
|
||||
|
||||
func newRemoteDataStore(cs chunks.ChunkStore) *RemoteDataStore {
|
||||
rootRef := cs.Root()
|
||||
if rootRef == (ref.Ref{}) {
|
||||
if rootRef.IsEmpty() {
|
||||
return &RemoteDataStore{dataStoreCommon{cs, nil}}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (lds *RemoteDataStore) CopyReachableChunksP(r, exclude ref.Ref, cs chunks.C
|
||||
|
||||
values := &url.Values{}
|
||||
values.Add("all", "true")
|
||||
if exclude != (ref.Ref{}) {
|
||||
if !exclude.IsEmpty() {
|
||||
values.Add("exclude", exclude.String())
|
||||
}
|
||||
u.RawQuery = values.Encode()
|
||||
|
||||
+6
-1
@@ -14,7 +14,8 @@ import (
|
||||
|
||||
var (
|
||||
// In the future we will allow different digest types, so this will get more complicated. For now sha1 is fine.
|
||||
pattern = regexp.MustCompile("^sha1-([0-9a-f]{40})$")
|
||||
pattern = regexp.MustCompile("^sha1-([0-9a-f]{40})$")
|
||||
emptyRef = Ref{}
|
||||
)
|
||||
|
||||
type Sha1Digest [sha1.Size]byte
|
||||
@@ -29,6 +30,10 @@ func (r Ref) Digest() Sha1Digest {
|
||||
return r.digest
|
||||
}
|
||||
|
||||
func (r Ref) IsEmpty() bool {
|
||||
return r.digest == emptyRef.digest
|
||||
}
|
||||
|
||||
func (r Ref) String() string {
|
||||
return fmt.Sprintf("sha1-%s", hex.EncodeToString(r.digest[:]))
|
||||
}
|
||||
|
||||
@@ -68,3 +68,14 @@ func TestFromHash(t *testing.T) {
|
||||
r := FromHash(h)
|
||||
assert.Equal(t, "sha1-a9993e364706816aba3e25717850c26c9cd0d89d", r.String())
|
||||
}
|
||||
|
||||
func TestIsEmpty(t *testing.T) {
|
||||
r1 := Ref{}
|
||||
assert.True(t, r1.IsEmpty())
|
||||
|
||||
r2 := Parse("sha1-0000000000000000000000000000000000000000")
|
||||
assert.True(t, r2.IsEmpty())
|
||||
|
||||
r3 := Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
|
||||
assert.False(t, r3.IsEmpty())
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ func (r *jsonArrayReader) readTypeRefAsValue(pkg *Package) TypeRef {
|
||||
if ordinal == -1 {
|
||||
namespace := r.readString()
|
||||
name := r.readString()
|
||||
d.Chk.Equal(ref.Ref{}, pkgRef, "Unresolved TypeRefs may not have a package ref")
|
||||
d.Chk.True(pkgRef.IsEmpty(), "Unresolved TypeRefs may not have a package ref")
|
||||
return MakeUnresolvedTypeRef(namespace, name)
|
||||
}
|
||||
return MakeTypeRef(pkgRef, ordinal)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ func getRefNoOverride(v Value) ref.Ref {
|
||||
}
|
||||
|
||||
func ensureRef(r *ref.Ref, v Value) ref.Ref {
|
||||
if *r == (ref.Ref{}) {
|
||||
if r.IsEmpty() {
|
||||
*r = getRef(v)
|
||||
}
|
||||
return *r
|
||||
|
||||
Reference in New Issue
Block a user