[PATCH 1/2] scripts: Introduce a helper script for git send-email

From: Mario Limonciello
Date: Fri Jun 17 2022 - 14:32:23 EST


Kernel documentation suggests to use scripts/get_maintainer.pl to
find maintainers, but this can be a tedious process especially when
contributing to new subsystems. To make the process easier, introduce
a helper script that can be used with `--to-cmd` and `--cc-cmd` with
`git send-email`.

When this script is launched directly (./scripts/git-send-email.sh) it
will emit usage instructions. This is based off of scripts posted by
Joe Perches.

Suggested-by: Joe Perches <joe@xxxxxxxxxxx>
Link: https://lore.kernel.org/lkml/1473862411.32273.25.camel@xxxxxxxxxxx/
Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx>
---
scripts/git-send-email-cc.sh | 1 +
scripts/git-send-email-to.sh | 1 +
scripts/git-send-email.sh | 37 ++++++++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+)
create mode 120000 scripts/git-send-email-cc.sh
create mode 120000 scripts/git-send-email-to.sh
create mode 100755 scripts/git-send-email.sh

diff --git a/scripts/git-send-email-cc.sh b/scripts/git-send-email-cc.sh
new file mode 120000
index 000000000000..ecb7bcc91077
--- /dev/null
+++ b/scripts/git-send-email-cc.sh
@@ -0,0 +1 @@
+git-send-email.sh
\ No newline at end of file
diff --git a/scripts/git-send-email-to.sh b/scripts/git-send-email-to.sh
new file mode 120000
index 000000000000..ecb7bcc91077
--- /dev/null
+++ b/scripts/git-send-email-to.sh
@@ -0,0 +1 @@
+git-send-email.sh
\ No newline at end of file
diff --git a/scripts/git-send-email.sh b/scripts/git-send-email.sh
new file mode 100755
index 000000000000..89760d50c124
--- /dev/null
+++ b/scripts/git-send-email.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Helper script for git send-email to determine who to send email to.
+# Uses scripts/get_maintainer.pl to parse MAINTAINERS
+#
+
+usage()
+{
+ echo "To use this script add these lines to your gitconfig:"
+ printf "[sendemail]\n"
+ printf "\t cccmd = ./scripts/git-send-email-cc.sh\n"
+ printf "\t tocmd = ./scripts/git-send-email-to.sh\n"
+ exit 1
+}
+
+patch="$1"
+opts="--nogit --nogit-fallback --norolestats"
+if [ $(basename "$0") = "git-send-email.sh" ]; then
+ usage
+elif [ $(basename "$0") = "git-send-email-to.sh" ]; then
+ opts="$opts --pattern-depth=1"
+ maint_opts="--nol"
+fi
+#Handle cover letters - Add maintainers for all other patches in the directory
+if [[ $(basename "$patch") =~ ^0000- ]] ; then
+ ./scripts/get_maintainer.pl --nom $opts $(dirname "$patch")/*.patch
+#Handle patches
+else
+ maint=$(./scripts/get_maintainer.pl $maint_opts $opts "$patch")
+ if [ "$maint" = "" ] && [ "$maint_opts" ]; then
+ echo "linux-kernel@xxxxxxxxxxxxxxx"
+ else
+ echo "$maint"
+ fi
+fi
+
--
2.25.1