mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-17 19:10:18 -05:00
More principled naming / filter choices for default refs
This commit is contained in:
@@ -143,7 +143,7 @@ func printBranches(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
|
||||
printRemote := apr.Contains(remoteParam)
|
||||
printAll := apr.Contains(allFlag)
|
||||
|
||||
branches, err := dEnv.DoltDB.GetRefs(ctx)
|
||||
branches, err := dEnv.DoltDB.GetHeadRefs(ctx)
|
||||
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.BuildDError("error: failed to read refs from db").AddCause(err).Build(), nil)
|
||||
|
||||
@@ -86,7 +86,7 @@ func (cmd FetchCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
remotes, _ := dEnv.GetRemotes()
|
||||
r, refSpecs, verr := getRefSpecs(apr.Args(), dEnv, remotes)
|
||||
|
||||
updateMode := ref.RefUpdateMode{Force: apr.Contains(ForceFetchFlag)}
|
||||
updateMode := ref.UpdateMode{Force: apr.Contains(ForceFetchFlag)}
|
||||
|
||||
if verr == nil {
|
||||
verr = fetchRefSpecs(ctx, updateMode, dEnv, r, refSpecs)
|
||||
@@ -178,7 +178,7 @@ func mapRefspecsToRemotes(refSpecs []ref.RemoteRefSpec, dEnv *env.DoltEnv) (map[
|
||||
return rsToRem, nil
|
||||
}
|
||||
|
||||
func fetchRefSpecs(ctx context.Context, mode ref.RefUpdateMode, dEnv *env.DoltEnv, rem env.Remote, refSpecs []ref.RemoteRefSpec) errhand.VerboseError {
|
||||
func fetchRefSpecs(ctx context.Context, mode ref.UpdateMode, dEnv *env.DoltEnv, rem env.Remote, refSpecs []ref.RemoteRefSpec) errhand.VerboseError {
|
||||
srcDB, err := rem.GetRemoteDB(ctx, dEnv.DoltDB.ValueReadWriter().Format())
|
||||
|
||||
if err != nil {
|
||||
@@ -187,7 +187,7 @@ func fetchRefSpecs(ctx context.Context, mode ref.RefUpdateMode, dEnv *env.DoltEn
|
||||
|
||||
for _, rs := range refSpecs {
|
||||
|
||||
branchRefs, err := srcDB.GetRefs(ctx)
|
||||
branchRefs, err := srcDB.GetHeadRefs(ctx)
|
||||
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to read from ").AddCause(err).Build()
|
||||
|
||||
@@ -192,7 +192,7 @@ func pushMigratedRepo(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.Arg
|
||||
}
|
||||
|
||||
cli.Println(color.BlueString(fmt.Sprintf("Pushing migrated branch %s to %s", branch.String(), remoteName)))
|
||||
mode := ref.RefUpdateMode{Force: true}
|
||||
mode := ref.UpdateMode{Force: true}
|
||||
err = pushToRemoteBranch(ctx, dEnv, mode, src, dest, remoteRef, dEnv.DoltDB, destDB, remote)
|
||||
|
||||
if err != nil {
|
||||
@@ -232,7 +232,7 @@ func fetchMigratedRemoteBranches(ctx context.Context, dEnv *env.DoltEnv, apr *ar
|
||||
r, refSpecs, err := getRefSpecs(apr.Args(), dEnv, remotes)
|
||||
|
||||
if err == nil {
|
||||
err = fetchRefSpecs(ctx, ref.RefUpdateMode{Force: true}, dEnv, r, refSpecs)
|
||||
err = fetchRefSpecs(ctx, ref.UpdateMode{Force: true}, dEnv, r, refSpecs)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@@ -49,7 +49,7 @@ type pushOpts struct {
|
||||
destRef ref.DoltRef
|
||||
remoteRef ref.DoltRef
|
||||
remote env.Remote
|
||||
mode ref.RefUpdateMode
|
||||
mode ref.UpdateMode
|
||||
setUpstream bool
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ func parsePushArgs(ctx context.Context, apr *argparser.ArgParseResults, dEnv *en
|
||||
destRef: dest,
|
||||
remoteRef: remoteRef,
|
||||
remote: remote,
|
||||
mode: ref.RefUpdateMode{
|
||||
mode: ref.UpdateMode{
|
||||
Force: apr.Contains(ForcePushFlag),
|
||||
},
|
||||
setUpstream: apr.Contains(SetUpstreamFlag),
|
||||
@@ -361,7 +361,7 @@ func deleteRemoteBranch(ctx context.Context, toDelete, remoteRef ref.DoltRef, lo
|
||||
return nil
|
||||
}
|
||||
|
||||
func pushToRemoteBranch(ctx context.Context, dEnv *env.DoltEnv, mode ref.RefUpdateMode, srcRef, destRef, remoteRef ref.DoltRef, localDB, remoteDB *doltdb.DoltDB, remote env.Remote) errhand.VerboseError {
|
||||
func pushToRemoteBranch(ctx context.Context, dEnv *env.DoltEnv, mode ref.UpdateMode, srcRef, destRef, remoteRef ref.DoltRef, localDB, remoteDB *doltdb.DoltDB, remote env.Remote) errhand.VerboseError {
|
||||
evt := events.GetEventFromContext(ctx)
|
||||
|
||||
u, err := earl.Parse(remote.Url)
|
||||
|
||||
@@ -53,7 +53,7 @@ func CommitItrForAllBranches(ctx context.Context, ddb *DoltDB) (CommitItr, error
|
||||
|
||||
rootCommits := make([]*Commit, 0, len(branchRefs))
|
||||
for _, ref := range branchRefs {
|
||||
cm, err := ddb.ResolveRef(ctx, ref)
|
||||
cm, err := ddb.ResolveCommitRef(ctx, ref)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -353,8 +353,9 @@ func (ddb *DoltDB) Resolve(ctx context.Context, cs *CommitSpec, cwb ref.DoltRef)
|
||||
return NewCommit(ddb.db, commitSt), nil
|
||||
}
|
||||
|
||||
// ResolveRef takes a DoltRef and returns a Commit, or an error if the commit cannot be found.
|
||||
func (ddb *DoltDB) ResolveRef(ctx context.Context, ref ref.DoltRef) (*Commit, error) {
|
||||
// ResolveCommitRef takes a DoltRef and returns a Commit, or an error if the commit cannot be found. The ref given must
|
||||
// point to a Commit.
|
||||
func (ddb *DoltDB) ResolveCommitRef(ctx context.Context, ref ref.DoltRef) (*Commit, error) {
|
||||
commitSt, err := getCommitStForRefStr(ctx, ddb.db, ref.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -482,7 +483,7 @@ func (ddb *DoltDB) FastForward(ctx context.Context, branch ref.DoltRef, commit *
|
||||
|
||||
// CanFastForward returns whether the given branch can be fast-forwarded to the commit given.
|
||||
func (ddb *DoltDB) CanFastForward(ctx context.Context, branch ref.DoltRef, new *Commit) (bool, error) {
|
||||
current, err := ddb.ResolveRef(ctx, branch)
|
||||
current, err := ddb.ResolveCommitRef(ctx, branch)
|
||||
|
||||
if err != nil {
|
||||
if err == ErrBranchNotFound {
|
||||
@@ -731,26 +732,6 @@ func (ddb *DoltDB) HasRef(ctx context.Context, doltRef ref.DoltRef) (bool, error
|
||||
return dss.Has(ctx, types.String(doltRef.String()))
|
||||
}
|
||||
|
||||
// GetRef returns the ref given, if it exists
|
||||
func (ddb *DoltDB) GetRef(ctx context.Context, doltRef ref.DoltRef) (hash.Hash, bool, error) {
|
||||
ds, err := ddb.db.GetDataset(ctx, doltRef.String())
|
||||
if err != nil {
|
||||
return hash.Hash{}, false, err
|
||||
}
|
||||
|
||||
if !ds.HasHead() {
|
||||
return hash.Hash{}, false, nil
|
||||
}
|
||||
|
||||
head, ok := ds.MaybeHead()
|
||||
if !ok {
|
||||
return hash.Hash{}, false, nil
|
||||
}
|
||||
|
||||
hash, err := head.Hash(ddb.Format())
|
||||
return hash, true, err
|
||||
}
|
||||
|
||||
var branchRefFilter = map[ref.RefType]struct{}{ref.BranchRefType: {}}
|
||||
|
||||
// GetBranches returns a list of all branches in the database.
|
||||
@@ -779,9 +760,9 @@ func (ddb *DoltDB) GetWorkingSets(ctx context.Context) ([]ref.DoltRef, error) {
|
||||
return ddb.GetRefsOfType(ctx, workingSetsRefFilter)
|
||||
}
|
||||
|
||||
// GetRefs returns a list of all refs in the database.
|
||||
func (ddb *DoltDB) GetRefs(ctx context.Context) ([]ref.DoltRef, error) {
|
||||
return ddb.GetRefsOfType(ctx, ref.RefTypes)
|
||||
// GetHeadRefs returns a list of all refs that point to a Commit
|
||||
func (ddb *DoltDB) GetHeadRefs(ctx context.Context) ([]ref.DoltRef, error) {
|
||||
return ddb.GetRefsOfType(ctx, ref.HeadRefTypes)
|
||||
}
|
||||
|
||||
func (ddb *DoltDB) GetRefsOfType(ctx context.Context, refTypeFilter map[ref.RefType]struct{}) ([]ref.DoltRef, error) {
|
||||
@@ -897,7 +878,8 @@ func (ddb *DoltDB) NewTagAtCommit(ctx context.Context, tagRef ref.DoltRef, c *Co
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateWorkingSet updates the working set with the ref given.
|
||||
// UpdateWorkingSet updates the working set with the ref given to the root value given
|
||||
// |prevHash| is the hash of the expected WorkingSet struct stored in the ref, not the hash of the RootValue there.
|
||||
func (ddb *DoltDB) UpdateWorkingSet(ctx context.Context, workingSetRef ref.DoltRef, rootVal *RootValue, prevHash hash.Hash) error {
|
||||
if !IsWorkingSetRef(workingSetRef) {
|
||||
panic(fmt.Sprintf("invalid working set ref %s", workingSetRef.String()))
|
||||
|
||||
2
go/libraries/doltcore/env/actions/remotes.go
vendored
2
go/libraries/doltcore/env/actions/remotes.go
vendored
@@ -31,7 +31,7 @@ var ErrCantFF = errors.New("can't fast forward merge")
|
||||
// the given commit via a fast forward merge. If this is the case, an attempt will be made to update the branch in the
|
||||
// destination db to the given commit via fast forward move. If that succeeds the tracking branch is updated in the
|
||||
// source db.
|
||||
func Push(ctx context.Context, dEnv *env.DoltEnv, mode ref.RefUpdateMode, destRef ref.BranchRef, remoteRef ref.RemoteRef, srcDB, destDB *doltdb.DoltDB, commit *doltdb.Commit, progChan chan datas.PullProgress, pullerEventCh chan datas.PullerEvent) error {
|
||||
func Push(ctx context.Context, dEnv *env.DoltEnv, mode ref.UpdateMode, destRef ref.BranchRef, remoteRef ref.RemoteRef, srcDB, destDB *doltdb.DoltDB, commit *doltdb.Commit, progChan chan datas.PullProgress, pullerEventCh chan datas.PullerEvent) error {
|
||||
var err error
|
||||
if mode == ref.FastForwardOnly {
|
||||
canFF, err := srcDB.CanFastForward(ctx, remoteRef, commit)
|
||||
|
||||
4
go/libraries/doltcore/env/environment.go
vendored
4
go/libraries/doltcore/env/environment.go
vendored
@@ -361,7 +361,7 @@ func (r *repoStateReader) CWBHeadSpec() *doltdb.CommitSpec {
|
||||
|
||||
func (r *repoStateReader) CWBHeadHash(ctx context.Context) (hash.Hash, error) {
|
||||
ref := r.CWBHeadRef()
|
||||
cm, err := r.dEnv.DoltDB.ResolveRef(ctx, ref)
|
||||
cm, err := r.dEnv.DoltDB.ResolveCommitRef(ctx, ref)
|
||||
|
||||
if err != nil {
|
||||
return hash.Hash{}, err
|
||||
@@ -480,7 +480,7 @@ func (dEnv *DoltEnv) DocsReadWriter() DocsReadWriter {
|
||||
}
|
||||
|
||||
func (dEnv *DoltEnv) HeadRoot(ctx context.Context) (*doltdb.RootValue, error) {
|
||||
commit, err := dEnv.DoltDB.ResolveRef(ctx, dEnv.RepoState.CWBHeadRef())
|
||||
commit, err := dEnv.DoltDB.ResolveCommitRef(ctx, dEnv.RepoState.CWBHeadRef())
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
2
go/libraries/doltcore/env/repo_state.go
vendored
2
go/libraries/doltcore/env/repo_state.go
vendored
@@ -226,7 +226,7 @@ func UpdateWorkingRoot(ctx context.Context, ddb *doltdb.DoltDB, rsw RepoStateWri
|
||||
|
||||
// Returns the head root.
|
||||
func HeadRoot(ctx context.Context, ddb *doltdb.DoltDB, rsr RepoStateReader) (*doltdb.RootValue, error) {
|
||||
commit, err := ddb.ResolveRef(ctx, rsr.CWBHeadRef())
|
||||
commit, err := ddb.ResolveCommitRef(ctx, rsr.CWBHeadRef())
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -139,7 +139,7 @@ func rebaseRefs(ctx context.Context, dbData env.DbData, replay ReplayCommitFn, n
|
||||
|
||||
heads := make([]*doltdb.Commit, len(refs))
|
||||
for i, dRef := range refs {
|
||||
heads[i], err = ddb.ResolveRef(ctx, dRef)
|
||||
heads[i], err = ddb.ResolveCommitRef(ctx, dRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func rebaseRefs(ctx context.Context, dbData env.DbData, replay ReplayCommitFn, n
|
||||
}
|
||||
}
|
||||
|
||||
cm, err := ddb.ResolveRef(ctx, cwbRef)
|
||||
cm, err := ddb.ResolveCommitRef(ctx, cwbRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -56,18 +56,18 @@ const (
|
||||
WorkingSetRefType RefType = "workingSets"
|
||||
)
|
||||
|
||||
// RefTypes is the set of all supported reference types. External RefTypes can be added to this map in order to add
|
||||
// RefTypes for external tooling
|
||||
var RefTypes = map[RefType]struct{}{
|
||||
BranchRefType: {},
|
||||
RemoteRefType: {},
|
||||
InternalRefType: {},
|
||||
TagRefType: {},
|
||||
WorkspaceRefType: {},
|
||||
WorkingSetRefType: {},
|
||||
var allRefTypes = []RefType{
|
||||
BranchRefType,
|
||||
RemoteRefType,
|
||||
InternalRefType,
|
||||
TagRefType,
|
||||
WorkspaceRefType,
|
||||
WorkingSetRefType,
|
||||
}
|
||||
|
||||
// HeadRefTypes are the ref types that point to a HEAD.
|
||||
// HeadRefTypes are the ref types that point to a HEAD and contain a Commit struct. These are the types that are
|
||||
// returned by GetHeadRefs. Other ref types don't point to Commits necessarily, so aren't in this list and must be
|
||||
// asked for explicitly.
|
||||
var HeadRefTypes = map[RefType]struct{}{
|
||||
BranchRefType: {},
|
||||
RemoteRefType: {},
|
||||
@@ -81,21 +81,21 @@ func PrefixForType(refType RefType) string {
|
||||
return refPrefix + string(refType) + "/"
|
||||
}
|
||||
|
||||
type RefUpdateMode struct {
|
||||
type UpdateMode struct {
|
||||
Force bool
|
||||
}
|
||||
|
||||
var ForceUpdate = RefUpdateMode{true}
|
||||
var FastForwardOnly = RefUpdateMode{false}
|
||||
var ForceUpdate = UpdateMode{true}
|
||||
var FastForwardOnly = UpdateMode{false}
|
||||
|
||||
// DoltRef is a reference to a commit.
|
||||
type DoltRef interface {
|
||||
fmt.Stringer
|
||||
|
||||
// Type is the RefType of this ref
|
||||
// GetType returns the RefType of this ref
|
||||
GetType() RefType
|
||||
|
||||
// Path is the identifier for the reference
|
||||
// GetPath returns the identifier for the reference
|
||||
GetPath() string
|
||||
}
|
||||
|
||||
@@ -121,12 +121,12 @@ func EqualsStr(dr DoltRef, str string) bool {
|
||||
return Equals(dr, other)
|
||||
}
|
||||
|
||||
// String() converts the DoltRef to a reference string in the format refs/type/path
|
||||
// String converts the DoltRef to a reference string in the format refs/type/path
|
||||
func String(dr DoltRef) string {
|
||||
return PrefixForType(dr.GetType()) + dr.GetPath()
|
||||
}
|
||||
|
||||
// MarshalJson implements the json Marshaler interface to json encode DoltRefs as their string representation
|
||||
// MarshalJSON implements the json Marshaler interface to json encode DoltRefs as their string representation
|
||||
func MarshalJSON(dr DoltRef) ([]byte, error) {
|
||||
str := dr.String()
|
||||
data := make([]byte, len(str)+2)
|
||||
@@ -152,7 +152,7 @@ func Parse(str string) (DoltRef, error) {
|
||||
}
|
||||
}
|
||||
|
||||
for rType := range RefTypes {
|
||||
for _, rType := range allRefTypes {
|
||||
prefix := PrefixForType(rType)
|
||||
if strings.HasPrefix(str, prefix) {
|
||||
str = str[len(prefix):]
|
||||
|
||||
@@ -82,7 +82,7 @@ func (t *HashOf) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cm, err = ddb.ResolveRef(ctx, branchRef)
|
||||
cm, err = ddb.ResolveCommitRef(ctx, branchRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func getBranchCommit(ctx *sql.Context, val interface{}, ddb *doltdb.DoltDB) (*do
|
||||
return nil, hash.Hash{}, err
|
||||
}
|
||||
|
||||
cm, err := ddb.ResolveRef(ctx, branchRef)
|
||||
cm, err := ddb.ResolveCommitRef(ctx, branchRef)
|
||||
|
||||
if err != nil {
|
||||
return nil, hash.Hash{}, err
|
||||
|
||||
@@ -94,7 +94,7 @@ func NewBranchItr(sqlCtx *sql.Context, ddb *doltdb.DoltDB) (*BranchItr, error) {
|
||||
branchNames := make([]string, len(branches))
|
||||
commits := make([]*doltdb.Commit, len(branches))
|
||||
for i, branch := range branches {
|
||||
commit, err := ddb.ResolveRef(sqlCtx, branch)
|
||||
commit, err := ddb.ResolveCommitRef(sqlCtx, branch)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
"github.com/dolthub/go-mysql-server/sql/expression"
|
||||
"github.com/dolthub/go-mysql-server/sql/parse"
|
||||
@@ -116,7 +115,7 @@ func NewCommitDiffTable(ctx *sql.Context, tblName string, ddb *doltdb.DoltDB, ro
|
||||
}
|
||||
|
||||
func calcSuperDuperSchema(ctx context.Context, ddb *doltdb.DoltDB, working *doltdb.RootValue, tblName string) (*schema.SuperSchema, error) {
|
||||
refs, err := ddb.GetRefsOfType(ctx, ref.HeadRefTypes)
|
||||
refs, err := ddb.GetHeadRefs(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -134,7 +133,7 @@ func calcSuperDuperSchema(ctx context.Context, ddb *doltdb.DoltDB, working *dolt
|
||||
}
|
||||
|
||||
for _, ref := range refs {
|
||||
cm, err := ddb.ResolveRef(ctx, ref)
|
||||
cm, err := ddb.ResolveCommitRef(ctx, ref)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user