module Git::Parsers::Diff::Patch
Parser for βpatch output (combined with numstat)
Constants
- BINARY_PATTERN
-
Binary patch marker line pattern
- COPY_FROM_PATTERN
-
Copy source path line pattern
- COPY_TO_PATTERN
-
Copy destination path line pattern
- DIFF_HEADER_PATTERN
-
Header line pattern for each patch file section
- FILE_MODE_PATTERN
-
File mode line pattern for file creation and deletion
- GIT_BINARY_PATCH_PATTERN
-
Gitbinary patch header line pattern - INDEX_PATTERN
-
Index line pattern with source/destination SHAs and optional mode
- NEW_MODE_PATTERN
-
New mode line pattern for mode changes
- OLD_MODE_PATTERN
-
Old mode line pattern for mode changes
- PATCH_STATUS_MAP
-
Maps patch metadata status words to diff status symbols
- RENAME_FROM_PATTERN
-
Rename source path line pattern
- RENAME_TO_PATTERN
-
Rename destination path line pattern
- SIMILARITY_PATTERN
-
Similarity percentage line pattern
Public Instance Methods
Source
# 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
Parse combined patch + numstat + shortstat output into DiffResult
@param output [String] combined output
@param include_dirstat [Boolean] whether dirstat output is expected
@return [Git::DiffResult]
Source
# 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
Splits pre-patch lines into numstat, shortstat, and dirstat sections
@param pre_diff_lines [Array<String>] lines before the first diff header
@param include_dirstat [Boolean] whether dirstat output is expected
@param patch_text [String] patch text starting at the first diff header
@return [Array(Array<String>, (String, nil), Array<String>, String)]
Source
# 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
Split output into numstat, shortstat, dirstat, and patch sections
@param output [String] combined output
@param include_dirstat [Boolean] whether to expect dirstat section
@return [Array(Array<String>, (String, nil), Array<String>, String)]