Module: Git::Parsers::ConfigEntry Private

Defined in:
lib/git/parsers/config_entry.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 config output

Each public method corresponds to a different git config sub-command variant and handles the specific output format that variant produces. Most variants are called with --show-scope --show-origin --null; parse_urlmatch handles the --get-urlmatch format where --show-origin is unsupported and therefore absent.

Class Method Summary collapse

Class Method Details

.parse_get(key, output) ⇒ Git::ConfigEntryInfo?

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 config --get --show-scope --show-origin --null output

Output format (per entry): scope\0origin\0value\0

The key name is absent from --get output and must be supplied by the caller.

Parameters:

  • key (String)

    the config key name that was queried

  • output (String)

    raw stdout from the command

Returns:



33
34
35
36
37
38
# File 'lib/git/parsers/config_entry.rb', line 33

def parse_get(key, output)
  return nil if output.empty?

  scope, origin, value = output.split("\0", -1)
  Git::ConfigEntryInfo.new(scope: scope, origin: origin, key: key, value: value)
end

.parse_get_all(key, output) ⇒ Array<Git::ConfigEntryInfo>

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 config --get-all --show-scope --show-origin --null output

Output format (per entry): scope\0origin\0value\0

The key name is absent from --get-all output and must be supplied by the caller. Multiple entries appear back-to-back in the same string.

Parameters:

  • key (String)

    the config key name that was queried

  • output (String)

    raw stdout from the command

Returns:



53
54
55
56
57
58
59
60
61
# File 'lib/git/parsers/config_entry.rb', line 53

def parse_get_all(key, output)
  return [] if output.empty?

  tokens = output.split("\0", -1)
  tokens.pop if tokens.last == ''
  tokens.each_slice(3).map do |scope, origin, value|
    Git::ConfigEntryInfo.new(scope: scope, origin: origin, key: key, value: value)
  end
end

.parse_list(output) ⇒ Array<Git::ConfigEntryInfo>

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 config --list --show-scope --show-origin --null output

Also handles --get-regexp output, which shares the same format.

Output format (per entry): scope\0origin\0key\nvalue\0

Multiple entries appear back-to-back in the same string.

Parameters:

  • output (String)

    raw stdout from the command

Returns:



75
76
77
78
79
80
81
82
83
84
# File 'lib/git/parsers/config_entry.rb', line 75

def parse_list(output)
  return [] if output.empty?

  tokens = output.split("\0", -1)
  tokens.pop if tokens.last == ''
  tokens.each_slice(3).map do |scope, origin, key_value|
    key, value = key_value.split("\n", 2)
    Git::ConfigEntryInfo.new(scope: scope, origin: origin, key: key, value: value || '')
  end
end

.parse_urlmatch(output) ⇒ Array<Git::ConfigEntryInfo>

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 config --get-urlmatch --show-scope --null output

Handles the two-field-per-entry format produced by --get-urlmatch when --show-scope is used but --show-origin is not (git does not support --show-origin with --get-urlmatch).

Output format (per entry): scope\0key\nvalue\0

Parameters:

  • output (String)

    raw stdout from the command

Returns:



98
99
100
101
102
103
104
105
106
107
# File 'lib/git/parsers/config_entry.rb', line 98

def parse_urlmatch(output)
  return [] if output.empty?

  tokens = output.split("\0", -1)
  tokens.pop if tokens.last == ''
  tokens.each_slice(2).map do |scope, key_value|
    key, value = key_value.split("\n", 2)
    Git::ConfigEntryInfo.new(scope: scope, origin: nil, key: key, value: value || '')
  end
end