Class: Git::CommandLine::Streaming
- Defined in:
- lib/git/command_line/streaming.rb
Overview
Executes a git command in streaming mode without buffering stdout in memory
Streaming is the non-buffering strategy: it calls
ProcessExecuter.run and streams stdout directly to the caller-supplied out:
IO object. Stderr is always captured internally in a StringIO for error
diagnostics and is available as result.stderr.
Use this class (via Lib#command_streaming) for commands such as
cat-file -p <blob> whose stdout may be too large to buffer in memory.
Capturing is the complementary strategy for the common case where buffering stdout is acceptable.
Constant Summary collapse
- RUN_OPTION_DEFAULTS =
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.
Default options accepted by #run
{ in: nil, out: nil, err: nil, chdir: nil, timeout: nil, raise_on_failure: true, env: {} }.freeze
Instance Attribute Summary
Attributes inherited from Base
#binary_path, #env, #global_opts, #logger
Instance Method Summary collapse
-
#run(**options_hash) ⇒ Git::CommandLineResult
Execute a git command in streaming mode and return the result.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Git::CommandLine::Base
Instance Method Details
#run(**options_hash) ⇒ Git::CommandLineResult
Execute a git command in streaming mode and return the result
Unlike Capturing#run, this method does not buffer
stdout in memory. Stdout is written only to the IO object provided via the
out: option. Stderr is captured internally via a StringIO for error
diagnostics.
Use this entry point for commands that stream large content (e.g. blobs) where capturing stdout in memory would be unacceptable.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/git/command_line/streaming.rb', line 109 def run(*, **) = (RUN_OPTION_DEFAULTS, ) internal_err = StringIO.new # Tee stderr to the caller-provided destination (if any) AND the internal # StringIO. This ensures result.stderr is always available even when err: # is a non-StringIO IO object. err_dest = [:err] ? build_stderr_tee(internal_err, [:err]) : internal_err result = execute(*, err_io: err_dest, **) process_result(result, internal_err, ) end |