[PATCH v3] git-contacts: allow inputting patch via stdin
- From
Brigham Campbell <me@brighamcampbell.com>
- Date
- Sep 24, 2026, 01:25 UTC
- Message-ID
- <20260923-git-contacts-stdin-v3-1-56dd43c64d56@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 when the user passes `-` at least once:
$ git contacts - <patch $ git contacts patch1 - patch3 <patch2
Signed-off-by: Brigham Campbell <me@brighamcampbell.com> --- This patch is motivated by an ongoing personal effort to allow b4 to invoke git-contacts automatically.
This latest revision requires the user to pass '-' instead of implicitly reading from stdin when stdin is not a tty and argv is empty. This simplifies the change slightly and allows for input via files, revisions, and stdin in a single invocation of git-contacts. --- Changes in v3: - Make user pass '-' instead of an empty argv and non-TTY stdin - Link to v2: https://patch.msgid.link/20260915-git-contacts-stdin-v2-1-2005061d907a@brighamcampbell.com
Changes in v2: - 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts index 85ad732fc0..74910496f4 100755 --- a/contrib/contacts/git-contacts +++ b/contrib/contacts/git-contacts @@ -162,9 +162,11 @@ if (!@ARGV) { die "No input revisions or patch files\n"; } -my (@files, @rev_args); +my (@files, @rev_args, $read_from_stdin); for (@ARGV) { - if (-e) { + if ($_ eq '-') { + $read_from_stdin = 1; + } elsif (-e) { push @files, $_; } else { push @rev_args, $_; @@ -178,6 +180,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