[PATCH v2] git-contacts: allow inputting patch via stdin
- From
Brigham Campbell <me@brighamcampbell.com>
- Date
- Sep 16, 2026, 04:52 UTC
- Message-ID
- <20260915-git-contacts-stdin-v2-1-2005061d907a@brighamcampbell.com>
- In-Reply-To
- <20260914-git-contacts-stdin-v1-1-9ac628e6fd20@brighamcampbell.com>
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
Signed-off-by: Brigham Campbell <me@brighamcampbell.com> --- I authored this patch as the first of a two-patch series to enable b4 to automatically determine patch recipients. The second patch modifies .b4-config to wire everything up. I discovered, however, that the latest version of b4 doesn't pass the mbox "Fixes " header as it should. A fix is queued for the next release of b4.
The second patch of this series will therefore have to wait until the b4 fix lands in the latest version, so I'm splitting up this series of patches to git. This patch is useful and warranted even by itself.
Link: https://lore.kernel.org/tools/20260914-mbox-from-auto-to-cc-v1-1-fbf0c3fbd460@brighamcampbell.com --- Changes in v2 (Thanks for your careful review, Junio): - Minor variable cleanup / un-spaghettification - Include update to usage comment - Remove Cc trailers from commit message - Link to v1: https://patch.msgid.link/20260914-git-contacts-stdin-v1-1-9ac628e6fd20@brighamcampbell.com --- contrib/contacts/git-contacts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts index 85ad732fc0..03d03135d6 100755 --- a/contrib/contacts/git-contacts +++ b/contrib/contacts/git-contacts @@ -4,6 +4,7 @@ # git-send-email --cc-cmd option, and in other situations. # # Usage: git contacts <file | rev-list option> ... +# git contacts < <patch> use strict; use warnings; @@ -158,11 +159,15 @@ sub mailmap_contacts { return \%mapped; } +my (@files, @rev_args, $read_from_stdin); + if (!@ARGV) { - die "No input revisions or patch files\n"; + 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 +183,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; --- base-commit: f0ef1b96a076d08dc972a8d2cb0d1cfd60931eb6 change-id: 20260914-git-contacts-stdin-1e829930e19b Thanks!
-- Brigham Campbell https://brighamcampbell.com