diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 22:00:14 +0300 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/models/repository.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r-- | app/models/repository.rb | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 90e87de4a5b..cedfed16b20 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -189,6 +189,8 @@ class Repository return [] end + query = Feature.enabled?(:commit_search_trailing_spaces) ? query.strip : query + commits = raw_repository.find_commits_by_message(query, ref, path, limit, offset).map do |c| commit(c) end @@ -631,7 +633,11 @@ class Repository end def readme_path - head_tree&.readme_path + if Feature.enabled?(:readme_from_gitaly) + readme_path_gitaly + else + head_tree&.readme_path + end end cache_method :readme_path @@ -1239,6 +1245,29 @@ class Repository container.full_path, container: container) end + + def readme_path_gitaly + return if empty? || root_ref.nil? + + # (?i) to enable case-insensitive mode + # + # Note: `Gitlab::FileDetector::PATTERNS[:readme]#to_s` won't work because of + # incompatibility of regex engines between Rails and Gitaly. + regex = "(?i)#{Gitlab::FileDetector::PATTERNS[:readme].source}" + + readmes = search_files_by_regexp(regex, root_ref) + + choose_readme_to_display(readmes) + end + + # Extracted from Tree#readme_path + def choose_readme_to_display(readmes) + previewable_readme = readmes.find { |name| Gitlab::MarkupHelper.previewable?(name) } + + return previewable_readme if previewable_readme + + readmes.find { |name| Gitlab::MarkupHelper.plain?(name) } + end end Repository.prepend_mod_with('Repository') |