Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-11-15 15:15:43 +0300
committerDouwe Maan <douwe@gitlab.com>2016-11-15 15:15:43 +0300
commitb3616e3074202d63a4ed03bbe94b14a4488c7800 (patch)
tree0492ad9e4b09c6a5eee90a821588a7563408b9a1 /app
parent374b8e95c38833d6aeee491b077bd43c023c0686 (diff)
parent5c966f70fb218d6f4de0f888733604293f36c33e (diff)
Merge branch 'master-recursiveTree' into 'master'
Issue #4270: Recursive option for files through API ## What does this MR do? - Adds recursive param to tree API request. With this param we can get all repository paths in a single request. - Related [old github pull request](https://github.com/gitlabhq/gitlabhq/pull/9311) ## Are there points in the code the reviewer needs to double check? ## Why was this MR needed? Requested in #4270 ## Screenshots (if relevant) ## Does this MR meet the acceptance criteria? - [X] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [X] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md) - [X] API support added - Tests - [X] Added for this feature/bug - [x] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) ## What are the relevant issue numbers? Requested in #4270 See merge request !6088
Diffstat (limited to 'app')
-rw-r--r--app/models/repository.rb4
-rw-r--r--app/models/tree.rb22
2 files changed, 22 insertions, 4 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 063dc74021d..4282197faa5 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -631,7 +631,7 @@ class Repository
@head_tree ||= Tree.new(self, head_commit.sha, nil)
end
- def tree(sha = :head, path = nil)
+ def tree(sha = :head, path = nil, recursive: false)
if sha == :head
if path.nil?
return head_tree
@@ -640,7 +640,7 @@ class Repository
end
end
- Tree.new(self, sha, path)
+ Tree.new(self, sha, path, recursive: recursive)
end
def blob_at_branch(branch_name, path)
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 7c4ed6e393b..2d1d68dbd81 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -3,15 +3,16 @@ class Tree
attr_accessor :repository, :sha, :path, :entries
- def initialize(repository, sha, path = '/')
+ def initialize(repository, sha, path = '/', recursive: false)
path = '/' if path.blank?
@repository = repository
@sha = sha
@path = path
+ @recursive = recursive
git_repo = @repository.raw_repository
- @entries = Gitlab::Git::Tree.where(git_repo, @sha, @path)
+ @entries = get_entries(git_repo, @sha, @path, recursive: @recursive)
end
def readme
@@ -58,4 +59,21 @@ class Tree
def sorted_entries
trees + blobs + submodules
end
+
+ private
+
+ def get_entries(git_repo, sha, path, recursive: false)
+ current_path_entries = Gitlab::Git::Tree.where(git_repo, sha, path)
+ ordered_entries = []
+
+ current_path_entries.each do |entry|
+ ordered_entries << entry
+
+ if recursive && entry.dir?
+ ordered_entries.concat(get_entries(git_repo, sha, entry.path, recursive: true))
+ end
+ end
+
+ ordered_entries
+ end
end