module Git::Repository::Logging::Private
Internal helpers for {Logging} that should not be mixed into {Git::Repository} instances
@api private
Public Instance Methods
Source
# File lib/git/repository/logging.rb, line 209 def log_base_call_options(opts, extra = {}) { all: opts[:all], cherry: opts[:cherry], since: opts[:since], until: opts[:until], grep: opts[:grep], author: opts[:author], max_count: opts[:count], path: opts[:path_limiter] ? Array(opts[:path_limiter]) : nil }.merge(extra).compact end
Builds keyword options passed to {Git::Commands::Log#call}
@param opts [Hash] the log options
@param extra [Hash] additional keyword options merged into the call options
@option opts [Boolean, nil] :all (nil) include commits reachable from any ref
@option opts [Boolean, nil] :cherry (nil) omit commits equivalent to
cherry-picked commits
@option opts [String, nil] :since (nil) include commits newer than this date
expression
@option opts [String, nil] :until (nil) include commits older than this date
expression
@option opts [String, nil] :grep (nil) only include commits whose message
matches this pattern
@option opts [String, nil] :author (nil) only include commits whose author
matches this pattern
@option opts [Integer, nil] :count (nil) maximum number of commits to return
@option opts [String, Pathname, Array<String, Pathname>, nil] :path_limiter (nil)
only include commits that impact files from the specified path(s)
@option extra [Integer, nil] :skip (nil) skip this many commits before output
@option extra [Boolean, nil] :merges (nil) include only merge commits
@return [Hash] keyword options for {Git::Commands::Log#call}
Source
# File lib/git/repository/logging.rb, line 256 def log_or_empty_on_unborn yield rescue Git::FailedError => e raise unless e.result.status.exitstatus == 128 && e.result.stderr =~ /does not have any commits yet/ [] end
Returns an empty result when the repository has no commits yet
@return [Array<Hash>] parsed commits or an empty array for unborn repositories
@raise [Git::FailedError] if git fails for a reason other than unborn history
@yield [] runs the wrapped log command
@yieldreturn [Array<Hash>] the parsed commits from the wrapped command
Source
# File lib/git/repository/logging.rb, line 165 def log_revision_range_args(opts) if opts[:between] ["#{opts[:between][0]}..#{opts[:between][1]}"] elsif opts[:object].is_a?(String) [opts[:object]] else [] end end
Builds positional revision arguments for βgit log`
@param opts [Hash] the log options
@option opts [Array(String, String), nil] :between (nil) a two-revision
range where index `0` is the start and index `1` is the end
@option opts [String, nil] :object (nil) a single revision range expression
@return [Array<String>] zero or one positional revision arguments
Source
# File lib/git/repository/logging.rb, line 234 def run_log_command(execution_context, revision_range_args, call_opts) log_or_empty_on_unborn do result = Git::Commands::Log.new(execution_context).call( *revision_range_args, no_color: true, pretty: 'raw', **call_opts ) RawLogParser.new(result.stdout.split("\n")).parse end end
Executes git log and parses the raw output
@param execution_context [Git::ExecutionContext] the execution context
@param revision_range_args [Array<String>] positional revision range arguments
@param call_opts [Hash] keyword options for {Git::Commands::Log#call}
@return [Array<Hash>] parsed commits from the command output
@raise [Git::FailedError] if git exits with a non-zero exit status
Source
# File lib/git/repository/logging.rb, line 145 def validate_log_between_option!(opts) between = opts[:between] return if between.nil? return if between.is_a?(Array) && between.length == 2 && between.none?(&:nil?) raise ArgumentError, "The log between option must be an Array with exactly two non-nil values but was #{between.inspect}" end
Validates the :between log option
@param opts [Hash] the log options
@option opts [Array(String, String), nil] :between (nil) the two-commit
revision range to validate
@return [void]
@raise [ArgumentError] if the :between option is not an Array with exactly
two non-nil values
Source
# File lib/git/repository/logging.rb, line 127 def validate_log_count_option!(opts) return if opts[:count].nil? || opts[:count].is_a?(Integer) raise ArgumentError, "The log count option must be an Integer but was #{opts[:count].inspect}" end
Validates the :count log option
@param opts [Hash] the log options
@option opts [Integer, nil] :count (nil) the maximum number of commits to
return
@return [void]
@raise [ArgumentError] if the log count option is not an Integer