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
|
# File 'lib/git-object-browser/models/directory.rb', line 13
def read_entries
entries = []
Dir.chdir(File.join(@root, @path)) do
files = Dir.glob("*")
files.each do |file|
relpath = File.join(@path, file).gsub(%r{\A/}, '')
entry = {}
if File.directory?(file)
entry[:type] = 'directory'
elsif File.symlink?(file)
entry[:type] = 'symlink'
elsif Ref::path?(relpath)
entry[:type] = 'ref'
elsif Reflog::path?(relpath)
entry[:type] = 'reflog'
elsif InfoRefs::path?(relpath)
entry[:type] = 'info_refs'
elsif PackedRefs::path?(relpath)
entry[:type] = 'packed_refs'
elsif Index::path?(relpath)
entry[:type] = 'index'
elsif GitObject::path?(relpath)
entry[:type] = 'object'
else
entry[:type] = "file"
end
entry[:basename] = file
entry[:mtime] = File.mtime(file).to_i
entry[:size] = File.size(file)
entries << entry
end
end
order = %w{directory ref reflog info_refs packed_refs index object file symlink}
entries.sort do |a,b|
(order.index(a[:type]) <=> order.index(b[:type])).nonzero? ||
a[:basename] <=> b[:basename]
end
end
|