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.
%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 ([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.
/^(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 (......)/- 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 (......)/- 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 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$/- 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 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 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 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 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 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.
{ '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) private
-
.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
380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/git/parsers/diff.rb', line 380 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)
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.
407 408 409 410 411 412 413 |
# File 'lib/git/parsers/diff.rb', line 407 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
399 400 401 402 403 404 405 |
# File 'lib/git/parsers/diff.rb', line 399 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 |