Module: Git::Parsers::Diff::Patch Private
- Defined in:
- lib/git/parsers/diff.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Parser for --patch output (combined with numstat)
Defined Under Namespace
Modules: PatchMetadataParser Classes: PatchFileParser
Constant Summary collapse
- DIFF_HEADER_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Header line pattern for each patch file section
%r{\Adiff --git ("?)a/(.+?)\1 ("?)b/(.+?)\3\z}- INDEX_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Index line pattern with source/destination SHAs and optional mode
/^index ([0-9a-f]{4,40})\.\.([0-9a-f]{4,40})( ......)?/- FILE_MODE_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
File mode line pattern for file creation and deletion
/^(new|deleted) file mode (......)/- OLD_MODE_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Old mode line pattern for mode changes
/^old mode (......)/- NEW_MODE_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
New mode line pattern for mode changes
/^new mode (......)/- BINARY_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Binary patch marker line pattern
/^Binary files /- GIT_BINARY_PATCH_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Git binary patch header line pattern
/^GIT binary patch$/- RENAME_FROM_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Rename source path line pattern
/^rename from (.+)$/- RENAME_TO_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Rename destination path line pattern
/^rename to (.+)$/- COPY_FROM_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Copy source path line pattern
/^copy from (.+)$/- COPY_TO_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Copy destination path line pattern
/^copy to (.+)$/- SIMILARITY_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Similarity percentage line pattern
/^similarity index (\d+)%$/- PATCH_STATUS_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps patch metadata status words to diff status symbols
{ 'new' => :added, 'deleted' => :deleted, 'modified' => :modified, 'renamed' => :renamed, 'copied' => :copied, 'type_changed' => :type_changed }.freeze
Class Method Summary collapse
-
.parse(output, include_dirstat: false) ⇒ Git::DiffResult
private
Parse combined patch + numstat + shortstat output into DiffResult.
-
.split_pre_diff(pre_diff_lines, include_dirstat, patch_text) ⇒ Array(Array<String>, (String, nil), Array<String>, String)
private
Splits pre-patch lines into numstat, shortstat, and dirstat sections.
-
.split_sections(output, include_dirstat) ⇒ Array(Array<String>, (String, nil), Array<String>, String)
private
Split output into numstat, shortstat, dirstat, and patch sections.
Class Method Details
.parse(output, include_dirstat: false) ⇒ Git::DiffResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse combined patch + numstat + shortstat output into DiffResult
458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/git/parsers/diff.rb', line 458 def parse(output, include_dirstat: false) return Diff.empty_result if output.empty? numstat_lines, shortstat_line, dirstat_lines, patch_text = split_sections(output, include_dirstat) numstat_map = Numstat.parse_as_map(numstat_lines) Diff.build_result( files: PatchFileParser.new(patch_text, numstat_map).parse, shortstat: Diff.parse_shortstat(shortstat_line), dirstat: include_dirstat ? Diff.parse_dirstat(dirstat_lines) : nil ) end |
.split_pre_diff(pre_diff_lines, include_dirstat, patch_text) ⇒ Array(Array<String>, (String, nil), Array<String>, String)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Splits pre-patch lines into numstat, shortstat, and dirstat sections
497 498 499 500 501 502 503 |
# File 'lib/git/parsers/diff.rb', line 497 def split_pre_diff(pre_diff_lines, include_dirstat, patch_text) shortstat_index = pre_diff_lines.index { |l| l.match?(/^\s*\d+\s+files?\s+changed/) } return [pre_diff_lines, nil, [], patch_text] unless shortstat_index [pre_diff_lines[0...shortstat_index], pre_diff_lines[shortstat_index], include_dirstat ? pre_diff_lines[(shortstat_index + 1)..] : [], patch_text] end |
.split_sections(output, include_dirstat) ⇒ Array(Array<String>, (String, nil), Array<String>, String)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Split output into numstat, shortstat, dirstat, and patch sections
479 480 481 482 483 484 485 |
# File 'lib/git/parsers/diff.rb', line 479 def split_sections(output, include_dirstat) lines = output.lines first_diff_index = lines.index { |l| l.start_with?('diff --git') } || lines.length pre_diff_lines = lines[0...first_diff_index].map(&:chomp).reject(&:empty?) patch_text = lines[first_diff_index..].join split_pre_diff(pre_diff_lines, include_dirstat, patch_text) end |