mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-05 16:15:41 -06:00
pr feedback
This commit is contained in:
@@ -260,3 +260,58 @@ func fetchRemoteBranch(ctx context.Context, dEnv *env.DoltEnv, rem env.Remote, s
|
||||
|
||||
return srcDBCommit, nil
|
||||
}
|
||||
|
||||
// fetchFollowTags fetches all tags from the source DB whose commits have already
|
||||
// been fetched into the destination DB.
|
||||
// todo: potentially too expensive to iterate over all srcDB tags
|
||||
func fetchFollowTags(ctx context.Context, dEnv *env.DoltEnv, srcDB, destDB *doltdb.DoltDB) errhand.VerboseError {
|
||||
err := actions.IterResolvedTags(ctx, srcDB, func(tag *doltdb.Tag) (stop bool, err error) {
|
||||
stRef, err := tag.GetStRef()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
tagHash := stRef.TargetHash()
|
||||
|
||||
tv, err := destDB.ValueReadWriter().ReadValue(ctx, tagHash)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
if tv != nil {
|
||||
// tag is already fetched
|
||||
return false, nil
|
||||
}
|
||||
|
||||
cmHash, err := tag.Commit.HashOf()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
cv, err := destDB.ValueReadWriter().ReadValue(ctx, cmHash)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
if cv == nil {
|
||||
// neither tag nor commit has been fetched
|
||||
return false, nil
|
||||
}
|
||||
|
||||
wg, progChan, pullerEventCh := runProgFuncs()
|
||||
err = actions.FetchTag(ctx, dEnv, srcDB, destDB, tag, progChan, pullerEventCh)
|
||||
stopProgFuncs(wg, progChan, pullerEventCh)
|
||||
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
err = destDB.SetHead(ctx, tag.GetDoltRef(), stRef)
|
||||
|
||||
return false, err
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errhand.VerboseErrorFromError(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ package commands
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
@@ -150,58 +147,3 @@ func pullRemoteBranch(ctx context.Context, dEnv *env.DoltEnv, r env.Remote, srcR
|
||||
|
||||
return mergeCommitSpec(ctx, dEnv, destRef.String())
|
||||
}
|
||||
|
||||
// fetchFollowTags fetches all tags from the source DB whose commits have already
|
||||
// been fetched into the destination DB.
|
||||
// todo: potentially too expensive to iterate over all srcDB tags
|
||||
func fetchFollowTags(ctx context.Context, dEnv *env.DoltEnv, srcDB, destDB *doltdb.DoltDB) errhand.VerboseError {
|
||||
err := actions.IterResolvedTags(ctx, srcDB, func(tag *doltdb.Tag) (stop bool, err error) {
|
||||
stRef, err := tag.GetStRef()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
tagHash := stRef.TargetHash()
|
||||
|
||||
tv, err := destDB.ValueReadWriter().ReadValue(ctx, tagHash)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
if tv != nil {
|
||||
// tag is already fetched
|
||||
return false, nil
|
||||
}
|
||||
|
||||
cmHash, err := tag.Commit.HashOf()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
cv, err := destDB.ValueReadWriter().ReadValue(ctx, cmHash)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
if cv == nil {
|
||||
// neither tag nor commit has been fetched
|
||||
return false, nil
|
||||
}
|
||||
|
||||
wg, progChan, pullerEventCh := runProgFuncs()
|
||||
err = actions.FetchTag(ctx, dEnv, srcDB, destDB, tag, progChan, pullerEventCh)
|
||||
stopProgFuncs(wg, progChan, pullerEventCh)
|
||||
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
err = destDB.SetHead(ctx, tag.GetDoltRef(), stRef)
|
||||
|
||||
return false, err
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errhand.VerboseErrorFromError(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ func (c *Commit) GetCommitMeta() (*CommitMeta, error) {
|
||||
return nil, errors.New(h.String() + " is a commit without the required metadata.")
|
||||
}
|
||||
|
||||
// ParentHashes returns the commit hashes for all parent commits.
|
||||
func (c *Commit) ParentHashes(ctx context.Context) ([]hash.Hash, error) {
|
||||
hashes := make([]hash.Hash, len(c.parents))
|
||||
for i, pr := range c.parents {
|
||||
@@ -178,6 +179,7 @@ func (c *Commit) GetRootValue() (*RootValue, error) {
|
||||
return nil, errHasNoRootValue
|
||||
}
|
||||
|
||||
// GetStRef returns a Noms Ref for this Commit's Noms commit Struct.
|
||||
func (c *Commit) GetStRef() (types.Ref, error) {
|
||||
return types.NewRef(c.commitSt, c.vrw.Format())
|
||||
}
|
||||
|
||||
@@ -357,6 +357,7 @@ func (ddb *DoltDB) ResolveRef(ctx context.Context, ref ref.DoltRef) (*Commit, er
|
||||
return NewCommit(ddb.db, commitSt), nil
|
||||
}
|
||||
|
||||
// ResolveTag takes a TagRef and returns the corresponding Tag object.
|
||||
func (ddb *DoltDB) ResolveTag(ctx context.Context, tagRef ref.TagRef) (*Tag, error) {
|
||||
ds, err := ddb.db.GetDataset(ctx, tagRef.String())
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ type Tag struct {
|
||||
Commit *Commit
|
||||
}
|
||||
|
||||
// NewTag creates a new Tag object.
|
||||
func NewTag(ctx context.Context, name string, vrw types.ValueReadWriter, tagSt types.Struct) (*Tag, error) {
|
||||
metaSt, ok, err := tagSt.MaybeGet(datas.TagMetaField)
|
||||
|
||||
@@ -72,10 +73,12 @@ func NewTag(ctx context.Context, name string, vrw types.ValueReadWriter, tagSt t
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetStRef returns a Noms Ref for this Tag's Noms tag Struct.
|
||||
func (t *Tag) GetStRef() (types.Ref, error) {
|
||||
return types.NewRef(t.tagSt, t.vrw.Format())
|
||||
}
|
||||
|
||||
// GetDoltRef returns a DoltRef for this Tag.
|
||||
func (t *Tag) GetDoltRef() ref.DoltRef {
|
||||
return ref.NewTagRef(t.Name)
|
||||
}
|
||||
|
||||
4
go/libraries/doltcore/env/actions/remotes.go
vendored
4
go/libraries/doltcore/env/actions/remotes.go
vendored
@@ -73,6 +73,7 @@ func Push(ctx context.Context, dEnv *env.DoltEnv, mode ref.RefUpdateMode, destRe
|
||||
return err
|
||||
}
|
||||
|
||||
// PushTag pushes a commit tag and all underlying data from a local source database to a remote destination database.
|
||||
func PushTag(ctx context.Context, dEnv *env.DoltEnv, destRef ref.TagRef, srcDB, destDB *doltdb.DoltDB, tag *doltdb.Tag, progChan chan datas.PullProgress, pullerEventCh chan datas.PullerEvent) error {
|
||||
var err error
|
||||
|
||||
@@ -117,6 +118,7 @@ func DeleteRemoteBranch(ctx context.Context, targetRef ref.BranchRef, remoteRef
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchCommit takes a fetches a commit and all underlying data from a remote source database to the local destination database.
|
||||
func FetchCommit(ctx context.Context, dEnv *env.DoltEnv, srcDB, destDB *doltdb.DoltDB, srcDBCommit *doltdb.Commit, progChan chan datas.PullProgress, pullerEventCh chan datas.PullerEvent) error {
|
||||
stRef, err := srcDBCommit.GetStRef()
|
||||
|
||||
@@ -127,6 +129,7 @@ func FetchCommit(ctx context.Context, dEnv *env.DoltEnv, srcDB, destDB *doltdb.D
|
||||
return destDB.PullChunks(ctx, dEnv.TempTableFilesDir(), srcDB, stRef, progChan, pullerEventCh)
|
||||
}
|
||||
|
||||
// FetchCommit takes a fetches a commit tag and all underlying data from a remote source database to the local destination database.
|
||||
func FetchTag(ctx context.Context, dEnv *env.DoltEnv, srcDB, destDB *doltdb.DoltDB, srcDBTag *doltdb.Tag, progChan chan datas.PullProgress, pullerEventCh chan datas.PullerEvent) error {
|
||||
stRef, err := srcDBTag.GetStRef()
|
||||
|
||||
@@ -137,6 +140,7 @@ func FetchTag(ctx context.Context, dEnv *env.DoltEnv, srcDB, destDB *doltdb.Dolt
|
||||
return destDB.PullChunks(ctx, dEnv.TempTableFilesDir(), srcDB, stRef, progChan, pullerEventCh)
|
||||
}
|
||||
|
||||
// Clone pulls all data from a remote source database to a local destination database.
|
||||
func Clone(ctx context.Context, srcDB, destDB *doltdb.DoltDB, eventCh chan<- datas.TableFileEvent) error {
|
||||
return srcDB.Clone(ctx, destDB, eventCh)
|
||||
}
|
||||
|
||||
@@ -210,13 +210,13 @@ func (db *database) doSetHead(ctx context.Context, ds Dataset, newHeadRef types.
|
||||
return err
|
||||
}
|
||||
|
||||
stRef, err := db.WriteValue(ctx, newSt) // will be orphaned if the tryCommitChunks() below fails
|
||||
refSt, err := db.WriteValue(ctx, newSt) // will be orphaned if the tryCommitChunks() below fails
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ref, err := types.ToRefOfValue(stRef, db.Format())
|
||||
ref, err := types.ToRefOfValue(refSt, db.Format())
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user