summaryrefslogtreecommitdiff
path: root/app/helpers/tree_helper.rb
diff options
context:
space:
mode:
authormarmis85 <marmis85@gmail.com>2014-12-31 03:15:04 +0100
committermarmis85 <marmis85@gmail.com>2014-12-31 03:15:04 +0100
commit021cff67f3514b4c2cb1f7b859cbfc314afa0a0c (patch)
tree47253adc2352071bc09754ae12903e1364026c5a /app/helpers/tree_helper.rb
parentac1584249c262e447a6360734597fa17fe077718 (diff)
downloadgitlab-ce-021cff67f3514b4c2cb1f7b859cbfc314afa0a0c.tar.gz
Flatten the directory hierarchy while there is only one directory descendant
Diffstat (limited to 'app/helpers/tree_helper.rb')
-rw-r--r--app/helpers/tree_helper.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index e32aeba5f8f..5a96a208e93 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -113,6 +113,16 @@ module TreeHelper
tree_join(@ref, file)
end
+ # returns the relative path of the first subdir that doesn't have only one directory descendand
+ def flatten_tree(tree)
+ subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path)
+ if subtree.count == 1 && subtree.first.dir?
+ return tree_join(tree.name, flatten_tree(subtree.first))
+ else
+ return tree.name
+ end
+ end
+
def leave_edit_message
"Leave edit mode?\nAll unsaved changes will be lost."
end