mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Roland Hieber <rhi@pengutronix.de>
To: ptxdist@pengutronix.de
Cc: Roland Hieber <rhi@pengutronix.de>
Subject: [ptxdist] [PATCH v3] git-ptx-patches: call git in a pristine environment
Date: Mon, 18 Nov 2019 10:32:40 +0100	[thread overview]
Message-ID: <20191118093239.18000-1-rhi@pengutronix.de> (raw)
In-Reply-To: <20191111113129.18152-1-rhi@pengutronix.de>

The behaviour of git-format-patch can be customized through user-defined
variables from the environment or from the user's .gitconfig, like
custom regexes for function context in diff hunk headers, or different
cleanup options. These things can lead to fuzz in generated patches
which cannot easily be reproduced by different users when re-exporting
existing patch stacks.

Create a wrapper to call git in a pristine environment in order to
minimize any differences between user environments, and use it to format
the patch stack.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>

---
v3:
 - fix typo in the log message

v2:
 - saving author and email is not necessary for format-patch
---
 scripts/git-ptx-patches | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/git-ptx-patches b/scripts/git-ptx-patches
index 721aa78ba31c..fe680273085b 100755
--- a/scripts/git-ptx-patches
+++ b/scripts/git-ptx-patches
@@ -1,5 +1,20 @@
 #!/bin/bash
 
+# Create a pristine environment to minimize unnecessary fuzz when different
+# users use git-ptx-patches on the same patch stack. That is, don't load any
+# config files, and pin down environment variables which could influence git's
+# behaviour or patch output.
+pristine_git() {
+	# Notes from the git(1) manpage:
+	# - GIT_DIFF_OPTS takes takes precedence over -U command line parameter
+	HOME=/nonexistent \
+	XDG_CONFIG_HOME=/nonexistent \
+	GIT_CONFIG_NOSYSTEM=true \
+	GIT_DIFF_OPTS="-u3" \
+	git "$@"
+}
+GIT="pristine_git"
+
 PTX_PATCHES_HEADER="# generated by git-ptx-patches"
 
 function _md5sum() {
@@ -116,7 +131,7 @@ case "$remove_old" in
 esac
 
 # git-format-patch --no-signature is supported since git 1.7.2
-if git format-patch -h 2>&1 | grep -q signature; then
+if ${GIT} format-patch -h 2>&1 | grep -q signature; then
 	GIT_EXTRA_ARGS="--no-signature"
 fi
 
@@ -129,7 +144,7 @@ fi
 GIT_EXTRA_ARGS="$GIT_EXTRA_ARGS --summary --stat=80"
 
 cat .ptxdist/series.0 > .ptxdist/series
-git format-patch -N $GIT_EXTRA_ARGS ${tagopt} -o .ptxdist/patches/ ${range} | sed -e 's,^.ptxdist/patches/,,' > .ptxdist/series.auto
+${GIT} format-patch -N $GIT_EXTRA_ARGS ${tagopt} -o .ptxdist/patches/ ${range} | sed -e 's,^.ptxdist/patches/,,' > .ptxdist/series.auto
 cat .ptxdist/series.auto >> .ptxdist/series
 cat .ptxdist/series.1 >> .ptxdist/series
 cat .ptxdist/series | _md5sum >> .ptxdist/series
-- 
2.24.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

  parent reply	other threads:[~2019-11-18  9:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-11 11:31 [ptxdist] [PATCH] " Roland Hieber
2019-11-17 10:31 ` Michael Olbrich
2019-11-17 21:57   ` Roland Hieber
2019-11-18  7:18   ` Alexander Dahl
2019-11-18  9:13     ` Michael Olbrich
2019-11-18  9:21 ` [ptxdist] [PATCH v2] " Roland Hieber
2019-11-18  9:32 ` Roland Hieber [this message]
2019-11-18 13:39   ` [ptxdist] [PATCH v3] " Jon Ringle
2019-11-27  9:41     ` Roland Hieber
2019-12-05 10:15       ` Roland Hieber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191118093239.18000-1-rhi@pengutronix.de \
    --to=rhi@pengutronix.de \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox