dev-cmd/contributions: Better shell argument handling, plus stop piping to grep

This commit is contained in:
Issy Long 2022-07-28 11:20:04 +01:00
parent 5a34bc86c4
commit 8e5a5672fb
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4

View File

@ -80,21 +80,20 @@ module Homebrew
sig { params(repo_path: Pathname, args: Homebrew::CLI::Args).returns(Integer) }
def git_log_author_cmd(repo_path, args)
cmd = "git -C #{repo_path} log --oneline --author=#{args.named.first}"
cmd += " --before=#{args[:to]}" if args[:to]
cmd += " --after=#{args[:from]}" if args[:from]
cmd = ["git", "-C", repo_path, "log", "--oneline", "--author=#{args.named.first}"]
cmd << "--before=#{args[:to]}" if args[:to]
cmd << "--after=#{args[:from]}" if args[:from]
Utils.safe_popen_read(cmd).lines.count
Utils.safe_popen_read(*cmd).lines.count
end
sig { params(repo_path: Pathname, args: Homebrew::CLI::Args).returns(Integer) }
def git_log_coauthor_cmd(repo_path, args)
cmd = "git -C #{repo_path} log --oneline"
cmd += " --format='%(trailers:key=Co-authored-by:)'"
cmd += " --before=#{args[:to]}" if args[:to]
cmd += " --after=#{args[:from]}" if args[:from]
cmd += " | grep #{args.named.first}"
cmd = ["git", "-C", repo_path, "log", "--oneline"]
cmd << "--format='%(trailers:key=Co-authored-by:)'"
cmd << "--before=#{args[:to]}" if args[:to]
cmd << "--after=#{args[:from]}" if args[:from]
Utils.safe_popen_read(cmd).lines.count
Utils.safe_popen_read(*cmd).lines.select { |l| l.include?(args.named.first) }.length
end
end