Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4506401ybx; Mon, 4 Nov 2019 14:31:36 -0800 (PST) X-Google-Smtp-Source: APXvYqydeSx4LJBE0IB2GWXu8FnF/Qcf9umFMzpbw3CG/mMQdoe/RDjDnSq7o+jeI3E/tXJt89wq X-Received: by 2002:a17:906:524b:: with SMTP id y11mr25915098ejm.82.1572906696734; Mon, 04 Nov 2019 14:31:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572906696; cv=none; d=google.com; s=arc-20160816; b=i6dGrcda1vyNoQu6iU7W3OwLHiYwEL6DyQDqxd5p2RTNCXkrSLF0Jf3tlD2SqytPpr 6vkmaqMop12akZVspKD9pty/wbMdPXMLcnHkAJfSeG05iQJj3kxAV2aWgG3Pj1tIsYv0 mxnKxHEXUk9X+VTnG9/J05S2U+NbU7/H4+/d/CrnRCvgjIzB+0WVFqaBzUL6VLaBtTc0 1pq9hovDrzwMACVsJTWOY6Ty95+8X9iuuzL9eDiEBmOYeOtsmkuyMFHFIl7uad0b9nX/ V8Kf/qAcmEE13yS0e4qhh5MVFUEGG95g9WgGCIAlnasBXB7aWlQy6+djHyxpwo9f7SUK yZcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m52crl8uyHTMlmYjcdDVgoQX5W99Glnv2ZS039ZnTp0=; b=LSEBouIhfGaWAv9gH1uzg8FgjDVV83MIhLUZIJeu/fUTLs/+y+CmyaYSy+tha6vUT0 W1J3+gjs5dDVKkx3XQr+IK2eM5cFXqL6jtHc7F1h/ND04c8eEQUFOxRtI3EugeHFLq2O b7I5LC/2H5MLGpjtf9B83TAfhleUchaIB1LlRwNaemmK+qTNnGJisRreiDCNIfgERiPE 4RngI7oNr4rn07QOwidOm5qI3P9AL6BaN8ECO84/K1ULVE5EX2ItkHKmJ8SusyuZ55vY orSAZwTtMFmQ/Q8jWBGsTP2pfTviXHtEHyEWM3pMCV0J8picJoQhURrEt2iPwZKfRfUL 0yJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UFBiie76; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j23si8112202ede.389.2019.11.04.14.31.13; Mon, 04 Nov 2019 14:31:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UFBiie76; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388678AbfKDW2j (ORCPT + 99 others); Mon, 4 Nov 2019 17:28:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:39632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729589AbfKDVsv (ORCPT ); Mon, 4 Nov 2019 16:48:51 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A09F8214D9; Mon, 4 Nov 2019 21:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904130; bh=NKZrH064zSWHbCkv4ldq9xtQnckfn8tIW6d4IdRtN2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UFBiie76ycV2G+1M4q8VqApoykxz4BztrTQuoaKjbI1S5jlOWCIaIBUXwqtWnGxbl oJTg/1tPEvBL5LZmy7sphCw4iZtgSje8nPaSaWN8jYDf2CA3bGHalizytvcXqZ+iMW 6xoEXltsyq4r75pcgeg+K9N2dHLHvf6eXShWUQSg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Kujau , Guenter Roeck , Alexander Kapshuk , Brian Norris , Genki Sky , Masahiro Yamada , Sasha Levin Subject: [PATCH 4.4 07/46] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks Date: Mon, 4 Nov 2019 22:44:38 +0100 Message-Id: <20191104211837.762505177@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104211830.912265604@linuxfoundation.org> References: <20191104211830.912265604@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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