From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: Brian Norris <briannorris@chromium.org>
Cc: Alexander Kapshuk <alexander.kapshuk@gmail.com>,
Genki Sky <sky@genki.is>,
Douglas Anderson <dianders@chromium.org>,
Guenter Roeck <linux@roeck-us.net>,
Christian Kujau <lists@nerdbynature.de>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
schwab@linux-m68k.org
Subject: Re: [PATCH v3] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks
Date: Mon, 19 Nov 2018 23:42:08 +0900 [thread overview]
Message-ID: <CAK7LNASaEkUH4egjXVmyKP2awAEccF4_WJacxh=VWA+N3nB-qQ@mail.gmail.com> (raw)
In-Reply-To: <20181115021116.GA195691@google.com>
On Thu, Nov 15, 2018 at 11:12 AM Brian Norris <briannorris@chromium.org> wrote:
>
> git-diff-index does not refresh the index for you, so using it for a
> "-dirty" check can give misleading results. Commit 6147b1cf19651
> ("scripts/setlocalversion: git: Make -dirty check more robust") tried to
> fix this by switching to git-status, but it overlooked the fact that
> git-status also writes to the .git directory of the source tree, which
> is definitely not kosher for an out-of-tree (O=) build. That is getting
> reverted.
>
> Fortunately, git-status now supports avoiding writing to the index via
> the --no-optional-locks flag, as of git 2.14. It still calculates an
> up-to-date index, but it avoids writing it out to the .git directory.
>
> So, let's retry the solution from commit 6147b1cf19651 using this new
> flag first, and if it fails, we assume this is an older version of git
> and just use the old git-diff-index method.
>
> It's hairy to get the 'grep -vq' (inverted matching) correct by stashing
> the output of git-status (you have to be careful about the difference
> betwen "empty stdin" and "blank line on stdin"), so just pipe the output
> directly to grep and use a regex that's good enough for both the
> git-status and git-diff-index version.
>
> Cc: Genki Sky <sky@genki.is>
> Cc: Christian Kujau <lists@nerdbynature.de>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Suggested-by: Alexander Kapshuk <alexander.kapshuk@gmail.com>
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
> v1 -> v2:
> * handle empty (non-dirty) results properly, where
> echo "${empty_variable}" | grep -qv "${something_else}"
> always has a 0 exit status (a blank line is an inverted match for any
> non-blank expression). Just pipe directly to grep instead, with a
> hopefully-not-too-permissive regex to handle both versions.
> * actually tested with dirty and non-dirty trees this time
>
> v2 -> v3:
> * switch to extended regex (-E), instead of relying on GNU extension
> (\?)
> ---
Applied to linux-kbuild.
Thanks!
> scripts/setlocalversion | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/setlocalversion b/scripts/setlocalversion
> index 71f39410691b..365b3c2b8f43 100755
> --- a/scripts/setlocalversion
> +++ b/scripts/setlocalversion
> @@ -73,8 +73,16 @@ scm_version()
> printf -- '-svn%s' "`git svn find-rev $head`"
> fi
>
> - # Check for uncommitted changes
> - if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
> + # Check for uncommitted changes.
> + # First, with git-status, but --no-optional-locks is only
> + # supported in git >= 2.14, so fall back to git-diff-index if
> + # it fails. Note that git-diff-index does not refresh the
> + # index, so it may give misleading results. See
> + # git-update-index(1), git-diff-index(1), and git-status(1).
> + if {
> + git --no-optional-locks status -uno --porcelain 2>/dev/null ||
> + git diff-index --name-only HEAD
> + } | grep -qvE '^(.. )?scripts/package'; then
> printf '%s' -dirty
> fi
>
> --
> 2.19.1.930.g4563a0d9d0-goog
--
Best Regards
Masahiro Yamada
next prev parent reply other threads:[~2018-11-19 14:43 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 18:10 [PATCH] Revert "scripts/setlocalversion: git: Make -dirty check more robust" Guenter Roeck
2018-11-06 19:23 ` Genki Sky
2018-11-07 2:22 ` Brian Norris
2018-11-07 2:58 ` Christian Kujau
2018-11-07 3:10 ` Guenter Roeck
2018-11-07 4:00 ` Brian Norris
2018-11-07 18:44 ` Brian Norris
2018-11-07 20:43 ` Genki Sky
2018-11-07 20:55 ` Guenter Roeck
2018-11-07 21:07 ` Genki Sky
2018-11-07 21:18 ` Doug Anderson
2018-11-07 21:26 ` Genki Sky
2018-11-08 3:16 ` Brian Norris
2018-11-09 2:55 ` Masahiro Yamada
2018-11-09 18:34 ` [PATCH] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks Brian Norris
2018-11-09 20:43 ` Guenter Roeck
2018-11-10 8:58 ` Genki Sky
2018-11-10 10:42 ` Andreas Schwab
2018-11-10 20:10 ` Genki Sky
2018-11-11 14:48 ` Alexander Kapshuk
2018-11-11 15:03 ` Alexander Kapshuk
2018-11-11 17:41 ` Genki Sky
2018-11-11 19:59 ` Alexander Kapshuk
2018-11-12 8:42 ` Alexander Kapshuk
2018-11-13 0:09 ` Brian Norris
2018-11-13 8:35 ` Alexander Kapshuk
2018-11-13 18:32 ` Brian Norris
2018-11-13 19:03 ` [PATCH v2] " Brian Norris
2018-11-13 19:47 ` Genki Sky
2018-11-13 22:03 ` Andreas Schwab
2018-11-15 2:06 ` Brian Norris
2018-11-15 2:11 ` [PATCH v3] " Brian Norris
2018-11-16 15:17 ` Masahiro Yamada
2018-11-19 14:42 ` Masahiro Yamada [this message]
2018-11-13 19:15 ` [PATCH] " Alexander Kapshuk
2018-11-09 2:55 ` [PATCH] Revert "scripts/setlocalversion: git: Make -dirty check more robust" Masahiro Yamada
2018-11-09 16:39 ` Masahiro Yamada
2018-11-09 16:39 ` Masahiro Yamada
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='CAK7LNASaEkUH4egjXVmyKP2awAEccF4_WJacxh=VWA+N3nB-qQ@mail.gmail.com' \
--to=yamada.masahiro@socionext.com \
--cc=alexander.kapshuk@gmail.com \
--cc=briannorris@chromium.org \
--cc=dianders@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=lists@nerdbynature.de \
--cc=schwab@linux-m68k.org \
--cc=sky@genki.is \
/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;
as well as URLs for NNTP newsgroup(s).