go/store/datas: Move around some Ref creation in doCommit.

This commit is contained in:
Aaron Son
2022-02-02 10:22:13 -08:00
parent 52fc803365
commit ec014823a5
2 changed files with 21 additions and 56 deletions
+9 -32
View File
@@ -104,25 +104,6 @@ func newCommit(ctx context.Context, value types.Value, parentsList types.List, p
}
func FindCommonAncestorUsingParentsList(ctx context.Context, c1, c2 types.Ref, vr1, vr2 types.ValueReader) (types.Ref, bool, error) {
t1, err := types.TypeOf(c1)
if err != nil {
return types.Ref{}, false, err
}
// precondition checks
if !IsRefOfCommitType(c1.Format(), t1) {
d.Panic("first reference is not a commit")
}
t2, err := types.TypeOf(c2)
if err != nil {
return types.Ref{}, false, err
}
if !IsRefOfCommitType(c2.Format(), t2) {
d.Panic("second reference is not a commit")
}
c1Q, c2Q := RefByHeightHeap{c1}, RefByHeightHeap{c2}
for !c1Q.Empty() && !c2Q.Empty() {
c1Ht, c2Ht := c1Q.MaxHeight(), c2Q.MaxHeight()
@@ -131,7 +112,7 @@ func FindCommonAncestorUsingParentsList(ctx context.Context, c1, c2 types.Ref, v
if common, ok := findCommonRef(c1Parents, c2Parents); ok {
return common, true, nil
}
err = parentsToQueue(ctx, c1Parents, &c1Q, vr1)
err := parentsToQueue(ctx, c1Parents, &c1Q, vr1)
if err != nil {
return types.Ref{}, false, err
}
@@ -140,12 +121,12 @@ func FindCommonAncestorUsingParentsList(ctx context.Context, c1, c2 types.Ref, v
return types.Ref{}, false, err
}
} else if c1Ht > c2Ht {
err = parentsToQueue(ctx, c1Q.PopRefsOfHeight(c1Ht), &c1Q, vr1)
err := parentsToQueue(ctx, c1Q.PopRefsOfHeight(c1Ht), &c1Q, vr1)
if err != nil {
return types.Ref{}, false, err
}
} else {
err = parentsToQueue(ctx, c2Q.PopRefsOfHeight(c2Ht), &c2Q, vr2)
err := parentsToQueue(ctx, c2Q.PopRefsOfHeight(c2Ht), &c2Q, vr2)
if err != nil {
return types.Ref{}, false, err
}
@@ -209,16 +190,6 @@ func FindCommonAncestor(ctx context.Context, c1, c2 types.Ref, vr1, vr2 types.Va
// where |cl| is the transitive closure of one or more refs. If a common ancestor
// exists, |ok| is set to true, else false.
func FindClosureCommonAncestor(ctx context.Context, cl RefClosure, cm types.Ref, vr types.ValueReader) (a types.Ref, ok bool, err error) {
t, err := types.TypeOf(cm)
if err != nil {
return types.Ref{}, false, err
}
// precondition checks
if !IsRefOfCommitType(cm.Format(), t) {
d.Panic("reference is not a commit")
}
q := &RefByHeightHeap{cm}
var curr types.RefSlice
@@ -264,6 +235,9 @@ func parentsToQueue(ctx context.Context, refs types.RefSlice, q *RefByHeightHeap
if !ok {
return fmt.Errorf("target ref is not struct: %v", v)
}
if c.Name() != CommitName {
return fmt.Errorf("target ref is not commit: %v", v)
}
ps, ok, err := c.MaybeGet(ParentsListField)
if err != nil {
return err
@@ -463,6 +437,9 @@ func newParentsClosureIterator(ctx context.Context, r types.Ref, vr types.ValueR
if !ok {
return nil, fmt.Errorf("target ref is not struct: %v", sv)
}
if s.Name() != CommitName {
return nil, fmt.Errorf("target ref is not commit: %v", sv)
}
fv, ok, err := s.MaybeGet(ParentsClosureField)
if err != nil {
+12 -24
View File
@@ -286,7 +286,6 @@ func (db *database) datasetFromMap(ctx context.Context, datasetID string, datase
return Dataset{}, err
} else if ok {
head, err = r.(types.Ref).TargetValue(ctx, db)
if err != nil {
return Dataset{}, err
}
@@ -456,16 +455,7 @@ func (db *database) doCommit(ctx context.Context, datasetID string, commit types
return types.Map{}, err
}
if hasHead {
head, err := curr.(types.Ref).TargetValue(ctx, db)
if err != nil {
return types.Map{}, err
}
currRef, err := types.NewRef(head, db.Format())
if err != nil {
return types.Map{}, err
}
currRef := curr.(types.Ref)
ancestorRef, found, err := FindCommonAncestor(ctx, commitRef, currRef, db, db)
if err != nil {
return types.Map{}, err
@@ -483,6 +473,7 @@ func (db *database) doCommit(ctx context.Context, datasetID string, commit types
if err != nil {
return types.Map{}, err
}
} else {
}
}
@@ -534,6 +525,15 @@ func (db *database) doMerge(
return types.Ref{}, err
}
// Load bearing re-ref. Sometimes current head has come from the
// datasets map and does not have Type information. parents_list is
// storing fully typed Refs, so we need to grab the type from that
// value we have.
currentHeadRef, err = types.NewRef(currentHead, db.Format())
if err != nil {
return types.Ref{}, err
}
parents, err := types.NewList(ctx, db, commitRef, currentHeadRef)
if err != nil {
return types.Ref{}, err
@@ -735,19 +735,7 @@ func (db *database) CommitWithWorkingSet(
}
if hasHead {
// TODO: We have to do a round-trip here (target the ref, then take a ref of it) because the type of the entry
// stored in the dataset is a ValueType, rather than Struct (commit). See types.ToRefOfValue
// We should rip this out along with much other type info
head, err := r.(types.Ref).TargetValue(ctx, db)
if err != nil {
return types.Map{}, err
}
currentHeadRef, err := types.NewRef(head, db.Format())
if err != nil {
return types.Map{}, err
}
currentHeadRef := r.(types.Ref)
ancestorRef, found, err := FindCommonAncestor(ctx, commitRef, currentHeadRef, db, db)
if err != nil {
return types.Map{}, err