From 129d8d9efbc82f4da000c1c8e7c92c47e9124985 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 25 Jul 2024 13:03:58 -0700 Subject: [PATCH 1/5] case insensitive tags --- go/cmd/dolt/commands/sql.go | 2 +- go/libraries/doltcore/doltdb/doltdb.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/go/cmd/dolt/commands/sql.go b/go/cmd/dolt/commands/sql.go index 379db9cb4d0..4240829c85d 100644 --- a/go/cmd/dolt/commands/sql.go +++ b/go/cmd/dolt/commands/sql.go @@ -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] } } diff --git a/go/libraries/doltcore/doltdb/doltdb.go b/go/libraries/doltcore/doltdb/doltdb.go index 82d269834bb..42019c869dc 100644 --- a/go/libraries/doltcore/doltdb/doltdb.go +++ b/go/libraries/doltcore/doltdb/doltdb.go @@ -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 } } @@ -1071,7 +1070,7 @@ func (ddb *DoltDB) HasTag(ctx context.Context, tagName string) (bool, error) { } for _, t := range tags { - if t.GetPath() == tagName { + if strings.EqualFold(t.GetPath(), tagName) { return true, nil } } From 3c9a7f8a0a8d1fb6a55967cf7a6bc5b77a111706 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 25 Jul 2024 14:06:34 -0700 Subject: [PATCH 2/5] test --- .../doltcore/sqle/enginetest/dolt_queries.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go index 14a1031b58d..9e52fbe877a 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go @@ -4619,6 +4619,48 @@ var DoltTagTestScripts = []queries.ScriptTest{ }, }, }, + { + Name: "dolt-tag: case insensitive", + SetUpScript: []string{ + "CREATE TABLE test(pk int primary key);", + "CALL DOLT_ADD('.');", + "CALL DOLT_TAG('ABC','HEAD');", + "INSERT INTO test VALUES (0),(1),(2);", + "CALL DOLT_COMMIT('-am','created table 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: "select database();", + Expected: []sql.Row{}, + }, + { + Query: "use mydb/abc;", + Expected: []sql.Row{}, + }, + { + Query: "select * from test;", + Expected: []sql.Row{ + {0}, + {1}, + {2}, + }, + }, + }, + }, } var DoltRemoteTestScripts = []queries.ScriptTest{ From de31fcb211f530459b3cf63dc524ace59f82e51f Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 25 Jul 2024 15:03:38 -0700 Subject: [PATCH 3/5] fixing and adding test --- go/libraries/doltcore/doltdb/doltdb.go | 10 +++++----- go/libraries/doltcore/sqle/database_provider.go | 14 +++++++------- .../doltcore/sqle/enginetest/dolt_queries.go | 16 ++++------------ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/go/libraries/doltcore/doltdb/doltdb.go b/go/libraries/doltcore/doltdb/doltdb.go index 42019c869dc..e95c5518031 100644 --- a/go/libraries/doltcore/doltdb/doltdb.go +++ b/go/libraries/doltcore/doltdb/doltdb.go @@ -1063,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 strings.EqualFold(t.GetPath(), tagName) { - return true, nil + if path := t.GetPath(); strings.EqualFold(t.GetPath(), tagName) { + return path, true, nil } } - return false, nil + return "", false, nil } type TagWithHash struct { diff --git a/go/libraries/doltcore/sqle/database_provider.go b/go/libraries/doltcore/sqle/database_provider.go index 12ba86629af..8abe6ca7855 100644 --- a/go/libraries/doltcore/sqle/database_provider.go +++ b/go/libraries/doltcore/sqle/database_provider.go @@ -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) { @@ -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 diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go index 9e52fbe877a..e4e08288edc 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go @@ -4623,10 +4623,10 @@ var DoltTagTestScripts = []queries.ScriptTest{ Name: "dolt-tag: case insensitive", SetUpScript: []string{ "CREATE TABLE test(pk int primary key);", - "CALL DOLT_ADD('.');", - "CALL DOLT_TAG('ABC','HEAD');", + "CALL DOLT_COMMIT('-Am','created table test');", + "CALL DOLT_TAG('ABC');", "INSERT INTO test VALUES (0),(1),(2);", - "CALL DOLT_COMMIT('-am','created table test');", + "CALL DOLT_COMMIT('-am','inserted rows into test');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -4643,21 +4643,13 @@ var DoltTagTestScripts = []queries.ScriptTest{ {2}, }, }, - { - Query: "select database();", - Expected: []sql.Row{}, - }, { Query: "use mydb/abc;", Expected: []sql.Row{}, }, { Query: "select * from test;", - Expected: []sql.Row{ - {0}, - {1}, - {2}, - }, + Expected: []sql.Row{}, }, }, }, From 221c42b65fd2ffe26ee95c6bbc049ec0e8de3f89 Mon Sep 17 00:00:00 2001 From: James Cor Date: Thu, 25 Jul 2024 15:11:58 -0700 Subject: [PATCH 4/5] tidying up --- go/libraries/doltcore/doltdb/doltdb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/libraries/doltcore/doltdb/doltdb.go b/go/libraries/doltcore/doltdb/doltdb.go index e95c5518031..28ad921342b 100644 --- a/go/libraries/doltcore/doltdb/doltdb.go +++ b/go/libraries/doltcore/doltdb/doltdb.go @@ -1070,7 +1070,7 @@ func (ddb *DoltDB) HasTag(ctx context.Context, tagName string) (string, bool, er } for _, t := range tags { - if path := t.GetPath(); strings.EqualFold(t.GetPath(), tagName) { + if path := t.GetPath(); strings.EqualFold(path, tagName) { return path, true, nil } } From 76e60c6fe671251094c50100f963e8f158858807 Mon Sep 17 00:00:00 2001 From: jycor Date: Thu, 25 Jul 2024 22:19:35 +0000 Subject: [PATCH 5/5] [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh --- go/libraries/doltcore/sqle/enginetest/dolt_queries.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go index e4e08288edc..fa96f343c85 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go @@ -4630,7 +4630,7 @@ var DoltTagTestScripts = []queries.ScriptTest{ }, Assertions: []queries.ScriptTestAssertion{ { - Query: "SELECT tag_name FROM dolt_tags", + Query: "SELECT tag_name FROM dolt_tags", Expected: []sql.Row{ {"ABC"}, }, @@ -4648,7 +4648,7 @@ var DoltTagTestScripts = []queries.ScriptTest{ Expected: []sql.Row{}, }, { - Query: "select * from test;", + Query: "select * from test;", Expected: []sql.Row{}, }, },