summaryrefslogtreecommitdiff
path: root/app/models/repository.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r--app/models/repository.rb80
1 files changed, 51 insertions, 29 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index c767d1051d1..807b33b2a3e 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -94,18 +94,6 @@ class Repository
gitlab_shell.rm_tag(path_with_namespace, tag_name)
end
- def round_commit_count
- if commit_count > 10000
- '10000+'
- elsif commit_count > 5000
- '5000+'
- elsif commit_count > 1000
- '1000+'
- else
- commit_count
- end
- end
-
def branch_names
cache.fetch(:branch_names) { raw_repository.branch_names }
end
@@ -130,28 +118,29 @@ class Repository
cache.fetch(:size) { raw_repository.size }
end
+ def cache_keys
+ %i(size branch_names tag_names commit_count
+ readme version contribution_guide changelog license)
+ end
+
+ def build_cache
+ cache_keys.each do |key|
+ unless cache.exist?(key)
+ send(key)
+ end
+ end
+ end
+
def expire_cache
- %i(size branch_names tag_names commit_count graph_log
- readme version contribution_guide changelog license).each do |key|
+ cache_keys.each do |key|
cache.expire(key)
end
end
- def graph_log
- cache.fetch(:graph_log) do
- commits = raw_repository.log(limit: 6000, skip_merges: true,
- ref: root_ref)
-
- commits.map do |rugged_commit|
- commit = Gitlab::Git::Commit.new(rugged_commit)
-
- {
- author_name: commit.author_name,
- author_email: commit.author_email,
- additions: commit.stats.additions,
- deletions: commit.stats.deletions,
- }
- end
+ def rebuild_cache
+ cache_keys.each do |key|
+ cache.expire(key)
+ send(key)
end
end
@@ -431,6 +420,39 @@ class Repository
end
end
+ def search_files(query, ref)
+ offset = 2
+ args = %W(git grep -i -n --before-context #{offset} --after-context #{offset} #{query} #{ref || root_ref})
+ Gitlab::Popen.popen(args, path_to_repo).first.scrub.split(/^--$/)
+ end
+
+ def parse_search_result(result)
+ ref = nil
+ filename = nil
+ startline = 0
+
+ result.each_line.each_with_index do |line, index|
+ if line =~ /^.*:.*:\d+:/
+ ref, filename, startline = line.split(':')
+ startline = startline.to_i - index
+ break
+ end
+ end
+
+ data = ""
+
+ result.each_line do |line|
+ data << line.sub(ref, '').sub(filename, '').sub(/^:-\d+-/, '').sub(/^::\d+:/, '')
+ end
+
+ OpenStruct.new(
+ filename: filename,
+ ref: ref,
+ startline: startline,
+ data: data
+ )
+ end
+
private
def cache