Module: Git::Parsers::LsTree Private
- Defined in:
- lib/git/parsers/ls_tree.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 ls-tree output
Provides a class method that transforms raw git ls-tree output into a
structured Hash consumed by the Git::Repository::ObjectOperations facade.
Class Method Summary collapse
-
.parse(output) ⇒ Hash<String, Hash<String, Hash>>
private
Parse
git ls-treeoutput into a type-keyed hash of entries. -
.unescape_path(path) ⇒ String
private
Converts a git-quoted path back to its original form.
Class Method Details
.parse(output) ⇒ Hash<String, Hash<String, 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 ls-tree output into a type-keyed hash of entries
Each line of output is expected in the format produced by
git ls-tree: <mode> <type> <sha>\t<file>.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/git/parsers/ls_tree.rb', line 30 def parse(output) data = { 'blob' => {}, 'tree' => {}, 'commit' => {} } output.split("\n").each do |line| info, filenm = line.split("\t", 2) filenm = unescape_path(filenm) if filenm mode, type, entry_sha = info.split data[type][filenm] = { mode: mode, sha: entry_sha } end data end |
.unescape_path(path) ⇒ 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.
Converts a git-quoted path back to its original form
49 50 51 52 53 54 55 |
# File 'lib/git/parsers/ls_tree.rb', line 49 def unescape_path(path) if path.start_with?('"') && path.end_with?('"') Git::EscapedPath.new(path[1..-2]).unescape else path end end |