Class: MetaCommit::Changelog::Commands::CommitDiffExaminer
- Inherits:
-
Object
- Object
- MetaCommit::Changelog::Commands::CommitDiffExaminer
- Defined in:
- lib/meta_commit/changelog/commands/commit_diff_examiner.rb
Instance Method Summary collapse
-
#initialize(parse_command, ast_path_factory, diff_factory) ⇒ CommitDiffExaminer
constructor
A new instance of CommitDiffExaminer.
-
#meta(repo, left_commit, right_commit) ⇒ Array<MetaCommit::Contracts::Diff>
Creates diff objects with meta information of changes between left and right commit.
Constructor Details
#initialize(parse_command, ast_path_factory, diff_factory) ⇒ CommitDiffExaminer
Returns a new instance of CommitDiffExaminer.
7 8 9 10 11 |
# File 'lib/meta_commit/changelog/commands/commit_diff_examiner.rb', line 7 def initialize(parse_command, ast_path_factory, diff_factory) @parse_command = parse_command @ast_path_factory = ast_path_factory @diff_factory = diff_factory end |
Instance Method Details
#meta(repo, left_commit, right_commit) ⇒ Array<MetaCommit::Contracts::Diff>
Creates diff objects with meta information of changes between left and right commit
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/meta_commit/changelog/commands/commit_diff_examiner.rb', line 19 def (repo, left_commit, right_commit) diffs = [] commit_id_old = left_commit.oid commit_id_new = right_commit.oid repo.diff_with_optimized_lines(left_commit, right_commit) do |old_file_path, new_file_path, patch, line| old_file_content = repo.get_blob_at(commit_id_old, old_file_path, '') new_file_content = repo.get_blob_at(commit_id_new, new_file_path, '') old_file_ast = @parse_command.execute(old_file_path, old_file_content) next if old_file_ast.nil? new_file_ast = @parse_command.execute(new_file_path, new_file_content) next if new_file_ast.nil? column_where_changes_start = line.compute_column(old_file_content, new_file_content) old_file_deleted = (patch.delta.new_file[:oid] == MetaCommit::Git::Repo::FILE_NOT_EXISTS_OID) old_line_number = (old_file_deleted) ? (MetaCommit::Factories::ContextualAstNodeFactory::WHOLE_FILE) : (line.old_lineno) old_contextual_ast = @ast_path_factory.create_contextual_node(old_file_ast, old_line_number) new_file_created = (patch.delta.old_file[:oid] == MetaCommit::Git::Repo::FILE_NOT_EXISTS_OID) new_line_number = (new_file_created) ? (MetaCommit::Factories::ContextualAstNodeFactory::WHOLE_FILE) : (line.new_lineno) new_contextual_ast = @ast_path_factory.create_contextual_node(new_file_ast, new_line_number) created_diff = @diff_factory.create_diff({ :line => line, :column => column_where_changes_start, :commit_id_old => commit_id_old, :commit_id_new => commit_id_new, :old_contextual_ast => old_contextual_ast, :new_contextual_ast => new_contextual_ast, :old_file_path => old_file_path, :new_file_path => new_file_path, }) diffs.push(created_diff) unless created_diff.nil? end diffs end |