class Git::Diff
object that holds the last X commits on given branch
Attributes
Public Class Methods
Source
# File lib/git/diff.rb, line 7 def initialize(base, from = nil, to = nil) @base = base @from = from && from.to_s @to = to && to.to_s @path = nil @full_diff = nil @full_diff_files = nil @stats = nil end
Public Instance Methods
Source
# File lib/git/diff.rb, line 62 def [](key) process_full @full_diff_files.assoc(key)[1] end
enumerable methods
Source
# File lib/git/diff.rb, line 38 def deletions cache_stats @stats[:total][:deletions] end
Source
# File lib/git/diff.rb, line 67 def each(&block) # :yields: each Git::DiffFile in turn process_full @full_diff_files.map { |file| file[1] }.each(&block) end
Source
# File lib/git/diff.rb, line 43 def insertions cache_stats @stats[:total][:insertions] end
Source
# File lib/git/diff.rb, line 54 def patch(file = nil) cache_full @full_diff end
if file is provided and is writable, it will write the patch into the file
Also aliased as: to_s
Private Instance Methods
Source
# File lib/git/diff.rb, line 103 def cache_full @full_diff ||= @base.lib.diff_full(@from, @to, {:path_limiter => @path}) end
Source
# File lib/git/diff.rb, line 117 def cache_name_status @name_status ||= @base.lib.diff_name_status(@from, @to, {:path => @path}) end
Source
# File lib/git/diff.rb, line 113 def cache_stats @stats ||= @base.lib.diff_stats(@from, @to, {:path_limiter => @path}) end
Source
# File lib/git/diff.rb, line 107 def process_full return if @full_diff_files cache_full @full_diff_files = process_full_diff end
Source
# File lib/git/diff.rb, line 122 def process_full_diff defaults = { :mode => '', :src => '', :dst => '', :type => 'modified' } final = {} current_file = nil @full_diff.split("\n").each do |line| if m = %r{\Adiff --git ("?)a/(.+?)\1 ("?)b/(.+?)\3\z}.match(line) current_file = Git::EscapedPath.new(m[2]).unescape final[current_file] = defaults.merge({:patch => line, :path => current_file}) else if m = /^index ([0-9a-f]{4,40})\.\.([0-9a-f]{4,40})( ......)*/.match(line) final[current_file][:src] = m[1] final[current_file][:dst] = m[2] final[current_file][:mode] = m[3].strip if m[3] end if m = /^([[:alpha:]]*?) file mode (......)/.match(line) final[current_file][:type] = m[1] final[current_file][:mode] = m[2] end if m = /^Binary files /.match(line) final[current_file][:binary] = true end final[current_file][:patch] << "\n" + line end end final.map { |e| [e[0], DiffFile.new(@base, e[1])] } end
break up @diff_full