Re: [PATCH] git-contacts: allow inputting patch via stdin
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 15, 2026, 04:29 UTC
- Message-ID
- <xmqqbj9z2l3y.fsf@gitster.g>
- In-Reply-To
- <20260914-git-contacts-stdin-v1-1-9ac628e6fd20@brighamcampbell.com>
Brigham Campbell <me@brighamcampbell.com> writes:
Show 9 quoted lines
> Make git-contacts accept patch contents via stdin for better > interoperability with other utilities. Read from stdin under the > following circumstances: > > * stdin is not a terminal > * argv is empty > > Cc: Junio C Hamano <gitster@pobox.com> > Cc: Patrick Steinhardt <ps@pks.im>
It is unusual for these trailers to be here for this project.
> Signed-off-by: Brigham Campbell <me@brighamcampbell.com> > ---
Show 20 quoted lines
> diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts
> index 85ad732fc0..52f6fbd044 100755
> --- a/contrib/contacts/git-contacts
> +++ b/contrib/contacts/git-contacts
> @@ -158,7 +158,7 @@ sub mailmap_contacts {
> return \%mapped;
> }
>
> -if (!@ARGV) {
> +if (!@ARGV && -t STDIN) {
> die "No input revisions or patch files\n";
> }
>
> @@ -178,6 +178,9 @@ for (@files) {
> if (@rev_args) {
> scan_rev_args(\%sources, \@rev_args)
> }
> +if (!@ARGV) {
> + scan_patches(\%sources, undef, \*STDIN);
> +}Immediately before this hunk, there is
for (@files) {
scan_patch_file(\%sources, $_);
}where both @rev_args and @files are derived from @ARGV. In fact, once @ARGV is sifted into @rev_args and @files, nobody uses @ARGV afterwards. @ARGV is used only to decide which things to work on and how, and the decision is recorded in variables with more meaningful names than @ARGV. After we are done with @ARGV, the actions are carried out using variables with more meaningful names.
It would be nicer if you followed the pattern by doing something like the attached patch instead.
By the way, there is a comment at the beginning of the file that says:
# List people who might be interested in a patch. Useful as the argument to
# git-send-email --cc-cmd option, and in other situations.
#
# Usage: git contacts <file | rev-list option> ...We'd probably need to update that part of the file as well.
contrib/contacts/git-contacts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git c/contrib/contacts/git-contacts w/contrib/contacts/git-contacts index 85ad732fc0..f9e225b8b2 100755 --- c/contrib/contacts/git-contacts +++ w/contrib/contacts/git-contacts @@ -158,11 +158,15 @@ sub mailmap_contacts { return \%mapped; } -if (!@ARGV) { - die "No input revisions or patch files\n"; +my (@files, @rev_args, $read_from_stdin); + +if (!@ARGV) + if (-t STDIN) { + die "No input revisions or patch files\n"; + } + $read_from_stdin = 1; } -my (@files, @rev_args); for (@ARGV) { if (-e) { push @files, $_; @@ -178,6 +182,9 @@ for (@files) { if (@rev_args) { scan_rev_args(\%sources, \@rev_args) } +if ($read_from_stdin) { + scan_patches(\%sources, undef, \*STDIN); +} my $toplevel = `git rev-parse --show-toplevel`; chomp $toplevel;