Volume XXII, number 279Tuesday, October 6, 2026Latest message 34 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patchgit-contacts: allow inputting patch via stdin

19 messages between Sep 15, 2026 and Oct 2, 2026, from Brigham Campbell, Junio C Hamano.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Brigham CampbellSep 15, 2026, 02:43 UTC on lore

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>
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 b4 doesn't
yet pass the mbox "Fixes " header as it should. I sent a fix to 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
---
 contrib/contacts/git-contacts | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Show changes to contrib/contacts/git-contacts +4 −1
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);
+}
 
 my $toplevel = `git rev-parse --show-toplevel`;
 chomp $toplevel;

---
base-commit: 47ce80527c56f462cb97db4ca8125342204d3783
change-id: 20260914-git-contacts-stdin-1e829930e19b

Thanks!
-- 
Brigham Campbell
https://brighamcampbell.com
Junio C HamanoSep 15, 2026, 04:29 UTC in reply to Brigham Campbell on lore

Re: [PATCH] git-contacts: allow inputting patch via stdin

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(-)
Show changes to diff +10 −3
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;
Brigham CampbellSep 16, 2026, 04:52 UTC in reply to Brigham Campbell on lore

[PATCH v2] git-contacts: allow inputting patch via stdin

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(-)
Show changes to contrib/contacts/git-contacts +10 −2
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
Junio C HamanoSep 16, 2026, 14:25 UTC in reply to Brigham Campbell on lore

Re: [PATCH v2] git-contacts: allow inputting patch via stdin

Brigham Campbell <me@brighamcampbell.com> writes:
>  # git-send-email --cc-cmd option, and in other situations.
>  #
>  # Usage: git contacts <file | rev-list option> ...
> +#        git contacts < <patch>

Not necessarily a suggestion to change what you already added, but a mere food for thought.

An obvious (and UNIX-y) alternative design would have been to follow the popular convention to tell the command to read from the standard input stream when "-" is used instead of a filename. Then this line did not have to change, and the command would have allowed arguments like:

	$ git contacts patch1 patch2 - <patch3
	$ git contacts patch1 - patch3 <patch2
Brigham CampbellSep 17, 2026, 06:56 UTC in reply to Junio C Hamano on lore

Re: [PATCH v2] git-contacts: allow inputting patch via stdin

On Wed Sep 16, 2026 at 8:25 AM MDT, Junio C Hamano wrote:
Show 11 quoted lines
> Not necessarily a suggestion to change what you already added, but a
> mere food for thought.
>
> An obvious (and UNIX-y) alternative design would have been to follow
> the popular convention to tell the command to read from the standard
> input stream when "-" is used instead of a filename.  Then this line
> did not have to change, and the command would have allowed arguments
> like:
>
> 	$ git contacts patch1 patch2 - <patch3
> 	$ git contacts patch1 - patch3 <patch2

I considered this approach as well. I may as well have flipped a coin. My approach to choosing hyphen or no wasn't very scientific.

Naturally, if you'd prefer that I change the approach to instead allow the user to pass "-" to indicate that a patch should be read via stdin, I'm happy to send out another revision. I understand why we would rather get the interface right on the first try, even for something small like this.

Until you ask me to work a revision that uses "-", I'll await further review on this v2.

Thanks again for your time!
-- 
Brigham Campbell
https://brighamcampbell.com
Brigham CampbellSep 24, 2026, 01:25 UTC in reply to Brigham Campbell on lore

[PATCH v3] git-contacts: allow inputting patch via stdin

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(-)
Show changes to contrib/contacts/git-contacts +7 −2
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
Junio C HamanoSep 24, 2026, 04:13 UTC in reply to Brigham Campbell on lore

Re: [PATCH v3] git-contacts: allow inputting patch via stdin

Brigham Campbell <me@brighamcampbell.com> writes:
> $ git contacts - <patch
> $ git contacts patch1 - patch3 <patch2

The second one is an example that we could tell the command to read these three files in patch1 and then patch2 and then patch3.

Show 10 quoted lines
> -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, $_;

But this does not match what I would expect here, which would be to have something like this ...

        if (-e || $_ eq '-') {
	        push @files, $_;
        } else {
		push @rev_args, $_;
	}

... around here, and then tell scan_patch_file that "-" shouldn't be opened and instead read from the standard input stream, perhaps like

        sub scan_patch_file {
                my ($commits, $file) = @_;
                if ($file eq '-') {
                        $f = \*STDIN;
                } else {
                        open my $f, '<', $file or die "read failure: $file: $!\n";
                }
                scan_patches($commits, undef, $f);
                close $f;
        }
or something.
Brigham CampbellSep 25, 2026, 01:51 UTC in reply to Junio C Hamano on lore

Re: [PATCH v3] git-contacts: allow inputting patch via stdin

On Wed Sep 23, 2026 at 10:13 PM MDT, Junio C Hamano wrote:
Show 7 quoted lines
> Brigham Campbell <me@brighamcampbell.com> writes:
>
>> $ git contacts - <patch
>> $ git contacts patch1 - patch3 <patch2
>
> The second one is an example that we could tell the command to read
> these three files in patch1 and then patch2 and then patch3.

Does the order in which arguments are processed matter? If it's a matter of producing predictable output, I just checked out `master` and I see that running git-contacts twice produces the same email addresses, but in different orders for the same two input patches:

	$ git format-patch HEAD~2
	0001-Git-2.56-rc2.patch
	0002-Revert-Merge-branch-en-no-amend-during-conflicts.patch
	$ ./contrib/contacts/git-contacts *.patch
	Ævar Arnfjörð Bjarmason <avarab@gmail.com>
	Elijah Newren <newren@gmail.com>
	Junio C Hamano <gitster@pobox.com>
	$ ./contrib/contacts/git-contacts *.patch
	Elijah Newren <newren@gmail.com>
	Ævar Arnfjörð Bjarmason <avarab@gmail.com>
	Junio C Hamano <gitster@pobox.com>

What's more, git-contacts already disregards the order of argv. It will always scan file contents first and then git rev-lists second, even if the user passes the rev-list first like follows:

	git contacts HEAD~2.. foo.patch

I would argue that this is not by mistake. The user should have no expectation as to the order in which arguments are processed. If the commit message implies that the arguments are processed one after another, regardless of whether it's a file, a rev-list, or stdin, then the commit message should be changed.

Do I misunderstand?
-- 
Brigham Campbell
https://brighamcampbell.com
Junio C HamanoSep 25, 2026, 04:38 UTC in reply to Brigham Campbell on lore

Re: [PATCH v3] git-contacts: allow inputting patch via stdin

"Brigham Campbell" <me@brighamcampbell.com> writes:
Show 10 quoted lines
> On Wed Sep 23, 2026 at 10:13 PM MDT, Junio C Hamano wrote:
>> Brigham Campbell <me@brighamcampbell.com> writes:
>>
>>> $ git contacts - <patch
>>> $ git contacts patch1 - patch3 <patch2
>>
>> The second one is an example that we could tell the command to read
>> these three files in patch1 and then patch2 and then patch3.
>
> Does the order in which arguments are processed matter?

It does not matter if the order makes difference in the end result, because my comment was made out of principle. I would not at all surprised if the command gathers information from all sources, sorts and then emits---in which case the end result won't be obviously affected.

Brigham CampbellSep 25, 2026, 06:42 UTC in reply to Brigham Campbell on lore

[PATCH v4] git-contacts: allow inputting patch via stdin

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
Signed-off-by: Brigham Campbell <me@brighamcampbell.com>
---
Junio, you suggested that I make git-contacts process files and stdin
with respect to the order in which they appear in argv. I instead
removed the implication that git-contacts processes input in any
particular order.

Even before this patch, git-contacts parses files first, then git rev-lists second, regardless of their order in argv. If we instead want git-contacts to parse arguments in the same order that they're passed, that's a change which should occur in a separate patch.

I'm happy to write that patch if you'd like.
---
Changes in v4:
- Don't imply that git-contacts processes input in any particular order
- Link to v3: https://patch.msgid.link/20260923-git-contacts-stdin-v3-1-56dd43c64d56@brighamcampbell.com
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
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Patrick Steinhardt <ps@pks.im>
---
 contrib/contacts/git-contacts | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Show changes to contrib/contacts/git-contacts +7 −2
diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts
index 85ad732fc0..df7b920d9e 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 ($read_from_stdin, @files, @rev_args);
 for (@ARGV) {
-	if (-e) {
+	if ($_ eq '-') {
+		$read_from_stdin = 1;
+	} elsif (-e) {
 		push @files, $_;
 	} else {
 		push @rev_args, $_;
@@ -172,6 +174,9 @@ for (@ARGV) {
 }
 
 my %sources;
+if ($read_from_stdin) {
+	scan_patches(\%sources, undef, \*STDIN);
+}
 for (@files) {
 	scan_patch_file(\%sources, $_);
 }

---
base-commit: 0f8e75abebff0877cae681a3d5ff31ac47f54220
change-id: 20260914-git-contacts-stdin-1e829930e19b

Thanks!
-- 
Brigham Campbell
https://brighamcampbell.com
Junio C HamanoSep 25, 2026, 16:09 UTC in reply to Brigham Campbell on lore

Re: [PATCH v4] git-contacts: allow inputting patch via stdin

Brigham Campbell <me@brighamcampbell.com> writes:
Show 5 quoted lines
> 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
OK.
> Even before this patch, git-contacts parses files first, then git
> rev-lists second, regardless of their order in argv. If we instead want
> git-contacts to parse arguments in the same order that they're passed,
> that's a change which should occur in a separate patch.
Fair enough.

We would want an update to contrib/contacts/git-contacts.adoc as well. Here is my attempt. I realize that the new text implies that we read only one patch from the standard input, but I do not know offhand whether scan_patches() successfully reads multiple patches concatenated together into a single stream. If it does, we may want to say "read patch file(s) from" instead.

The original uses <rev> in <angle brackets> to clarify that it is a placeholder, so the added text does the same for <patch>. The original text does not say what the command expects of the "patch files" it mentions, which may be worth improving and when it happens we would say <patch> in the description to refer to one argument on the command line. But I left it outside the scope of this message.

 contrib/contacts/git-contacts.adoc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Show changes to diff +2 −1
diff --git c/contrib/contacts/git-contacts.adoc w/contrib/contacts/git-contacts.adoc
index dd914d1261..6473e878e0 100644
--- c/contrib/contacts/git-contacts.adoc
+++ w/contrib/contacts/git-contacts.adoc
@@ -24,7 +24,8 @@ Input consists of one or more patch files or revision arguments.  A revision
 argument can be a range or a single `<rev>` which is interpreted as
 `<rev>..HEAD`, thus the same revision arguments are accepted as for
 linkgit:git-format-patch[1]. Patch files and revision arguments can be combined
-in the same invocation.
+in the same invocation.  A single dash `'-'` character in place of a <patch>
+tells the command to read a patch from the standard input.  
 
 This command can be useful for determining the list of people with whom to
 discuss proposed changes, or for finding the list of recipients to Cc: when
Brigham CampbellSep 29, 2026, 05:47 UTC in reply to Brigham Campbell on lore

[PATCH v5 0/2] git-contacts: allow inputting patch via stdin

Make git-contacts accept patches via stdin. Multiple patches may be concatenated together before being passed into git-contacts; git-contacts recognizes the mbox `From ` header inserted by git-format-patch to separate concatenated patches.

Update git-contacts and its corresponding documentation.
---
Changes in v5:
- Add a patch documenting stdin support
- Link to v4: https://patch.msgid.link/20260925-git-contacts-stdin-v4-1-9b4e4bcbb91c@brighamcampbell.com
Changes in v4:
- Don't imply that git-contacts processes input in any particular order
- Link to v3: https://patch.msgid.link/20260923-git-contacts-stdin-v3-1-56dd43c64d56@brighamcampbell.com
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
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Patrick Steinhardt <ps@pks.im>
---
Brigham Campbell (2):
      git-contacts: allow inputting patch via stdin
      git-contacts: add stdin functionality to docs
 contrib/contacts/git-contacts      | 9 +++++++--
 contrib/contacts/git-contacts.adoc | 3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)
---
base-commit: 0f8e75abebff0877cae681a3d5ff31ac47f54220
change-id: 20260914-git-contacts-stdin-1e829930e19b
Thanks!
-- 
Brigham Campbell
https://brighamcampbell.com
Brigham CampbellSep 29, 2026, 05:47 UTC in reply to Brigham Campbell on lore

[PATCH v5 1/2] git-contacts: allow inputting patch via stdin

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
Signed-off-by: Brigham Campbell <me@brighamcampbell.com>
---
 contrib/contacts/git-contacts | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Show changes to contrib/contacts/git-contacts +7 −2
diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts
index 85ad732fc0..df7b920d9e 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 ($read_from_stdin, @files, @rev_args);
 for (@ARGV) {
-	if (-e) {
+	if ($_ eq '-') {
+		$read_from_stdin = 1;
+	} elsif (-e) {
 		push @files, $_;
 	} else {
 		push @rev_args, $_;
@@ -172,6 +174,9 @@ for (@ARGV) {
 }
 
 my %sources;
+if ($read_from_stdin) {
+	scan_patches(\%sources, undef, \*STDIN);
+}
 for (@files) {
 	scan_patch_file(\%sources, $_);
 }
-- 
2.55.0
Brigham CampbellSep 29, 2026, 05:47 UTC in reply to Brigham Campbell on lore

[PATCH v5 2/2] git-contacts: add stdin functionality to docs

git-contacts now accepts patches via stdin. Optionally, multiple patches may be concatenated before piping the result into git-contacts. Document this feature.

Signed-off-by: Brigham Campbell <me@brighamcampbell.com>
---
 contrib/contacts/git-contacts.adoc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Show changes to contrib/contacts/git-contacts.adoc +2 −1
diff --git a/contrib/contacts/git-contacts.adoc b/contrib/contacts/git-contacts.adoc
index dd914d1261..4e0b518aae 100644
--- a/contrib/contacts/git-contacts.adoc
+++ b/contrib/contacts/git-contacts.adoc
@@ -24,7 +24,8 @@ Input consists of one or more patch files or revision arguments.  A revision
 argument can be a range or a single `<rev>` which is interpreted as
 `<rev>..HEAD`, thus the same revision arguments are accepted as for
 linkgit:git-format-patch[1]. Patch files and revision arguments can be combined
-in the same invocation.
+in the same invocation.  A single dash `'-'` character in place of a `<patch>`
+tells the command to read patch file(s) from the standard input.
 
 This command can be useful for determining the list of people with whom to
 discuss proposed changes, or for finding the list of recipients to Cc: when
-- 
2.55.0
Junio C HamanoSep 29, 2026, 16:30 UTC in reply to Brigham Campbell on lore

Re: [PATCH v5 0/2] git-contacts: allow inputting patch via stdin

Brigham Campbell <me@brighamcampbell.com> writes:
Show 11 quoted lines
> Make git-contacts accept patches via stdin. Multiple patches may be
> concatenated together before being passed into git-contacts;
> git-contacts recognizes the mbox `From ` header inserted by
> git-format-patch to separate concatenated patches.
>
> Update git-contacts and its corresponding documentation.
>
> ---
> Changes in v5:
> - Add a patch documenting stdin support
> - Link to v4: https://patch.msgid.link/20260925-git-contacts-stdin-v4-1-9b4e4bcbb91c@brighamcampbell.com

The end result may be the same, but I somehow expected that a new feature plus the documentation update to describe the new feature to come in a single patch.

Thanks.
Junio C HamanoSep 29, 2026, 19:29 UTC in reply to Brigham Campbell on lore

Re: [PATCH v5 1/2] git-contacts: allow inputting patch via stdin

Brigham Campbell <me@brighamcampbell.com> writes:
Show 39 quoted lines
> 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
>
> Signed-off-by: Brigham Campbell <me@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..df7b920d9e 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 ($read_from_stdin, @files, @rev_args);
>  for (@ARGV) {
> -	if (-e) {
> +	if ($_ eq '-') {
> +		$read_from_stdin = 1;
> +	} elsif (-e) {
>  		push @files, $_;
>  	} else {
>  		push @rev_args, $_;
> @@ -172,6 +174,9 @@ for (@ARGV) {
>  }
>  
>  my %sources;
> +if ($read_from_stdin) {
> +	scan_patches(\%sources, undef, \*STDIN);
> +}
>  for (@files) {
>  	scan_patch_file(\%sources, $_);
>  }
Doesn't the Usage comment at the beginning also want to be updated?
Thanks.
Show changes to diff +1 −1
diff --git i/contrib/contacts/git-contacts w/contrib/contacts/git-contacts
index 85ad732fc0..1eb91c4ab1 100755
--- i/contrib/contacts/git-contacts
+++ w/contrib/contacts/git-contacts
@@ -3,7 +3,7 @@
 # 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> ...
+# Usage: git contacts <file | '-' | rev-list option> ...
 
 use strict;
 use warnings;
Brigham CampbellOct 2, 2026, 04:44 UTC in reply to Junio C Hamano on lore

Re: [PATCH v5 1/2] git-contacts: allow inputting patch via stdin

On Tue Sep 29, 2026 at 1:29 PM MDT, Junio C Hamano wrote:
> Doesn't the Usage comment at the beginning also want to be updated?

I'm inclined to agree with you. I would have updated it had you not commented the following on v2, referring to the Usage comment:

On Wed Sep 16, 2026 at 8:25 AM MDT, Junio C Hamano wrote:
>                                                       Then this line
> did not have to change

I took that to mean that v5 did not have to change the Usage comment. I will update it in v6.

Thanks for your patience,
-- 
Brigham Campbell
https://brighamcampbell.com
Brigham CampbellOct 2, 2026, 06:50 UTC in reply to Brigham Campbell on lore

[PATCH v6] git-contacts: allow inputting patch via stdin

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
Signed-off-by: Brigham Campbell <me@brighamcampbell.com>
---
I verified the documentation changes by rendering html and inspecting
the output in a web browser.
---
Changes in v6:
- Squash documentation and code into a single commit
- Make documentation changes more complete
- Link to v5: https://patch.msgid.link/20260928-git-contacts-stdin-v5-0-e9becaebc47e@brighamcampbell.com
Changes in v5:
- Add a patch documenting stdin support
- Link to v4: https://patch.msgid.link/20260925-git-contacts-stdin-v4-1-9b4e4bcbb91c@brighamcampbell.com
Changes in v4:
- Don't imply that git-contacts processes input in any particular order
- Link to v3: https://patch.msgid.link/20260923-git-contacts-stdin-v3-1-56dd43c64d56@brighamcampbell.com
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
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Patrick Steinhardt <ps@pks.im>
---
 contrib/contacts/git-contacts      | 11 ++++++++---
 contrib/contacts/git-contacts.adoc | 14 +++++++++++---
 2 files changed, 19 insertions(+), 6 deletions(-)
Show changes to 2 files +19 −6

contrib/contacts/git-contacts, contrib/contacts/git-contacts.adoc

diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts
index 85ad732fc0..e4656affb5 100755
--- a/contrib/contacts/git-contacts
+++ b/contrib/contacts/git-contacts
@@ -3,7 +3,7 @@
 # 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> ...
+# Usage: git contacts <file | '-' | rev-list option> ...
 
 use strict;
 use warnings;
@@ -162,9 +162,11 @@ if (!@ARGV) {
 	die "No input revisions or patch files\n";
 }
 
-my (@files, @rev_args);
+my ($read_from_stdin, @files, @rev_args);
 for (@ARGV) {
-	if (-e) {
+	if ($_ eq '-') {
+		$read_from_stdin = 1;
+	} elsif (-e) {
 		push @files, $_;
 	} else {
 		push @rev_args, $_;
@@ -172,6 +174,9 @@ for (@ARGV) {
 }
 
 my %sources;
+if ($read_from_stdin) {
+	scan_patches(\%sources, undef, \*STDIN);
+}
 for (@files) {
 	scan_patch_file(\%sources, $_);
 }
diff --git a/contrib/contacts/git-contacts.adoc b/contrib/contacts/git-contacts.adoc
index dd914d1261..ea5dd58826 100644
--- a/contrib/contacts/git-contacts.adoc
+++ b/contrib/contacts/git-contacts.adoc
@@ -9,7 +9,7 @@ git-contacts - List people who might be interested in a set of changes
 SYNOPSIS
 --------
 [verse]
-'git contacts' (<patch>|<range>|<rev>)...
+'git contacts' (<patch>|'-'|<range>|<rev>)...
 
 
 DESCRIPTION
@@ -23,8 +23,10 @@ which touched the lines of files under consideration.
 Input consists of one or more patch files or revision arguments.  A revision
 argument can be a range or a single `<rev>` which is interpreted as
 `<rev>..HEAD`, thus the same revision arguments are accepted as for
-linkgit:git-format-patch[1]. Patch files and revision arguments can be combined
-in the same invocation.
+linkgit:git-format-patch[1].  A single dash `'-'` character in place of a
+`<patch>` tells the command to read patch file(s) from the standard input.
+Patch files, standard input, and revision arguments can be combined in the same
+invocation.
 
 This command can be useful for determining the list of people with whom to
 discuss proposed changes, or for finding the list of recipients to Cc: when
@@ -73,6 +75,12 @@ $ git contacts R1..R2
 $ git contacts origin
 ------------
 
+* Input a patch via stdin:
++
+------------
+$ git contacts - <feature.patch
+------------
+
 * Helper for `git send-email`:
 +
 ------------

---
base-commit: c46c1e37724f0478939de636ab8ea5a89086d532
change-id: 20260914-git-contacts-stdin-1e829930e19b

Thanks!
-- 
Brigham Campbell
https://brighamcampbell.com
Junio C HamanoOct 2, 2026, 14:50 UTC in reply to Brigham Campbell on lore

Re: [PATCH v6] git-contacts: allow inputting patch via stdin

Brigham Campbell <me@brighamcampbell.com> writes:
Show 10 quoted lines
> 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
>
> Signed-off-by: Brigham Campbell <me@brighamcampbell.com>
> ---
> I verified the documentation changes by rendering html and inspecting
> the output in a web browser.
Very much appreciated.  Will replace.
Let me mark the topic for 'next'.
Thanks.

Back to recent threads