[LrdeTools] 250: Objectify status entries.

https://svn.lrde.epita.fr/svn/lrdetools/trunk Index: ChangeLog from Nicolas Pouillard <ertai@lrde.epita.fr> Objectify status entries. * vcs/lib/vcs/status.rb: Add StatusEntry and adapt. * vcs/lib/vcs/changelog.rb, vcs/lib/vcs/diff.rb: Adapt to StatusEntry. changelog.rb | 10 +++---- diff.rb | 10 +++---- status.rb | 83 ++++++++++++++++++++++++++++++++++------------------------- 3 files changed, 59 insertions(+), 44 deletions(-) Index: vcs/lib/vcs/changelog.rb --- vcs/lib/vcs/changelog.rb (revision 249) +++ vcs/lib/vcs/changelog.rb (working copy) @@ -22,12 +22,12 @@ def mk_log_entry_contents ( *args ) return @@entries[args] if @@entries.has_key? args @@entries[args] = result = [] - from_status(*args) do |line, file_st, prop_st, copy_st, file| - next if file_st.chr =~ /[?X\\,+]/ - next if file.to_s == 'ChangeLog' - ls = [@@file_st[file_st], @@prop_st[prop_st]].compact! + status(*args) do |se| + next if se.file_st.chr =~ /[?X\\,+]/ + next if se.file.to_s == 'ChangeLog' + ls = [@@file_st[se.file_st], @@prop_st[se.prop_st]].compact! ls.first.capitalize! unless ls.empty? - result << [file, ls.join(', ')] + result << [se.file, ls.join(', ')] end raise Failure, 'No changes, so no ChangeLog entry.' if result.empty? result Index: vcs/lib/vcs/diff.rb --- vcs/lib/vcs/diff.rb (revision 249) +++ vcs/lib/vcs/diff.rb (working copy) @@ -24,11 +24,11 @@ # A diff only for your eyes def diffw! ( files_orig=[], options={} ) files = Set.new - from_status(files_orig) do |line, file_st, prop_st, cpy, file| - next if file_st.chr =~ /[?X\\,+D]/ - next if file.to_s == 'ChangeLog' - next if file.directory? - files << file + status(files_orig) do |se| + next if se.file_st.chr =~ /[?X\\,+D]/ + next if se.file.to_s == 'ChangeLog' + next if se.file.directory? + files << se.file end return if files.empty? and not files_orig.empty? diff_! files.to_a, options.merge(:diff_cmd => 'diff', :extensions => '-NPbuw') Index: vcs/lib/vcs/status.rb --- vcs/lib/vcs/status.rb (revision 249) +++ vcs/lib/vcs/status.rb (working copy) @@ -7,47 +7,34 @@ class Svn - @@category_symbol = - { - :precious => ?+, - :unmask => ?\\, - :junk => ?, - } + class StatusEntry + attr_accessor :line, :file_st, :prop_st, :cpy, :file, :category - def from_status ( *args, &block ) - status_(*args).each_line do |line| - next unless line =~ /^.{5} / - m = /^(.)(.)(.)(.)(.\s*)(.*)$/.match(line) + def initialize ( high_line, aString ) + @high_line = high_line + m = /^(.)(.)(.)(.)(.\s*)(.*)$/.match(aString) line, file_st, bl1, prop_st, cpy, bl2, file = m.to_a - file = file.to_path - file_st, prop_st, cpy = file_st[0], prop_st[0], cpy[0] - if file_st == ?? - category = Vcs.classify(file) - next if category == :exclude - file_st = @@category_symbol[category] || file_st - end - line = "#{file_st.chr}#{bl1}#{prop_st.chr}#{cpy.chr}#{bl2}#{file}" - block[line, file_st, prop_st, cpy, file] + @file = file.to_path + @file_st, @prop_st, @cpy = file_st[0], prop_st[0], cpy[0] + if @file_st == ?? + @category = Vcs.classify(@file) + @file_st = @@category_symbol[@category] || @file_st + else + @category = :normal end + @line = "#{@file_st.chr}#{bl1}#{prop_st}#{cpy}#{bl2}#{file}" end - protected :from_status - def color_status! ( *args ) - from_status(*args) do |line, file_st, prop_st, cpy, file| - line[0] = @h.color(file_st.chr, *@@style[file_st]) - puts line - end + def colorize! + @line[0] = @high_line.color(@file_st.chr, *@@style[@file_st]) end - def status! ( *args ) - if color? - color_status!(*args) - else - from_status(*args) do |line, file_st, prop_st, cpy, file| - puts line - end - end - end + @@category_symbol ||= + { + :precious => ?+, + :unmask => ?\\, + :junk => ?, + } @@style ||= { @@ -64,5 +51,33 @@ ?? => [:BLINK, :RED], ?C => [:BLINK, :RED], } + end # class StatusEntry + + def status ( *args, &block ) + return status_(*args) if block.nil? + status_(*args).each_line do |line| + next unless line =~ /^.{5} / + status_entry = StatusEntry.new(@h, line) + next if status_entry.category == :exclude + block[status_entry] + end + end + + def color_status! ( *args ) + status(*args) do |status_entry| + status_entry.colorize! + puts status_entry.line + end + end + + def status! ( *args ) + if color? + color_status!(*args) + else + status(*args) do |status_entry| + puts status_entry.line + end + end + end end # class Svn
participants (1)
-
Nicolas Pouillard