Module: Git::Parsers::Fsck Private

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

Handles parsing of git fsck output into structured data objects for dangling, missing, unreachable objects, warnings, roots, and tagged objects.

Design Note: Namespace Organization

This parser creates and returns FsckObject and FsckResult objects, which live at the top-level Git:: namespace rather than within Git::Parsers::. This is intentional:

  • Parsers are infrastructure - marked @api private, users shouldn't interact with them directly
  • Result classes are public API - returned by commands and used throughout the codebase
  • FsckObject and FsckResult represent operation outcomes - they describe repository integrity status, not parsing details

Keeping these classes at Git:: improves discoverability and correctly reflects their role as public types rather than parser internals.

Constant Summary collapse

OBJECT_PATTERN =

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.

Pattern matcher for dangling/missing/unreachable object lines Matches lines like: dangling commit abc123... missing blob def456... unreachable tree 789abc... (name)

/\A(dangling|missing|unreachable) (\w+) ([0-9a-f]{40})(?: \((.+)\))?\z/
WARNING_PATTERN =

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.

Pattern matcher for warning lines Matches lines like: warning in commit abc123...: message here

/\Awarning in (\w+) ([0-9a-f]{40}): (.+)\z/
ROOT_PATTERN =

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.

Pattern matcher for root commit lines Matches lines like: root abc123...

/\Aroot ([0-9a-f]{40})\z/
TAGGED_PATTERN =

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.

Pattern matcher for tagged object lines Matches lines like: tagged commit abc123... (tagname) in def456...

/\Atagged (\w+) ([0-9a-f]{40}) \((.+)\) in ([0-9a-f]{40})\z/

Class Method Summary collapse

Class Method Details

.parse(stdout) ⇒ Git::FsckResult

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 fsck output into a FsckResult object

Examples:

FsckParser.parse("dangling commit abc123...\nmissing blob def456...\n")
# => #<Git::FsckResult dangling: [...], missing: [...]>

Parameters:

  • stdout (String)

    output from git fsck command

Returns:



66
67
68
69
70
# File 'lib/git/parsers/fsck.rb', line 66

def parse(stdout)
  result = { dangling: [], missing: [], unreachable: [], warnings: [], root: [], tagged: [] }
  stdout.each_line { |line| parse_line(line.strip, result) }
  Git::FsckResult.new(**result)
end

.parse_line(line, result) ⇒ Boolean

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 a single line of fsck output

Parameters:

  • line (String)

    a line of output

  • result (Hash)

    the result hash to populate

Returns:

  • (Boolean)

    true if the line was parsed



80
81
82
83
84
85
# File 'lib/git/parsers/fsck.rb', line 80

def parse_line(line, result)
  parse_object_line(line, result) ||
    parse_warning_line(line, result) ||
    parse_root_line(line, result) ||
    parse_tagged_line(line, result)
end

.parse_object_line(line, result) ⇒ Boolean

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 a dangling/missing/unreachable object line

Parameters:

  • line (String)

    a line of output

  • result (Hash)

    the result hash to populate

Returns:

  • (Boolean)

    true if the line was parsed



95
96
97
98
99
# File 'lib/git/parsers/fsck.rb', line 95

def parse_object_line(line, result)
  return unless (match = OBJECT_PATTERN.match(line))

  result[match[1].to_sym] << Git::FsckObject.new(type: match[2].to_sym, oid: match[3], name: match[4])
end

.parse_root_line(line, result) ⇒ Boolean

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 a root line

Parameters:

  • line (String)

    a line of output

  • result (Hash)

    the result hash to populate

Returns:

  • (Boolean)

    true if the line was parsed



123
124
125
126
127
# File 'lib/git/parsers/fsck.rb', line 123

def parse_root_line(line, result)
  return unless (match = ROOT_PATTERN.match(line))

  result[:root] << Git::FsckObject.new(type: :commit, oid: match[1])
end

.parse_tagged_line(line, result) ⇒ Boolean

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 a tagged line

Parameters:

  • line (String)

    a line of output

  • result (Hash)

    the result hash to populate

Returns:

  • (Boolean)

    true if the line was parsed



137
138
139
140
141
# File 'lib/git/parsers/fsck.rb', line 137

def parse_tagged_line(line, result)
  return unless (match = TAGGED_PATTERN.match(line))

  result[:tagged] << Git::FsckObject.new(type: match[1].to_sym, oid: match[2], name: match[3])
end

.parse_warning_line(line, result) ⇒ Boolean

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 a warning line

Parameters:

  • line (String)

    a line of output

  • result (Hash)

    the result hash to populate

Returns:

  • (Boolean)

    true if the line was parsed



109
110
111
112
113
# File 'lib/git/parsers/fsck.rb', line 109

def parse_warning_line(line, result)
  return unless (match = WARNING_PATTERN.match(line))

  result[:warnings] << Git::FsckObject.new(type: match[1].to_sym, oid: match[2], message: match[3])
end