From 3107bf818f6e3d978753a914871f9cda82507f5e Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Wed, 3 May 2023 11:15:27 -0700 Subject: [PATCH 1/8] Add support for % wildcard. --- go/libraries/doltcore/doltdb/ignore.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/go/libraries/doltcore/doltdb/ignore.go b/go/libraries/doltcore/doltdb/ignore.go index 127f855c33..7026f70b18 100644 --- a/go/libraries/doltcore/doltdb/ignore.go +++ b/go/libraries/doltcore/doltdb/ignore.go @@ -110,6 +110,7 @@ func compilePattern(pattern string) (*regexp.Regexp, error) { pattern = "^" + regexp.QuoteMeta(pattern) + "$" pattern = strings.Replace(pattern, "\\?", ".", -1) pattern = strings.Replace(pattern, "\\*", ".*", -1) + pattern = strings.Replace(pattern, "\\%", ".*", -1) return regexp.Compile(pattern) } @@ -119,8 +120,10 @@ func compilePattern(pattern string) (*regexp.Regexp, error) { func getMoreSpecificPatterns(lessSpecific string) (*regexp.Regexp, error) { pattern := "^" + regexp.QuoteMeta(lessSpecific) + "$" // A ? can expand to any character except for a *, since that also has special meaning in patterns. + pattern = strings.Replace(pattern, "\\?", "[^\\*]", -1) pattern = strings.Replace(pattern, "\\*", ".*", -1) + pattern = strings.Replace(pattern, "\\%", ".*", -1) return regexp.Compile(pattern) } From 689cc0c6c86d95252f82daa3c0423f8ace6761f7 Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Wed, 3 May 2023 11:40:02 -0700 Subject: [PATCH 2/8] Add bats tests for % wildcard. --- integration-tests/bats/ignore.bats | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration-tests/bats/ignore.bats b/integration-tests/bats/ignore.bats index 508f8951b8..90a0bc45ce 100644 --- a/integration-tests/bats/ignore.bats +++ b/integration-tests/bats/ignore.bats @@ -12,6 +12,8 @@ INSERT INTO dolt_ignore VALUES ("*_ignore", true), ("do_not_ignore", false), + ("%_also_ignore", true), + ("commit_*", false), ("commit_me_not", true), @@ -85,6 +87,7 @@ SQL dolt sql < Date: Wed, 3 May 2023 11:47:23 -0700 Subject: [PATCH 3/8] When comparing two patterns, ? shouldn't match a literal % --- go/libraries/doltcore/doltdb/ignore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/libraries/doltcore/doltdb/ignore.go b/go/libraries/doltcore/doltdb/ignore.go index 7026f70b18..352424c8c0 100644 --- a/go/libraries/doltcore/doltdb/ignore.go +++ b/go/libraries/doltcore/doltdb/ignore.go @@ -121,7 +121,7 @@ func getMoreSpecificPatterns(lessSpecific string) (*regexp.Regexp, error) { pattern := "^" + regexp.QuoteMeta(lessSpecific) + "$" // A ? can expand to any character except for a *, since that also has special meaning in patterns. - pattern = strings.Replace(pattern, "\\?", "[^\\*]", -1) + pattern = strings.Replace(pattern, "\\?", "[^\\*%]", -1) pattern = strings.Replace(pattern, "\\*", ".*", -1) pattern = strings.Replace(pattern, "\\%", ".*", -1) return regexp.Compile(pattern) From ca374180c959d484c1d61045602845d73922a4be Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Wed, 3 May 2023 12:23:29 -0700 Subject: [PATCH 4/8] Don't escape % when building the regex, since it doesn't get escaped by regexp.QuoteMeta --- go/libraries/doltcore/doltdb/ignore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/libraries/doltcore/doltdb/ignore.go b/go/libraries/doltcore/doltdb/ignore.go index 352424c8c0..0a5ee944a3 100644 --- a/go/libraries/doltcore/doltdb/ignore.go +++ b/go/libraries/doltcore/doltdb/ignore.go @@ -110,7 +110,7 @@ func compilePattern(pattern string) (*regexp.Regexp, error) { pattern = "^" + regexp.QuoteMeta(pattern) + "$" pattern = strings.Replace(pattern, "\\?", ".", -1) pattern = strings.Replace(pattern, "\\*", ".*", -1) - pattern = strings.Replace(pattern, "\\%", ".*", -1) + pattern = strings.Replace(pattern, "%", ".*", -1) return regexp.Compile(pattern) } @@ -123,7 +123,7 @@ func getMoreSpecificPatterns(lessSpecific string) (*regexp.Regexp, error) { pattern = strings.Replace(pattern, "\\?", "[^\\*%]", -1) pattern = strings.Replace(pattern, "\\*", ".*", -1) - pattern = strings.Replace(pattern, "\\%", ".*", -1) + pattern = strings.Replace(pattern, "%", ".*", -1) return regexp.Compile(pattern) } From 1e91d996349b4a39e5ea4efb3d071e4051cdd51d Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Wed, 3 May 2023 12:24:35 -0700 Subject: [PATCH 5/8] Update ignore.bats --- integration-tests/bats/ignore.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/bats/ignore.bats b/integration-tests/bats/ignore.bats index 90a0bc45ce..53c4c05f8f 100644 --- a/integration-tests/bats/ignore.bats +++ b/integration-tests/bats/ignore.bats @@ -12,7 +12,7 @@ INSERT INTO dolt_ignore VALUES ("*_ignore", true), ("do_not_ignore", false), - ("%_also_ignore", true), + ("%_ignore_too", true), ("commit_*", false), ("commit_me_not", true), @@ -87,7 +87,7 @@ SQL dolt sql < Date: Wed, 3 May 2023 13:23:13 -0700 Subject: [PATCH 6/8] Detect equivalent ignore patterns with different values. --- go/libraries/doltcore/doltdb/ignore.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/go/libraries/doltcore/doltdb/ignore.go b/go/libraries/doltcore/doltdb/ignore.go index 0a5ee944a3..ac3d3cacc6 100644 --- a/go/libraries/doltcore/doltdb/ignore.go +++ b/go/libraries/doltcore/doltdb/ignore.go @@ -119,7 +119,7 @@ func compilePattern(pattern string) (*regexp.Regexp, error) { // match pattern B, but not vice versa.) func getMoreSpecificPatterns(lessSpecific string) (*regexp.Regexp, error) { pattern := "^" + regexp.QuoteMeta(lessSpecific) + "$" - // A ? can expand to any character except for a *, since that also has special meaning in patterns. + // A ? can expand to any character except for a * or %, since that also has special meaning in patterns. pattern = strings.Replace(pattern, "\\?", "[^\\*%]", -1) pattern = strings.Replace(pattern, "\\*", ".*", -1) @@ -127,6 +127,21 @@ func getMoreSpecificPatterns(lessSpecific string) (*regexp.Regexp, error) { return regexp.Compile(pattern) } +// normalizePattern generates an equivalent pattern, such that all equivalent patterns have the same normalized pattern. +// It accomplishes this by replacing all * with %, and removing multiple adjacent %. +// This will get a lot harder to implement once we support escaped characters in patterns. +func normalizePattern(pattern string) string { + pattern = strings.Replace(pattern, "*", "%", -1) + for { + newPattern := strings.Replace(pattern, "%%", "%", -1) + if newPattern == pattern { + break + } + pattern = newPattern + } + return pattern +} + func resolveConflictingPatterns(trueMatches, falseMatches []string, tableName string) (IgnoreResult, error) { trueMatchesToRemove := map[string]struct{}{} falseMatchesToRemove := map[string]struct{}{} @@ -136,6 +151,9 @@ func resolveConflictingPatterns(trueMatches, falseMatches []string, tableName st return ErrorOccurred, err } for _, falseMatch := range falseMatches { + if normalizePattern(trueMatch) == normalizePattern(falseMatch) { + return IgnorePatternConflict, DoltIgnoreConflictError{Table: tableName, TruePatterns: []string{trueMatch}, FalsePatterns: []string{falseMatch}} + } if trueMatchRegExp.MatchString(falseMatch) { trueMatchesToRemove[trueMatch] = struct{}{} } From e3806bdd4d4e51815f2e97709228f74ee298a7ce Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Fri, 5 May 2023 11:03:12 -0700 Subject: [PATCH 7/8] Add bats test for detectign equivalent patterns. --- integration-tests/bats/ignore.bats | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/integration-tests/bats/ignore.bats b/integration-tests/bats/ignore.bats index 53c4c05f8f..bcc9e0446d 100644 --- a/integration-tests/bats/ignore.bats +++ b/integration-tests/bats/ignore.bats @@ -379,4 +379,25 @@ SQL echo "$output" [[ "$output" =~ "ignoreme" ]] || false +} + +@test "ignore: detect when equivalent patterns have different values" { + dolt sql < Date: Fri, 5 May 2023 14:03:53 -0700 Subject: [PATCH 8/8] Skip dolt_ignore bats tests on __LD_1__ format. --- integration-tests/bats/ignore.bats | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration-tests/bats/ignore.bats b/integration-tests/bats/ignore.bats index bcc9e0446d..8de7ed91da 100644 --- a/integration-tests/bats/ignore.bats +++ b/integration-tests/bats/ignore.bats @@ -382,6 +382,8 @@ SQL } @test "ignore: detect when equivalent patterns have different values" { + skip_nbf_ld_1 + dolt sql <