public
Description: Vault
Homepage: http://peervoice.com/software/vault
Clone URL: git://github.com/ddollar/vault.git
Search Repo:
ddollar (author)
Sat Apr 12 22:40:57 -0700 2008
commit  b440b9039dc16555f89a973acaf7d386bf49c062
tree    a2ab62bf89208fbfa47be0e4360c5037975e922b
parent  6298664d50699b35005d5f88c3b9fbc52aa392f7
vault / app / models / engines / git.rb
100644 74 lines (59 sloc) 1.701 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'grit'
require 'grit/repo'
 
module Engines
 
  class Git
    
    def open(path)
      @engine = Grit::Repo.new(path)
    end
    
    def latest_revision_id
      @engine.commits.first.id_abbrev
    end
    
    def revisions
      @engine.commits.map do |commit|
        Revision.new(commit.id_abbrev)
      end
    end
 
    def node(revision_id, path, load_children=true)
      commit = @engine.commits(revision_id).first
      tree = commit.tree
      
      if path != ''
        tree = tree / path
        # path.split('/').each do |subdir|
        # tree = tree / subdir
        # end
      end
      
      lastcommit = @engine.log('master', path).first
      
      node = Node.new
      node.fullname = path
      node.name = File.basename(path)
      node.file_revision = lastcommit.id_abbrev
      node.is_directory = tree.is_a?(Grit::Tree)
      node.author = lastcommit.author.name
      node.date = lastcommit.authored_date
      node.log = lastcommit.message
      
      if node.is_directory
        node.size = -1
        node.contents = ''
        if load_children
          node.children = tree.contents.map do |child|
            node(revision_id,
                 path == '' ? child.name : File.join(path, child.name),
                 false)
          end
        else
          node.children = []
        end
      else
        node.size = tree.size
        
        # hack to make this faster, only load contents of 'parent' node
        if load_children
          node.contents = tree.data
        else
          node.contents = ''
        end
        
        node.children = []
      end
 
      node
    end
 
  end
 
end