Class: Gitlab::Search::FoundBlob
Constant Summary
collapse
- PATH_REGEXP =
/\A(?<ref>[^:]*):(?<path>[^\x00]*)\x00/.freeze
- CONTENT_REGEXP =
/^(?<ref>[^:]*):(?<path>[^\x00]*)\x00(?<startline>\d+)\x00/.freeze
EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, EncodingHelper::ESCAPED_CHARS, EncodingHelper::UNICODE_REPLACEMENT_CHARACTER
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#to_ability_name
#clear_memoization, #strong_memoize, #strong_memoized?
#language_from_gitattributes
#binary_io, #detect_binary?, #detect_encoding, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8, #encode_utf8_no_detect, #encode_utf8_with_replacement_character, #unquote_path
Constructor Details
#initialize(opts = {}) ⇒ FoundBlob
Returns a new instance of FoundBlob.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitlab/search/found_blob.rb', line 23
def initialize(opts = {})
@id = opts.fetch(:id, nil)
@binary_path = opts.fetch(:path, nil)
@binary_basename = opts.fetch(:basename, nil)
@ref = opts.fetch(:ref, nil)
@startline = opts.fetch(:startline, nil)
@highlight_line = opts.fetch(:highlight_line, nil)
@binary_data = opts.fetch(:data, nil)
@per_page = opts.fetch(:per_page, 20)
@project = opts.fetch(:project, nil)
@project_id = opts.fetch(:project_id, nil)
@content_match = opts.fetch(:content_match, nil)
@blob_path = opts.fetch(:blob_path, nil)
@repository = opts.fetch(:repository, nil)
end
|
Instance Attribute Details
#blob_path ⇒ Object
Returns the value of attribute blob_path.
12
13
14
|
# File 'lib/gitlab/search/found_blob.rb', line 12
def blob_path
@blob_path
end
|
#content_match ⇒ Object
Returns the value of attribute content_match.
12
13
14
|
# File 'lib/gitlab/search/found_blob.rb', line 12
def content_match
@content_match
end
|
#highlight_line ⇒ Object
Returns the value of attribute highlight_line.
12
13
14
|
# File 'lib/gitlab/search/found_blob.rb', line 12
def highlight_line
@highlight_line
end
|
#project ⇒ Object
Returns the value of attribute project.
12
13
14
|
# File 'lib/gitlab/search/found_blob.rb', line 12
def project
@project
end
|
Class Method Details
.preload_blobs(blobs) ⇒ Object
17
18
19
20
21
|
# File 'lib/gitlab/search/found_blob.rb', line 17
def self.preload_blobs(blobs)
to_fetch = blobs.select { |blob| blob.is_a?(self) && blob.blob_path }
to_fetch.each { |blob| blob.fetch_blob }
end
|
Instance Method Details
#basename ⇒ Object
67
68
69
|
# File 'lib/gitlab/search/found_blob.rb', line 67
def basename
@basename ||= encode_utf8(@binary_basename || parsed_content[:binary_basename])
end
|
#binary? ⇒ Boolean
83
84
85
|
# File 'lib/gitlab/search/found_blob.rb', line 83
def binary?
false
end
|
#binary_path ⇒ Object
binary_path is used for running filters on all matches. For grepped results (which use content_match), we get the path from the beginning of the grepped result which is faster than parsing the whole snippet
59
60
61
|
# File 'lib/gitlab/search/found_blob.rb', line 59
def binary_path
@binary_path ||= content_match ? search_result_path : parsed_content[:binary_path]
end
|
#data ⇒ Object
71
72
73
|
# File 'lib/gitlab/search/found_blob.rb', line 71
def data
@data ||= encode_utf8(@binary_data || parsed_content[:binary_data])
end
|
#fetch_blob ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/gitlab/search/found_blob.rb', line 87
def fetch_blob
path = [ref, blob_path]
missing_blob = { binary_path: blob_path }
BatchLoader.for(path).batch(default_value: missing_blob) do |refs, loader|
Gitlab::Git::Blob.batch(repository, refs, blob_size_limit: 1024).each do |blob|
data = {
id: blob.id,
binary_path: blob.path,
binary_basename: path_without_extension(blob.path),
ref: ref,
startline: 1,
binary_data: blob.data,
project: project
}
loader.call([ref, blob.path], data)
end
end
end
|
#id ⇒ Object
43
44
45
|
# File 'lib/gitlab/search/found_blob.rb', line 43
def id
@id ||= parsed_content[:id]
end
|
#path ⇒ Object
63
64
65
|
# File 'lib/gitlab/search/found_blob.rb', line 63
def path
@path ||= encode_utf8(@binary_path || parsed_content[:binary_path])
end
|
#present ⇒ Object
79
80
81
|
# File 'lib/gitlab/search/found_blob.rb', line 79
def present
super(presenter_class: BlobPresenter)
end
|
#project_id ⇒ Object
75
76
77
|
# File 'lib/gitlab/search/found_blob.rb', line 75
def project_id
@project_id || @project&.id
end
|
#ref ⇒ Object
47
48
49
|
# File 'lib/gitlab/search/found_blob.rb', line 47
def ref
@ref ||= parsed_content[:ref]
end
|
#startline ⇒ Object
51
52
53
|
# File 'lib/gitlab/search/found_blob.rb', line 51
def startline
@startline ||= parsed_content[:startline]
end
|