Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shallow Clone #7486

Merged
merged 19 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/cmd/dolt/cli/arg_parser_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func CreateCloneArgParser() *argparser.ArgParser {
ap := argparser.NewArgParserWithMaxArgs("clone", 2)
ap.SupportsString(RemoteParam, "", "name", "Name of the remote to be added to the cloned database. The default is 'origin'.")
ap.SupportsString(BranchParam, "b", "branch", "The branch to be cloned. If not specified all branches will be cloned.")
ap.SupportsString(DepthFlag, "", "depth", "Clone a single branch and limit history to the given commit depth.")
ap.SupportsString(dbfactory.AWSRegionParam, "", "region", "")
ap.SupportsValidatedString(dbfactory.AWSCredsTypeParam, "", "creds-type", "", argparser.ValidatorFromStrList(dbfactory.AWSCredsTypeParam, dbfactory.AWSCredTypes))
ap.SupportsString(dbfactory.AWSCredsFileParam, "", "file", "AWS credentials file.")
Expand Down
1 change: 1 addition & 0 deletions go/cmd/dolt/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
DecorateFlag = "decorate"
DeleteFlag = "delete"
DeleteForceFlag = "D"
DepthFlag = "depth"
DryRunFlag = "dry-run"
ForceFlag = "force"
HardResetParam = "hard"
Expand Down
7 changes: 6 additions & 1 deletion go/cmd/dolt/commands/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ func clone(ctx context.Context, apr *argparser.ArgParseResults, dEnv *env.DoltEn
return errhand.VerboseErrorFromError(err)
}

depth, ok := apr.GetInt(cli.DepthFlag)
if !ok {
depth = -1
}

// Nil out the old Dolt env so we don't accidentally operate on the wrong database
dEnv = nil

err = actions.CloneRemote(ctx, srcDB, remoteName, branch, singleBranch, clonedEnv)
err = actions.CloneRemote(ctx, srcDB, remoteName, branch, singleBranch, depth, clonedEnv)
if err != nil {
// If we're cloning into a directory that already exists do not erase it. Otherwise
// make best effort to delete the directory we created.
Expand Down
4 changes: 4 additions & 0 deletions go/cmd/dolt/commands/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package commands

import (
"context"
"errors"
"fmt"
"io"
"strconv"
Expand Down Expand Up @@ -433,6 +434,9 @@ func (dArgs *diffArgs) applyDiffRoots(queryist cli.Queryist, sqlCtx *sql.Context
fromRef := args[0]
// treat the first arg as a ref spec
_, err := getTableNamesAtRef(queryist, sqlCtx, fromRef)
if errors.Is(err, doltdb.ErrGhostCommitEncountered) {
return nil, err
}
// if it doesn't resolve, treat it as a table name
if err != nil {
// `dolt diff table`
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/engine/sqlengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewSqlEngine(
return nil, err
}

all := append(dbs)
all := dbs[:]

clusterDB := config.ClusterController.ClusterDatabase()
if clusterDB != nil {
Expand Down
6 changes: 5 additions & 1 deletion go/cmd/dolt/commands/filter-branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ func getNerf(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResu
return nil, err
}

cm, err := dEnv.DoltDB.Resolve(ctx, cs, headRef)
optCmt, err := dEnv.DoltDB.Resolve(ctx, cs, headRef)
if err != nil {
return nil, err
}
cm, ok := optCmt.ToCommit()
if !ok {
return nil, doltdb.ErrGhostCommitEncountered
}

return rebase.StopAtCommit(cm), nil
}
Expand Down
7 changes: 5 additions & 2 deletions go/cmd/dolt/commands/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func TestLog(t *testing.T) {
}

cs, _ := doltdb.NewCommitSpec(env.DefaultInitBranch)
commit, _ := dEnv.DoltDB.Resolve(context.Background(), cs, nil)
opt, _ := dEnv.DoltDB.Resolve(context.Background(), cs, nil)
commit, _ := opt.ToCommit()

meta, _ := commit.GetCommitMeta(context.Background())
require.Equal(t, "Bill Billerson", meta.Name)
}
Expand All @@ -60,7 +62,8 @@ func TestLogSigterm(t *testing.T) {
}

cs, _ := doltdb.NewCommitSpec(env.DefaultInitBranch)
commit, _ := dEnv.DoltDB.Resolve(context.Background(), cs, nil)
optCmt, _ := dEnv.DoltDB.Resolve(context.Background(), cs, nil)
commit, _ := optCmt.ToCommit()
cMeta, _ := commit.GetCommitMeta(context.Background())
cHash, _ := commit.HashOf()

Expand Down
10 changes: 6 additions & 4 deletions go/cmd/dolt/commands/read_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func pullTableValue(ctx context.Context, dEnv *env.DoltEnv, srcDB *doltdb.DoltDB
cli.Println("Retrieving", tblName)
runProgFunc := buildProgStarter(language)
wg, pullerEventCh := runProgFunc(newCtx)
err = dEnv.DoltDB.PullChunks(ctx, tmpDir, srcDB, []hash.Hash{tblHash}, pullerEventCh)
err = dEnv.DoltDB.PullChunks(ctx, tmpDir, srcDB, []hash.Hash{tblHash}, pullerEventCh, nil)
stopProgFuncs(cancelFunc, wg, pullerEventCh)
if err != nil {
return nil, errhand.BuildDError("Failed reading chunks for remote table '%s' at '%s'", tblName, commitStr).AddCause(err).Build()
Expand All @@ -217,14 +217,16 @@ func getRemoteDBAtCommit(ctx context.Context, remoteUrl string, remoteUrlParams
return nil, nil, errhand.BuildDError("Invalid Commit '%s'", commitStr).Build()
}

cm, err := srcDB.Resolve(ctx, cs, nil)

optCmt, err := srcDB.Resolve(ctx, cs, nil)
if err != nil {
return nil, nil, errhand.BuildDError("Failed to find commit '%s'", commitStr).Build()
}
cm, ok := optCmt.ToCommit()
if !ok {
return nil, nil, errhand.BuildDError(doltdb.ErrGhostCommitEncountered.Error()).Build()
}

srcRoot, err := cm.GetRootValue(ctx)

if err != nil {
return nil, nil, errhand.BuildDError("Failed to read from database").AddCause(err).Build()
}
Expand Down
6 changes: 5 additions & 1 deletion go/cmd/dolt/commands/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,14 @@ func printObjects(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts) error
return err
}

commit, err := dEnv.DoltDB.Resolve(ctx, headSpec, headRef)
optCmt, err := dEnv.DoltDB.Resolve(ctx, headSpec, headRef)
if err != nil {
return err
}
commit, ok := optCmt.ToCommit()
if !ok {
return doltdb.ErrGhostCommitEncountered
}

value := commit.Value()
cli.Println(value.Kind(), value.HumanReadableString())
Expand Down
9 changes: 8 additions & 1 deletion go/cmd/dolt/commands/stashcmds/pop.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,17 @@ func applyStashAtIdx(ctx *sql.Context, dEnv *env.DoltEnv, curWorkingRoot *doltdb
if err != nil {
return false, err
}
parentCommit, err := dEnv.DoltDB.Resolve(ctx, headCommitSpec, headRef)
optCmt, err := dEnv.DoltDB.Resolve(ctx, headCommitSpec, headRef)
if err != nil {
return false, err
}
parentCommit, ok := optCmt.ToCommit()
if !ok {
// Should not be possible to get into this situation. The parent of the stashed commit
// Must have been present at the time it was created
return false, doltdb.ErrGhostCommitEncountered
}

parentRoot, err := parentCommit.GetRootValue(ctx)
if err != nil {
return false, err
Expand Down
7 changes: 6 additions & 1 deletion go/cmd/dolt/commands/stashcmds/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ func stashChanges(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars
if err != nil {
return err
}
commit, err := dEnv.DoltDB.Resolve(ctx, commitSpec, curHeadRef)
optCmt, err := dEnv.DoltDB.Resolve(ctx, commitSpec, curHeadRef)
if err != nil {
return err
}
commit, ok := optCmt.ToCommit()
if !ok {
return doltdb.ErrGhostCommitEncountered
}

commitMeta, err := commit.GetCommitMeta(ctx)
if err != nil {
return err
Expand Down
13 changes: 11 additions & 2 deletions go/libraries/doltcore/cherry_pick/cherry_pick.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,14 @@ func cherryPick(ctx *sql.Context, dSess *dsess.DoltSession, roots doltdb.Roots,
if err != nil {
return nil, "", err
}
cherryCommit, err := doltDB.Resolve(ctx, cherryCommitSpec, headRef)
optCmt, err := doltDB.Resolve(ctx, cherryCommitSpec, headRef)
if err != nil {
return nil, "", err
}
cherryCommit, ok := optCmt.ToCommit()
if !ok {
return nil, "", doltdb.ErrGhostCommitEncountered
}

if len(cherryCommit.DatasParents()) > 1 {
return nil, "", fmt.Errorf("cherry-picking a merge commit is not supported")
Expand All @@ -223,10 +227,15 @@ func cherryPick(ctx *sql.Context, dSess *dsess.DoltSession, roots doltdb.Roots,

// When cherry-picking, we need to use the parent of the cherry-picked commit as the ancestor. This
// ensures that only the delta from the cherry-pick commit is applied.
parentCommit, err := doltDB.ResolveParent(ctx, cherryCommit, 0)
optCmt, err = doltDB.ResolveParent(ctx, cherryCommit, 0)
if err != nil {
return nil, "", err
}
parentCommit, ok := optCmt.ToCommit()
if !ok {
return nil, "", doltdb.ErrGhostCommitEncountered
}

parentRoot, err := parentCommit.GetRootValue(ctx)
if err != nil {
return nil, "", err
Expand Down
6 changes: 5 additions & 1 deletion go/libraries/doltcore/dbfactory/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,16 @@ func (fact FileFactory) CreateDB(ctx context.Context, nbf *types.NomsBinFormat,
}

oldGenSt, err := nbs.NewLocalStore(ctx, newGenSt.Version(), oldgenPath, defaultMemTableSize, q)
if err != nil {
return nil, nil, nil, err
}

ghostGen, err := nbs.NewGhostBlockStore(path)
if err != nil {
return nil, nil, nil, err
}

st := nbs.NewGenerationalCS(oldGenSt, newGenSt)
st := nbs.NewGenerationalCS(oldGenSt, newGenSt, ghostGen)
// metrics?

vrw := types.NewValueStore(st)
Expand Down
30 changes: 0 additions & 30 deletions go/libraries/doltcore/diff/diffsplitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
package diff

import (
"context"
"errors"
"strings"

"github.com/dolthub/go-mysql-server/sql"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
)

const (
Expand Down Expand Up @@ -218,29 +214,3 @@ func (ds DiffSplitter) SplitDiffResultRow(row sql.Row) (from, to RowDiff, err er
}
return
}

// MaybeResolveRoot returns a root value and true if the a commit exists for given spec string; nil and false if it does not exist.
// todo: distinguish between non-existent CommitSpec and other errors, don't assume non-existent
func MaybeResolveRoot(ctx context.Context, rsr env.RepoStateReader, doltDB *doltdb.DoltDB, spec string) (*doltdb.RootValue, bool) {
cs, err := doltdb.NewCommitSpec(spec)
if err != nil {
// it's non-existent CommitSpec
return nil, false
}

headRef, err := rsr.CWBHeadRef()
if err != nil {
return nil, false
}
cm, err := doltDB.Resolve(ctx, cs, headRef)
if err != nil {
return nil, false
}

root, err := cm.GetRootValue(ctx)
if err != nil {
return nil, false
}

return root, true
}
Loading
Loading