Class: Repositories::TreeFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/repositories/tree_finder.rb

Constant Summary collapse

CommitMissingError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(project, params = {}) ⇒ TreeFinder

Returns a new instance of TreeFinder.



7
8
9
10
11
# File 'app/finders/repositories/tree_finder.rb', line 7

def initialize(project, params = {})
  @project = project
  @repository = project.repository
  @params = params
end

Instance Method Details

#commit_exists?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/finders/repositories/tree_finder.rb', line 30

def commit_exists?
  commit.present?
end

#execute(gitaly_pagination: false) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
# File 'app/finders/repositories/tree_finder.rb', line 13

def execute(gitaly_pagination: false)
  raise CommitMissingError unless commit_exists?

  request_params = { recursive: recursive, rescue_not_found: rescue_not_found }
  request_params[:pagination_params] = pagination_params if gitaly_pagination

  repository.tree(commit.id, path, **request_params).sorted_entries
end

#totalObject



22
23
24
25
26
27
28
# File 'app/finders/repositories/tree_finder.rb', line 22

def total
  # This is inefficient and we'll look at replacing this implementation
  cache_key = [project, repository.commit, :tree_size, commit.id, path, recursive]
  Gitlab::Cache.fetch_once(cache_key) do
    repository.tree(commit.id, path, recursive: recursive).entries.size
  end
end