# Tested by: ../test/subversion_extensions_test.rb require_gem 'colored' require 'colored' class Array def to_regexp_char_class "[#{join('')}]" end end class String def colorize_svn_status_lines if Subversion.color self.gsub(/^ *\?/) { $&.yellow.bold}. gsub(/^ *A/) { $&.green.bold}. gsub(/^ *M/) { $&.green.bold}. gsub(/^ *D/) { $&.magenta.bold}. gsub(/^ *C/) { $&.red.bold}. gsub(/^ *~/) { $&.red.bold}. gsub(/^ *!/) { $&.red.bold} else self end end end # These are methods used by the SvnCommand for filtering and whatever else it needs... # It could probably be moved into SvnCommand, but I thought it might be good to at least make it *possible* to use them apart from SvnCommand. # Rename to Subversion::Filters ? Then would each_unadded fit? module Subversion module Extensions Interesting_status_flags = ["M", "A", "D", "?"] Uninteresting_status_flags = ["X", "W"] Status_flags = Interesting_status_flags | Uninteresting_status_flags def self.status_lines_filter(input) input = (input || "").reject { |line| line =~ /^$/ # Blank lines }.reject { |line| line =~ /^#{Uninteresting_status_flags.to_regexp_char_class}/ }.join before_externals, *externals = input.split(/^Performing status on external item at.*$/) before_externals ||= '' before_externals = before_externals.strip.colorize_svn_status_lines + "\n" if before_externals != "" externals = externals.join.strip externals = '_'*40 + ' externals '.underline + '_'*40 + "\n" + externals.reject { |line| line =~ /^Performing status on external item at/ }.reject { |line| line =~ /^$/ # Blank lines }.join.strip.colorize_svn_status_lines + "\n" if externals != "" before_externals + externals end def self.update_lines_filter(input) input.reject { |line| line =~ /^$/ # Blank lines }.reject { |line| line =~ /^Fetching external item into/ # Eventually we may want it to include this whole block, but only iff there is something updated for this external. }.reject { |line| line =~ /^External at revision/ }.join # Also get rid of all but one "At revision _."? end def self.unadded_lines_filter(input) input.select { |line| line =~ /^\?/ }.join end def self.unadded_filter(input) unadded_lines_filter(input).map { |line| # Just keep the filename part line =~ /^\?\s+(.+)/ $1 } end def self.each_unadded(input) unadded_filter(input).each { |line| yield line } end end end