Class: Git::Commands::CatFile::Batch Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/cat_file/batch.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-cat-file/2.53.0

Queries one or more git objects via the batch stdin streaming protocol

Accepts object names (or commands) written to stdin. Three output modes are available, selected by passing exactly one of batch:, batch_check:, or batch_command: as a keyword argument:

  • batch: true (--batch) — for each named object, write a header line <sha> <type> <size> followed by the raw content bytes and a newline separator; missing objects are reported inline as <name> missing
  • batch_check: true (--batch-check) — for each named object, write one metadata line <sha> <type> <size>; missing objects as <name> missing
  • batch_command: true (--batch-command) — enter command-dispatch mode; stdin carries named verbs (contents <object>, info <object>, flush), allowing content and metadata requests to be interleaved in a single process

All three modes accept a format string instead of true to customise the per-object output line (e.g. batch: "%(objectname) %(objecttype) %(objectsize)")

When batch_all_objects: true is given instead of object names, git enumerates the entire object database itself and stdin is not read (incompatible with batch_command:).

Missing objects never cause a non-zero exit — they are reported inline.

For single-object queries, use Raw. For filter-processed content, use Filtered.

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(*objects, batch: true, **options) ⇒ Git::CommandLineResult #call(*objects, batch_check: true, **options) ⇒ Git::CommandLineResult #call(*objects, batch_command: true, **options) ⇒ Git::CommandLineResult #call(batch_all_objects: true, batch: true, **options) ⇒ Git::CommandLineResult #call(batch_all_objects: true, batch_check: true, **options) ⇒ Git::CommandLineResult

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.

Execute git cat-file in batch stdin-streaming mode.

Exactly one of batch:, batch_check:, or batch_command: must be selected. Pass batch_all_objects: true instead of object names to enumerate the entire object database without reading stdin.

Overloads:

  • #call(*objects, batch: true, **options) ⇒ Git::CommandLineResult

    Stream one or more named objects; return header + content per object

    Parameters:

    • objects (Array<String>)

      object names written to stdin

    • batch (Boolean, String) (defaults to: true)

      enable --batch mode; pass a format string to customise the per-object output header (e.g. "%(objectname) %(objecttype) %(objectsize)")

    • options (Hash)

      command options

    Options Hash (**options):

    • :buffer (Boolean, nil) — default: nil

      use normal stdio buffering for better throughput

    • :follow_symlinks (Boolean, nil) — default: nil

      follow symlinks in trees

    • :unordered (Boolean, nil) — default: nil

      output in arbitrary order

    • :textconv (Boolean, nil) — default: nil

      apply textconv filters

    • :filters (Boolean, nil) — default: nil

      apply full working-tree filters

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    • :filter (String) — default: nil

      omit objects matching the given filter spec

    • :Z (Boolean, nil) — default: nil

      use NUL-delimited I/O

    • :out (#write, nil) — default: nil

      stream stdout to this IO object instead of buffering in memory; when given, result.stdout will be ''

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Stdout contains the batch output stream (or '' when out: is given)

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits non-zero (catastrophic failure only; missing objects are reported inline)

  • #call(*objects, batch_check: true, **options) ⇒ Git::CommandLineResult

    Stream one or more named objects; return one metadata line per object

    Parameters:

    • objects (Array<String>)

      object names written to stdin

    • batch_check (Boolean, String) (defaults to: true)

      enable --batch-check mode; pass a format string to customise the per-object output line (e.g. "%(objectname) %(objecttype) %(objectsize)")

    • options (Hash)

      command options

    Options Hash (**options):

    • :buffer (Boolean, nil) — default: nil

      use normal stdio buffering for better throughput when processing large numbers of objects

    • :follow_symlinks (Boolean, nil) — default: nil

      follow symlinks in trees

    • :unordered (Boolean, nil) — default: nil

      output in arbitrary order

    • :textconv (Boolean, nil) — default: nil

      apply textconv filters

    • :filters (Boolean, nil) — default: nil

      apply full working-tree filters

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    • :filter (String) — default: nil

      omit objects matching the given filter spec

    • :Z (Boolean, nil) — default: nil

      use NUL-delimited I/O

    • :out (#write, nil) — default: nil

      stream stdout to this IO object instead of buffering in memory; when given, result.stdout will be ''

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Stdout contains one metadata line per object (or '' when out: is given)

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits non-zero (catastrophic failure only; missing objects are reported inline)

  • #call(*objects, batch_command: true, **options) ⇒ Git::CommandLineResult

    Dispatch mixed contents/info/flush commands via stdin

    Each element of objects is written verbatim as a stdin line — the caller is responsible for prefixing lines with the appropriate verb (contents <object>, info <object>, or flush).

    Parameters:

    • objects (Array<String>)

      pre-formatted command lines to write to stdin

    • batch_command (Boolean, String) (defaults to: true)

      enable --batch-command mode; pass a format string to customise the output of info and contents commands

    • options (Hash)

      command options

    Options Hash (**options):

    • :buffer (Boolean, nil) — default: nil

      use normal stdio buffering for better throughput

    • :textconv (Boolean, nil) — default: nil

      apply textconv filters

    • :filters (Boolean, nil) — default: nil

      apply full working-tree filters

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    • :filter (String) — default: nil

      omit objects matching the given filter spec

    • :Z (Boolean, nil) — default: nil

      use NUL-delimited I/O

    • :out (#write, nil) — default: nil

      stream stdout to this IO object instead of buffering in memory; when given, result.stdout will be ''

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Stdout contains the interleaved command output (or '' when out: is given)

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits non-zero

  • #call(batch_all_objects: true, batch: true, **options) ⇒ Git::CommandLineResult

    Enumerate all objects in the repository with full content

    Parameters:

    • batch_all_objects (Boolean) (defaults to: true)

      enumerate all objects; stdin is not read

    • batch (Boolean, String) (defaults to: true)

      enable --batch mode; pass a format string to customise the per-object output header

    • options (Hash)

      command options

    Options Hash (**options):

    • :buffer (Boolean, nil) — default: nil

      use normal stdio buffering for better throughput

    • :unordered (Boolean, nil) — default: nil

      output in arbitrary order

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap for commit and tag objects (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    • :filter (String) — default: nil

      omit objects matching the given filter spec

    • :Z (Boolean, nil) — default: nil

      use NUL-delimited I/O

    • :out (#write, nil) — default: nil

      stream stdout to this IO object instead of buffering in memory; when given, result.stdout will be ''

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Stdout contains the full batch output (or '' when out: is given)

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits non-zero

  • #call(batch_all_objects: true, batch_check: true, **options) ⇒ Git::CommandLineResult

    Enumerate all objects in the repository with metadata only

    Parameters:

    • batch_all_objects (Boolean) (defaults to: true)

      enumerate all objects; stdin is not read

    • batch_check (Boolean, String) (defaults to: true)

      enable --batch-check mode; pass a format string to customise the per-object output line

    • options (Hash)

      command options

    Options Hash (**options):

    • :buffer (Boolean, nil) — default: nil

      use normal stdio buffering for better throughput when processing large numbers of objects

    • :unordered (Boolean, nil) — default: nil

      output in arbitrary order

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap for commit and tag objects (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    • :filter (String) — default: nil

      omit objects matching the given filter spec

    • :Z (Boolean, nil) — default: nil

      use NUL-delimited I/O

    • :out (#write, nil) — default: nil

      stream stdout to this IO object instead of buffering in memory; when given, result.stdout will be ''

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Stdout contains one metadata line per object (or '' when out: is given)

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits non-zero



312
313
314
315
316
317
318
319
320
# File 'lib/git/commands/cat_file/batch.rb', line 312

def call(*objects, **)
  bound = args_definition.bind(*objects, **)
  validate_version!
  # `-Z` puts git into NUL I/O mode: input objects must be NUL-terminated.
  # Without `-Z`, the standard newline delimiter is used.
  delimiter = bound.Z? ? "\0" : "\n"
  stdin = Array(bound.object).map { |o| "#{o}#{delimiter}" }.join
  with_stdin(stdin) { |reader| run_batch(bound, reader) }
end