From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED61FCA9EA9 for ; Fri, 18 Oct 2019 22:10:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEE2922478 for ; Fri, 18 Oct 2019 22:10:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571436639; bh=NKZrH064zSWHbCkv4ldq9xtQnckfn8tIW6d4IdRtN2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Z9vqwFTASxDta5vB6CvfBKjPPbcAtm6K8Ks1/J6oldVdgKp9Kwlp3dHgFvzS5ncnK YbMRcMetddwbUlBvE2QomGSadGHu8FEaNTcuA6nRPgnz++pOY3vZnqtLdVKd3o3aV2 VZeed+lNuWQNvDnKtY3b+oAUNcW7BSvXPcORt9I0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390478AbfJRWKi (ORCPT ); Fri, 18 Oct 2019 18:10:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:43092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389829AbfJRWKO (ORCPT ); Fri, 18 Oct 2019 18:10:14 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 161F12246F; Fri, 18 Oct 2019 22:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571436613; bh=NKZrH064zSWHbCkv4ldq9xtQnckfn8tIW6d4IdRtN2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SimeTUxnyL7552Z4tnVmFMgRB1exBKT6XWH8UNTFqGjZXd4usRfA+hnhFIrehRQul ECYv4zilJa4PfcCP591j6AG9cW3Dbh8TWowvNkvel9KmkFh8eJlJwkdvxpu8KlFHWO p0jAM3GtfuL9F/KKumthjyWAQjIsxdkYl1OQzvrA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Brian Norris , Christian Kujau , Guenter Roeck , Alexander Kapshuk , Genki Sky , Masahiro Yamada , Sasha Levin Subject: [PATCH AUTOSEL 4.4 03/21] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks Date: Fri, 18 Oct 2019 18:09:49 -0400 Message-Id: <20191018221007.10851-3-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191018221007.10851-1-sashal@kernel.org> References: <20191018221007.10851-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brian Norris [ Upstream commit ff64dd4857303dd5550faed9fd598ac90f0f2238 ] 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: Christian Kujau Cc: Guenter Roeck Suggested-by: Alexander Kapshuk Signed-off-by: Brian Norris Tested-by: Genki Sky Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- scripts/setlocalversion | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 966dd3924ea9c..aa28c3f298093 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -72,8 +72,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.20.1