git-contacts: allow inputting patch via stdin
PATCH 1/1 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
---
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.
--- contrib/contacts/git-contacts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/contacts/git-contacts +4 -1
@@ -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!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
Quoted 9 lines · Brigham Campbell
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 emptyCc Junio C Hamano <[email protected]>Cc Patrick Steinhardt <[email protected]>
It is unusual for these trailers to be here for this project.
Quoted 17 lines
Signed-off-by Brigham Campbell <[email protected]>---
contrib/contacts/git-contacts +1
-1@@ -158,7 +158,7 @@ sub mailmap_contacts { return \%mapped; } -if (!@ARGV) { +if (!@ARGV && -t STDIN) { die "No input revisions or patch files\n"; }
contrib/contacts/git-contacts for (@files) { · line 183
Quoted 6 lines
contrib/contacts/git-contacts +3
-0@@ -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(-)
contrib/contacts/git-contacts +10 -3
@@ -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;
PATCH v2 1/1 git-contacts: allow inputting patch via stdin
In reply to Brigham CampbellMake 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
---
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.
---
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(-)
contrib/contacts/git-contacts +10 -2
@@ -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!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
Quoted 4 lines · Brigham Campbell
# 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
Quoted 11 lines · Junio C Hamano
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!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
PATCH v3 1/1 git-contacts: allow inputting patch via stdin
In reply to Brigham CampbellMake 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
---
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(-)
contrib/contacts/git-contacts +7 -2
@@ -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!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
Quoted 2 lines · Brigham Campbell
$ 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.
contrib/contacts/git-contacts if (!@ARGV) { · line 172
Quoted 10 lines
contrib/contacts/git-contacts +4
-2-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.
Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Brigham Campbell
$ git contacts - <patch $ git contacts patch1 - patch3 <patch2The 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 <[email protected]> Elijah Newren <[email protected]> Junio C Hamano <[email protected]> $ ./contrib/contacts/git-contacts *.patch Elijah Newren <[email protected]> Ævar Arnfjörð Bjarmason <[email protected]> Junio C Hamano <[email protected]>
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?
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
Quoted 10 lines · Brigham Campbell
Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Brigham Campbell
$ git contacts - <patch $ git contacts patch1 - patch3 <patch2The 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.
PATCH v4 1/1 git-contacts: allow inputting patch via stdin
In reply to Brigham CampbellMake 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
---
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: [email protected]
Cc: Junio C Hamano <[email protected]>
Cc: Patrick Steinhardt <[email protected]>
--- contrib/contacts/git-contacts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
contrib/contacts/git-contacts +7 -2
@@ -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!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
Quoted 5 lines · Brigham Campbell
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.
Quoted 4 lines
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(-)
contrib/contacts/git-contacts.adoc +2 -1
@@ -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
v5 cover git-contacts: allow inputting patch via stdin
In reply to Brigham CampbellMake 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: [email protected]
Cc: Junio C Hamano <[email protected]>
Cc: Patrick Steinhardt <[email protected]>
---
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!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
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
--- contrib/contacts/git-contacts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
contrib/contacts/git-contacts +7 -2
@@ -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, $_); }
Signature · 1 line
2.55.0
Quoted 30 lines · Brigham Campbell
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 - <patchSigned-off-by Brigham Campbell <[email protected]>--- contrib/contacts/git-contacts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)contrib/contacts/git-contacts +4
-2@@ -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, $_;
contrib/contacts/git-contacts for (@ARGV) { · line 182
Quoted 9 lines
contrib/contacts/git-contacts +3
-0@@ -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.
contrib/contacts/git-contacts +1 -1
@@ -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;
Quoted 1 line · Junio C Hamano
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:
Quoted 2 lines · Junio C Hamano
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,
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
PATCH v5 2/2 git-contacts: add stdin functionality to docs
In reply to Brigham Campbellgit-contacts now accepts patches via stdin. Optionally, multiple patches may be concatenated before piping the result into git-contacts. Document this feature.
--- contrib/contacts/git-contacts.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/contacts/git-contacts.adoc +2 -1
@@ -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
Signature · 1 line
2.55.0
Quoted 11 lines · Brigham Campbell
Make git-contacts accept patches via stdin. Multiple patches may be concatenated together before being passed into git-contacts; git-contacts recognizes the mbox
Fromheader 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.
PATCH v6 1/1 git-contacts: allow inputting patch via stdin
In reply to Brigham CampbellMake 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
---
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: [email protected]
Cc: Junio C Hamano <[email protected]>
Cc: Patrick Steinhardt <[email protected]>
--- contrib/contacts/git-contacts | 11 ++++++++--- contrib/contacts/git-contacts.adoc | 14 +++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-)
contrib/contacts/git-contacts +8 -3
@@ -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, $_); }
contrib/contacts/git-contacts.adoc +11 -3
@@ -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!
Signature · 2 lines
Brigham Campbell https://brighamcampbell.com
Quoted 10 lines · Brigham Campbell
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 - <patchSigned-off-by Brigham Campbell <[email protected]>---
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.