module Git::Parsers::Diff::Patch::PatchMetadataParser
Methods for parsing patch metadata lines (index, mode, rename, etc.)
@api private
Private Instance Methods
Source
# File lib/git/parsers/diff.rb, line 595 def apply_file_mode(type, mode) case type when 'new' @current_file[:dst_mode] = mode @current_file[:src_path] = nil when 'deleted' @current_file[:src_mode] = mode @current_file[:dst_path] = nil end end
Applies source or destination mode updates based on file operation type
@param type [String] operation type (ββnewββ or `βdeletedββ)
@param mode [String] file mode from patch metadata
@return [void]
Source
# File lib/git/parsers/diff.rb, line 577 def detect_type_change src_mode = @current_file[:src_mode] dst_mode = @current_file[:dst_mode] return unless src_mode && dst_mode # Type change occurs when the file type bits differ (e.g., 100644 vs 120000) # The first 3 digits represent the file type @current_file[:status] = :type_changed if src_mode[0, 3] != dst_mode[0, 3] end
Marks the current entry as a type change when type bits differ
@return [void]
Source
# File lib/git/parsers/diff.rb, line 517 def parse_metadata_line(line) try_parse_index(line) try_parse_file_mode(line) try_parse_old_new_mode(line) try_parse_rename(line) try_parse_similarity(line) try_mark_binary(line) end
Parses a metadata line for the current patch file
@param line [String] a metadata line from the patch block
@return [void]
Source
# File lib/git/parsers/diff.rb, line 657 def try_mark_binary(line) @current_file[:binary] = true if line.match?(BINARY_PATTERN) || line.match?(GIT_BINARY_PATCH_PATTERN) end
Marks the current file as binary when binary markers are present
@param line [String] a metadata line from the patch block
@return [Boolean, nil] true when binary metadata is detected
Source
# File lib/git/parsers/diff.rb, line 549 def try_parse_file_mode(line) return unless (match = line.match(FILE_MODE_PATTERN)) type, mode = match.captures @current_file[:status] = PATCH_STATUS_MAP.fetch(type, :modified) apply_file_mode(type, mode) end
Parses file creation and deletion mode lines
@param line [String] a metadata line from the patch block
@return [void]
Source
# File lib/git/parsers/diff.rb, line 532 def try_parse_index(line) return unless (match = line.match(INDEX_PATTERN)) @current_file[:src_sha] = match[1] @current_file[:dst_sha] = match[2] return unless (mode = match[3]&.strip) return unless @current_file[:src_mode].nil? && @current_file[:dst_mode].nil? @current_file[:src_mode] = @current_file[:dst_mode] = mode end
Parses index metadata and updates mode defaults when present
@param line [String] a metadata line from the patch block
@return [void]
Source
# File lib/git/parsers/diff.rb, line 563 def try_parse_old_new_mode(line) if (match = line.match(OLD_MODE_PATTERN)) @current_file[:src_mode] = match[1] detect_type_change elsif (match = line.match(NEW_MODE_PATTERN)) @current_file[:dst_mode] = match[1] detect_type_change end end
Parses old/new mode lines and detects type changes
@param line [String] a metadata line from the patch block
@return [void]
Source
# File lib/git/parsers/diff.rb, line 612 def try_parse_rename(line) try_parse_rename_or_copy(line, RENAME_FROM_PATTERN, RENAME_TO_PATTERN, :renamed) || try_parse_rename_or_copy(line, COPY_FROM_PATTERN, COPY_TO_PATTERN, :copied) end
Parses rename or copy metadata for the current patch file
@param line [String] a metadata line from the patch block
@return [Symbol, nil] parsed status when a rename or copy line matches
Source
# File lib/git/parsers/diff.rb, line 629 def try_parse_rename_or_copy(line, from_pattern, to_pattern, status) if (match = line.match(from_pattern)) @current_file[:src_path] = Diff.unescape_path(match[1]) @current_file[:status] = status elsif (match = line.match(to_pattern)) @current_file[:dst_path] = Diff.unescape_path(match[1]) @current_file[:status] = status end end
Parses one side of rename or copy metadata
@param line [String] a metadata line from the patch block
@param from_pattern [Regexp] pattern for source path lines
@param to_pattern [Regexp] pattern for destination path lines
@param status [Symbol] status to set when a pattern matches
@return [Symbol, nil] the assigned status when matched
Source
# File lib/git/parsers/diff.rb, line 645 def try_parse_similarity(line) return unless (match = line.match(SIMILARITY_PATTERN)) @current_file[:similarity] = match[1].to_i end
Parses similarity index metadata
@param line [String] a metadata line from the patch block
@return [Integer, nil] parsed similarity percentage when matched