3 # object that holds the last X commits on given branch
13 @full_diff_files = nil
16 def initialize(base, from = nil, to = nil)
29 @stats[:total][:files]
34 @stats[:total][:lines]
39 @stats[:total][:deletions]
44 @stats[:total][:insertions]
52 # if file is provided and is writable, it will write the patch into the file
57 alias_method :to_s, :patch
63 @full_diff_files.assoc(key)[1]
68 @full_diff_files.each do |file|
74 attr_accessor :patch, :path, :mode, :src, :dst, :type
77 def initialize(base, hash)
89 @base.object(@src) if @src != '0000000'
91 @base.object(@dst) if @dst != '0000000'
100 @full_diff = @base.lib.diff_full(@from, @to, {:path_limiter => @path})
107 @full_diff_files = process_full_diff
113 @stats = @base.lib.diff_stats(@from, @to, {:path_limiter => @path})
117 # break up @diff_full
118 def process_full_diff
121 @full_diff.split("\n").each do |line|
122 if m = /diff --git a\/(.*?) b\/(.*?)/.match(line)
124 final[current_file] = {:patch => line, :path => current_file,
125 :mode => '', :src => '', :dst => '', :type => 'modified'}
127 if m = /index (.......)\.\.(.......)( ......)*/.match(line)
128 final[current_file][:src] = m[1]
129 final[current_file][:dst] = m[2]
130 final[current_file][:mode] = m[3].strip if m[3]
132 if m = /(.*?) file mode (......)/.match(line)
133 final[current_file][:type] = m[1]
134 final[current_file][:mode] = m[2]
136 final[current_file][:patch] << "\n" + line
139 final.map { |e| [e[0], DiffFile.new(@base, e[1])] }