Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2018-05-18 06:10:51 +0300
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2018-05-18 12:02:19 +0300
commit08efed6273d689cc8dc821303f12cc0c47764a10 (patch)
treea6f370806dbe3711efd53239ec66de9d7401f01c
parent3d4aba8d0999541c16b4a90833bf613252e2ba43 (diff)
Fix bug in SearchFilesByContent, don't drop last match
-rw-r--r--changelogs/unreleased/fix-search-files-by-content-buf.yml5
-rw-r--r--internal/service/repository/search_files.go9
-rw-r--r--internal/service/repository/search_files_test.go24
3 files changed, 34 insertions, 4 deletions
diff --git a/changelogs/unreleased/fix-search-files-by-content-buf.yml b/changelogs/unreleased/fix-search-files-by-content-buf.yml
new file mode 100644
index 000000000..615184528
--- /dev/null
+++ b/changelogs/unreleased/fix-search-files-by-content-buf.yml
@@ -0,0 +1,5 @@
+---
+title: Fix matching bug in SearchFilesByContent
+merge_request: 722
+author:
+type: fixed
diff --git a/internal/service/repository/search_files.go b/internal/service/repository/search_files.go
index 479ccff78..35ab1cb42 100644
--- a/internal/service/repository/search_files.go
+++ b/internal/service/repository/search_files.go
@@ -57,7 +57,7 @@ func (s *server) SearchFilesByContent(req *pb.SearchFilesByContentRequest, strea
buf = append(buf, obj...)
}
}
- if len(matches) > 1 {
+ if len(matches) > 0 {
err = stream.Send(&pb.SearchFilesByContentResponse{Matches: matches})
matches = nil
return err
@@ -69,8 +69,11 @@ func (s *server) SearchFilesByContent(req *pb.SearchFilesByContentRequest, strea
if err != nil {
return helper.DecorateError(codes.Internal, err)
}
- if len(buf) > 1 {
- return stream.Send(&pb.SearchFilesByContentResponse{Matches: [][]byte{buf}})
+ if len(buf) > 0 {
+ matches = append(matches, buf)
+ }
+ if len(matches) > 0 {
+ return stream.Send(&pb.SearchFilesByContentResponse{Matches: matches})
}
return nil
}
diff --git a/internal/service/repository/search_files_test.go b/internal/service/repository/search_files_test.go
index 042b929cb..2679e4715 100644
--- a/internal/service/repository/search_files_test.go
+++ b/internal/service/repository/search_files_test.go
@@ -54,6 +54,22 @@ var (
[]byte(""),
}, []byte{'\n'}),
}
+ contentCoffeeLines = [][]byte{
+ bytes.Join([][]byte{
+ []byte("many_files:CONTRIBUTING.md\x0092\x001. [Ruby style guide](https://github.com/bbatsov/ruby-style-guide)"),
+ []byte("many_files:CONTRIBUTING.md\x0093\x001. [Rails style guide](https://github.com/bbatsov/rails-style-guide)"),
+ []byte("many_files:CONTRIBUTING.md\x0094\x001. [CoffeeScript style guide](https://github.com/polarmobile/coffeescript-style-guide)"),
+ []byte("many_files:CONTRIBUTING.md\x0095\x001. [Shell command guidelines](doc/development/shell_commands.md)"),
+ []byte(""),
+ }, []byte{'\n'}),
+ bytes.Join([][]byte{
+ []byte("many_files:files/js/application.js\x001\x00// This is a manifest file that'll be compiled into including all the files listed below."),
+ []byte("many_files:files/js/application.js\x002\x00// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically"),
+ []byte("many_files:files/js/application.js\x003\x00// be included in the compiled file accessible from http://example.com/assets/application.js"),
+ []byte("many_files:files/js/application.js\x004\x00// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the"),
+ []byte(""),
+ }, []byte{'\n'}),
+ }
)
func TestSearchFilesByContentSuccessful(t *testing.T) {
@@ -82,11 +98,17 @@ func TestSearchFilesByContentSuccessful(t *testing.T) {
output: contentOutputLines,
},
{
- desc: "multi file in many_files",
+ desc: "single files, multiple matches",
query: "backup",
ref: "many_files",
output: contentMultiLines,
},
+ {
+ desc: "multiple files, multiple matches",
+ query: "coffee",
+ ref: "many_files",
+ output: contentCoffeeLines,
+ },
}
for _, tc := range testCases {