class Git::Diff
object that holds the diff between two commits
Attributes
Public Class Methods
Source
# File lib/git/diff.rb, line 11 def initialize(base, from = nil, to = nil) @base = base @from = from && from.to_s @to = to && to.to_s @path = nil @full_diff_files = nil end
Public Instance Methods
Source
# File lib/git/diff.rb, line 31 def [](key) process_full @full_diff_files.assoc(key)[1] end
Source
# File lib/git/diff.rb, line 62 def deletions Git::Deprecation.warn("Git::Diff#deletions is deprecated. Use Git::Base#diff_stats(...).deletions instead.") stats_provider.deletions end
Source
# File lib/git/diff.rb, line 36 def each(&block) process_full @full_diff_files.map { |file| file[1] }.each(&block) end
Source
# File lib/git/diff.rb, line 67 def insertions Git::Deprecation.warn("Git::Diff#insertions is deprecated. Use Git::Base#diff_stats(...).insertions instead.") stats_provider.insertions end
Source
# File lib/git/diff.rb, line 57 def lines Git::Deprecation.warn("Git::Diff#lines is deprecated. Use Git::Base#diff_stats(...).lines instead.") stats_provider.lines end
Source
# File lib/git/diff.rb, line 45 def name_status Git::Deprecation.warn("Git::Diff#name_status is deprecated. Use Git::Base#diff_path_status instead.") path_status_provider.to_h end
DEPRECATED METHODS
Source
# File lib/git/diff.rb, line 26 def patch @base.lib.diff_full(@from, @to, { path_limiter: @path }) end
Also aliased as: to_s
Source
# File lib/git/diff.rb, line 50 def size Git::Deprecation.warn("Git::Diff#size is deprecated. Use Git::Base#diff_stats(...).total[:files] instead.") stats_provider.total[:files] end
Source
# File lib/git/diff.rb, line 72 def stats Git::Deprecation.warn("Git::Diff#stats is deprecated. Use Git::Base#diff_stats instead.") # CORRECTED: Re-create the original hash structure for backward compatibility { files: stats_provider.files, total: stats_provider.total } end
Private Instance Methods
Source
# File lib/git/diff.rb, line 118 def path_status_provider @path_status_provider ||= Git::DiffPathStatus.new(@base, @from, @to, @path) end
CORRECTED: Pass the @path variable to the new objects
Source
# File lib/git/diff.rb, line 112 def process_full return if @full_diff_files @full_diff_files = process_full_diff end
Source
# File lib/git/diff.rb, line 127 def process_full_diff defaults = { mode: '', src: '', dst: '', type: 'modified' } final = {} current_file = nil patch.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
Source
# File lib/git/diff.rb, line 123 def stats_provider @stats_provider ||= Git::DiffStats.new(@base, @from, @to, @path) end
CORRECTED: Pass the @path variable to the new objects