OSDN Git Service

scm: git: override adapter entry() for browsing tree performance (#7047).
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 4 May 2011 18:07:50 +0000 (18:07 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 4 May 2011 18:07:50 +0000 (18:07 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5640 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/scm/adapters/git_adapter.rb

index 592a181..68fbfd6 100644 (file)
@@ -106,6 +106,20 @@ module Redmine
           bras.include?('master') ? 'master' : bras.first
         end
 
+        def entry(path=nil, identifier=nil)
+          parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
+          search_path = parts[0..-2].join('/')
+          search_name = parts[-1]
+          if search_path.blank? && search_name.blank?
+            # Root entry
+            Entry.new(:path => '', :kind => 'dir')
+          else
+            # Search for the entry in the parent directory
+            es = entries(search_path, identifier)
+            es ? es.detect {|e| e.name == search_name} : nil
+          end
+        end
+
         def entries(path=nil, identifier=nil, options={})
           entries_git(path, identifier, options)
         end