Module: Git::Parsers::CatFile Private
- Defined in:
- lib/git/parsers/cat_file.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 git cat-file commit and tag output
Provides class methods that transform raw git cat-file output lines into
structured Hash objects consumed by the Git::Repository::ObjectOperations
facade.
Constant Summary collapse
- CAT_FILE_HEADER_LINE =
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.
Matches a single
git cat-fileheader line /\A(?<key>\w+) (?<value>.*)\z/
Class Method Summary collapse
-
.each_header(lines) {|key, value| ... }
private
Yields parsed header key/value pairs from
git cat-fileoutput lines. -
.parse_commit(lines, sha) ⇒ Hash
private
Parse
git cat-file commitoutput into a structured Hash. -
.parse_commit_headers(lines) ⇒ Hash
private
Extracts and returns commit headers from the front of
lines. -
.parse_tag(lines, name) ⇒ Hash
private
Parse
git cat-file tagoutput into a structured Hash.
Class Method Details
.each_header(lines) {|key, value| ... }
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.
This method returns an undefined value.
Yields parsed header key/value pairs from git cat-file output lines
Consumes header lines from the front of lines until a blank line is
encountered. Continuation lines that begin with a space are folded
into the previous header value using newline separators.
101 102 103 104 105 106 107 108 |
# File 'lib/git/parsers/cat_file.rb', line 101 def each_header(lines) while (line = lines.shift) && (match = CAT_FILE_HEADER_LINE.match(line)) key = match[:key] value_lines = [match[:value]] value_lines << lines.shift.lstrip while lines.first&.start_with?(' ') yield key, value_lines.join("\n") end end |
.parse_commit(lines, sha) ⇒ Hash
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 git cat-file commit output into a structured Hash
33 34 35 36 37 |
# File 'lib/git/parsers/cat_file.rb', line 33 def parse_commit(lines, sha) headers = parse_commit_headers(lines) = "#{lines.join("\n")}\n" { 'sha' => sha, 'message' => }.merge(headers) end |
.parse_commit_headers(lines) ⇒ Hash
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.
Extracts and returns commit headers from the front of lines
Mutates lines in place, consuming header lines and the blank
separator line. After the call lines contains only message lines.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/git/parsers/cat_file.rb', line 69 def parse_commit_headers(lines) headers = { 'parent' => [] } each_header(lines) do |key, value| if key == 'parent' headers['parent'] << value else headers[key] = value end end headers end |
.parse_tag(lines, name) ⇒ Hash
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 git cat-file tag output into a structured Hash
50 51 52 53 54 55 |
# File 'lib/git/parsers/cat_file.rb', line 50 def parse_tag(lines, name) hsh = { 'name' => name } each_header(lines) { |key, value| hsh[key] = value } hsh['message'] = "#{lines.join("\n")}\n" hsh end |