44module GitMedia
55 module Status
66
7- def self . run!
7+ def self . run! ( opts )
88 @push = GitMedia . get_push_transport
99 r = self . find_references
10- self . print_references ( r )
10+ self . print_references ( r , opts [ :short ] )
1111 r = self . local_cache_status
12- self . print_cache_status ( r )
12+ self . print_cache_status ( r , opts [ :short ] )
1313 end
1414
1515 # find tree entries that are likely media references
@@ -19,7 +19,9 @@ def self.find_references
1919 files = files . map { |f | s = f . split ( "\t " ) ; [ s [ 0 ] . split ( ' ' ) . last , s [ 1 ] ] }
2020 files = files . select { |f | f [ 0 ] == '41' } # it's the right size
2121 files . each do |tree_size , fname |
22- if size = File . size? ( fname )
22+ if File . exists? ( fname )
23+ size = File . size ( fname )
24+
2325 # Windows newlines can offset file size by 1
2426 if size == tree_size . to_i or size == tree_size . to_i + 1
2527 # TODO: read in the data and verify that it's a sha + newline
@@ -39,49 +41,70 @@ def self.find_references
3941 references
4042 end
4143
42- def self . print_references ( refs )
44+ def self . print_references ( refs , short = false )
45+
4346 if refs [ :to_expand ] . size > 0
4447 puts "== Unexpanded Media =="
45- refs [ :to_expand ] . each do |file , sha |
46- puts " " + sha [ 0 , 8 ] + " " + file
48+ if short
49+ puts "Count: " + refs [ :to_expand ] . size . to_s
50+ else
51+ refs [ :to_expand ] . each do |file , sha |
52+ puts " " + sha [ 0 , 8 ] + " " + file
53+ end
54+ puts
4755 end
48- puts
4956 end
5057 if refs [ :expanded ] . size > 0
5158 puts "== Expanded Media =="
52- refs [ :expanded ] . each do |file |
53- size = File . size ( file )
54- puts " " + "(#{ self . to_human ( size ) } )" . ljust ( 8 ) + " #{ file } "
59+ if short
60+ puts "Count: " + refs [ :expanded ] . size . to_s
61+ else
62+ refs [ :expanded ] . each do |file |
63+ size = File . size ( file )
64+ puts " " + "(#{ self . to_human ( size ) } )" . ljust ( 8 ) + " #{ file } "
65+ end
66+ puts
5567 end
56- puts
5768 end
5869 if refs [ :deleted ] . size > 0
5970 puts "== Deleted Media =="
60- refs [ :deleted ] . each do |file |
61- puts " " + " #{ file } "
71+ if short
72+ puts "Count: " + refs [ :deleted ] . size . to_s
73+ else
74+ refs [ :deleted ] . each do |file |
75+ puts " " + " #{ file } "
76+ end
77+ puts
6278 end
63- puts
6479 end
6580 end
6681
67- def self . print_cache_status ( refs )
82+ def self . print_cache_status ( refs , short )
6883 if refs [ :unpushed ] . size > 0
6984 puts "== Unpushed Media =="
70- refs [ :unpushed ] . each do |sha |
71- cache_file = GitMedia . media_path ( sha )
72- size = File . size ( cache_file )
73- puts " " + "(#{ self . to_human ( size ) } )" . ljust ( 8 ) + ' ' + sha [ 0 , 8 ]
85+ if short
86+ puts "Count: " + refs [ :unpushed ] . size . to_s
87+ else
88+ refs [ :unpushed ] . each do |sha |
89+ cache_file = GitMedia . media_path ( sha )
90+ size = File . size ( cache_file )
91+ puts " " + "(#{ self . to_human ( size ) } )" . ljust ( 8 ) + ' ' + sha [ 0 , 8 ]
92+ end
93+ puts
7494 end
75- puts
7695 end
7796 if refs [ :pushed ] . size > 0
7897 puts "== Already Pushed Media =="
79- refs [ :pushed ] . each do |sha |
80- cache_file = GitMedia . media_path ( sha )
81- size = File . size ( cache_file )
82- puts " " + "(#{ self . to_human ( size ) } )" . ljust ( 8 ) + ' ' + sha [ 0 , 8 ]
98+ if short
99+ puts "Count: " + refs [ :pushed ] . size . to_s
100+ else
101+ refs [ :pushed ] . each do |sha |
102+ cache_file = GitMedia . media_path ( sha )
103+ size = File . size ( cache_file )
104+ puts " " + "(#{ self . to_human ( size ) } )" . ljust ( 8 ) + ' ' + sha [ 0 , 8 ]
105+ end
106+ puts
83107 end
84- puts
85108 end
86109 end
87110
0 commit comments