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

make tags case insensitive #8153

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ func getDBBranchFromSession(sqlCtx *sql.Context, qryist cli.Queryist) (db string

// It is possible to `use mydb/branch`, and as far as your session is concerned your database is mydb/branch. We
// allow that, but also want to show the user the branch name in the prompt. So we munge the DB in this case.
if strings.HasSuffix(db, "/"+branch) {
if strings.HasSuffix(strings.ToLower(db), strings.ToLower("/"+branch)) {
db = db[:len(db)-len(branch)-1]
}
}
Expand Down
15 changes: 7 additions & 8 deletions go/libraries/doltcore/doltdb/doltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,15 +980,14 @@ func (ddb *DoltDB) GetBranchesByNomsRoot(ctx context.Context, nomsRoot hash.Hash
// HasBranch returns whether the DB has a branch with the name given, case-insensitive. Returns the case-sensitive
// matching branch if found, as well as a bool indicating if there was a case-insensitive match, and any error.
func (ddb *DoltDB) HasBranch(ctx context.Context, branchName string) (string, bool, error) {
branchName = strings.ToLower(branchName)
branches, err := ddb.GetRefsOfType(ctx, branchRefFilter)
if err != nil {
return "", false, err
}

for _, b := range branches {
if strings.ToLower(b.GetPath()) == branchName {
return b.GetPath(), true, nil
if path := b.GetPath(); strings.EqualFold(path, branchName) {
return path, true, nil
}
}

Expand Down Expand Up @@ -1064,19 +1063,19 @@ func (ddb *DoltDB) GetTags(ctx context.Context) ([]ref.DoltRef, error) {
}

// HasTag returns whether the DB has a tag with the name given
func (ddb *DoltDB) HasTag(ctx context.Context, tagName string) (bool, error) {
func (ddb *DoltDB) HasTag(ctx context.Context, tagName string) (string, bool, error) {
tags, err := ddb.GetRefsOfType(ctx, tagsRefFilter)
if err != nil {
return false, err
return "", false, err
}

for _, t := range tags {
if t.GetPath() == tagName {
return true, nil
if path := t.GetPath(); strings.EqualFold(path, tagName) {
return path, true, nil
}
}

return false, nil
return "", false, nil
}

type TagWithHash struct {
Expand Down
14 changes: 7 additions & 7 deletions go/libraries/doltcore/sqle/database_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,13 @@ func revisionDbType(ctx *sql.Context, srcDb dsess.SqlDatabase, revSpec string) (
return dsess.RevisionTypeBranch, caseSensitiveBranchName, nil
}

isTag, err := isTag(ctx, srcDb, resolvedRevSpec)
caseSensitiveTagName, isTag, err := isTag(ctx, srcDb, resolvedRevSpec)
if err != nil {
return dsess.RevisionTypeNone, "", err
}

if isTag {
return dsess.RevisionTypeTag, resolvedRevSpec, nil
return dsess.RevisionTypeTag, caseSensitiveTagName, nil
}

if doltdb.IsValidCommitHash(resolvedRevSpec) {
Expand Down Expand Up @@ -1401,21 +1401,21 @@ func isRemoteBranch(ctx context.Context, ddbs []*doltdb.DoltDB, branchName strin
}

// isTag returns whether a tag with the given name is in scope for the database given
func isTag(ctx context.Context, db dsess.SqlDatabase, tagName string) (bool, error) {
func isTag(ctx context.Context, db dsess.SqlDatabase, tagName string) (string, bool, error) {
ddbs := db.DoltDatabases()

for _, ddb := range ddbs {
tagExists, err := ddb.HasTag(ctx, tagName)
tName, tagExists, err := ddb.HasTag(ctx, tagName)
if err != nil {
return false, err
return "", false, err
}

if tagExists {
return true, nil
return tName, true, nil
}
}

return false, nil
return "", false, nil
}

// revisionDbForBranch returns a new database that is tied to the branch named by revSpec
Expand Down
34 changes: 34 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4619,6 +4619,40 @@ var DoltTagTestScripts = []queries.ScriptTest{
},
},
},
{
Name: "dolt-tag: case insensitive",
SetUpScript: []string{
"CREATE TABLE test(pk int primary key);",
"CALL DOLT_COMMIT('-Am','created table test');",
"CALL DOLT_TAG('ABC');",
"INSERT INTO test VALUES (0),(1),(2);",
"CALL DOLT_COMMIT('-am','inserted rows into test');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT tag_name FROM dolt_tags",
Expected: []sql.Row{
{"ABC"},
},
},
{
Query: "select * from test;",
Expected: []sql.Row{
{0},
{1},
{2},
},
},
{
Query: "use mydb/abc;",
Expected: []sql.Row{},
},
{
Query: "select * from test;",
Expected: []sql.Row{},
},
},
},
}

var DoltRemoteTestScripts = []queries.ScriptTest{
Expand Down
Loading