Simplify logic in doCommit as per Raf's suggestions. Define ref.EmptyRef variable.

This commit is contained in:
Dan Willhite
2015-10-12 10:48:33 -07:00
parent 4852067aad
commit d6b221444a
2 changed files with 7 additions and 12 deletions
+5 -11
View File
@@ -46,17 +46,11 @@ func (ds *dataStoreCommon) commitWithParents(v types.Value, p SetOfCommit) bool
func (ds *dataStoreCommon) doCommit(commit Commit) bool {
currentRootRef := ds.Root()
// Note: |currentHead| may be different from ds.head and *must* be consistent with currentRootRef.
// If currentRoot or currentHead is nil, then any commit is allowed.
emptyRef := ref.Ref{}
dsHeadRef := emptyRef
if ds.head != nil {
dsHeadRef = ds.head.Ref()
}
var currentHead Commit
if currentRootRef != emptyRef {
if currentRootRef == dsHeadRef {
// First commit is always fast-foward.
if currentRootRef != ref.EmptyRef {
// Note: |currentHead| may be different from ds.head and *must* be consistent with currentRootRef.
var currentHead Commit
if ds.head != nil && currentRootRef == ds.head.Ref() {
currentHead = *ds.head
} else {
currentHead = *commitFromRef(currentRootRef, ds)
+2 -1
View File
@@ -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