Class: Repositories::TreeFinder

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

Constant Summary collapse

CommitMissingError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TreeFinder.


9
10
11
12
13
# File 'app/finders/repositories/tree_finder.rb', line 9

def initialize(user_project, params = {})
  super(user_project.repository, params)

  @user_project = user_project
end

Instance Attribute Details

#user_projectObject (readonly)

Returns the value of attribute user_project.


5
6
7
# File 'app/finders/repositories/tree_finder.rb', line 5

def user_project
  @user_project
end

Instance Method Details

#commit_exists?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'app/finders/repositories/tree_finder.rb', line 32

def commit_exists?
  commit.present?
end

#execute(gitaly_pagination: false) ⇒ Object

Raises:


15
16
17
18
19
20
21
22
23
# File 'app/finders/repositories/tree_finder.rb', line 15

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

  request_params = { recursive: recursive }
  request_params[:pagination_params] = pagination_params if gitaly_pagination
  tree = user_project.repository.tree(commit.id, path, **request_params)

  tree.sorted_entries
end

#totalObject


25
26
27
28
29
30
# File 'app/finders/repositories/tree_finder.rb', line 25

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