Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7457156imu; Wed, 14 Nov 2018 18:12:13 -0800 (PST) X-Google-Smtp-Source: AJdET5cEIUfL23/S8xUWdGwwe7oOqTXOO74alz+XwrXgr7nK4DsGximF7TK5lmxwf/7MzZIA7Lv7 X-Received: by 2002:a17:902:a5ca:: with SMTP id t10mr4336686plq.139.1542247933591; Wed, 14 Nov 2018 18:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542247933; cv=none; d=google.com; s=arc-20160816; b=aGttP/beTJ+5C4jT+86hC+ShVFKUNlDInVtwMkuQ+nTyvbLWODeH80sgqrMG5PjLP9 HqitLlUROKQen2TFOsaFjBvaNMicu4BlaPzGdWbKpUq7IyXZqTQ5rfaeAOq79eJL9GMg t/IXkDs9NPmkkdEGraEIowUTeodeohvoJzdgmdmEMED38nwP+znyhdnP5hUuRgSQSAWe 2lJpP4U1sDqQ++reloizU5qKfIk3uWzpl8cpKCuSx13ls3/5YrREa3JdceIiyFYeW/ki D21UbVMq9GFGz/hYiwRHnjIq49QaBQukeDznd/7OPXmZQWX8Kk/ZZqvmJXvjZ84tGb0S sGaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=49XnI6arT3v1CXSoUHRBjliSSvBvOE3PSXedAJX9RgE=; b=M+DYpL2+t7neb9HCjUbxJZg9gE3XZZsk1ytlNdO1/fYsOHCLZoo+v6BCwDysanjm8l 8AOjvv3KeMF9FF9oK3wZA/a7ZgW2v5TMo5c5UnNAbAsr+12HlBsubdwdJtpBqlSZKWt7 j0mO5uS93TxLSLctmOy8aOUDF0hbo1p++zGGUXPX0jbkPGEs5zve/EfxdNHmMmtOicdn sSH0sHWLu/2JrX4Px6l8YjfxQoep7vgDYQn60plot4lyQVTs2lZU5YUqp9R6QbOzYNpF pN6fe0zTZ6BonSvRFs4pTnJWrcqSY/ZGJMQPt52Lj6uggoGhD2+ckmLNiZG5fqpMulXU lFsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vl8j+NuX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32-v6si27956324plc.370.2018.11.14.18.11.58; Wed, 14 Nov 2018 18:12:13 -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=@chromium.org header.s=google header.b=Vl8j+NuX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728257AbeKOMRM (ORCPT + 99 others); Thu, 15 Nov 2018 07:17:12 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37868 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbeKOMRL (ORCPT ); Thu, 15 Nov 2018 07:17:11 -0500 Received: by mail-pl1-f193.google.com with SMTP id b5so2279281plr.4 for ; Wed, 14 Nov 2018 18:11:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=49XnI6arT3v1CXSoUHRBjliSSvBvOE3PSXedAJX9RgE=; b=Vl8j+NuXm7IDyt/0WCP0xu45sw5GqnDLbNanJ3DwiP6tjnwbZqxMUoYOG608UMoQpy 7TqC+enn2OVpTqKP8+hnsl7B4tmzXTTqaSLs9FBFySk+zO5xFdWG6abZjtVYncXfVSvc qs+DPFwLTEKjLruxSu/IcX5qpemqnX4LTeGEk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=49XnI6arT3v1CXSoUHRBjliSSvBvOE3PSXedAJX9RgE=; b=levBx1LxKSnb4FeoQRdli9yxiSuzddgajILIAEeCdgAoo54hH6gNjzpsj7CUm1HjjF c3kffmyVwYpARh6KWeDT3ZoMX1tRp9Y+dlqX3gA40xZB5tgpKaqyKDvg+FNfbnyg4tSB xmrVXj9R7x4xSxqefXJ4dkE3Hv950oafkkmTe+mVwLfkgnoUz46f/MmK5egJLeMnzuq8 lmbFuNqs1/sQ14GithA6apF96Cuax8jZ0Wd06FWkUTvWRKCuCD1TPOGeiNv1G5e2ZovX HeCRGxOrhrApIq5cFApn+xmePMzupGB2QuAXTrvyHVMl+C6GXl9DKrYP/2wir1ipccNv xugw== X-Gm-Message-State: AGRZ1gKKyVxjDHcJ7frXK/uyf0O4WUW6Z5LuZ9tCB8DjQwb1xJaTAvUW XckGcb47I6X7/rY5crIqLuEhyw== X-Received: by 2002:a17:902:8604:: with SMTP id f4-v6mr1298021plo.206.1542247881596; Wed, 14 Nov 2018 18:11:21 -0800 (PST) Received: from google.com ([2620:15c:202:1:299d:6b87:5478:d28a]) by smtp.gmail.com with ESMTPSA id h17-v6sm36555915pfj.125.2018.11.14.18.11.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Nov 2018 18:11:20 -0800 (PST) Date: Wed, 14 Nov 2018 18:11:18 -0800 From: Brian Norris To: yamada.masahiro@socionext.com Cc: Alexander Kapshuk , sky@genki.is, yamada.masahiro@socionext.com, Doug Anderson , Guenter Roeck , lists@nerdbynature.de, Linux Kernel , schwab@linux-m68k.org Subject: [PATCH v3] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks Message-ID: <20181115021116.GA195691@google.com> References: <20181111.174140.002789201@genki.is> <20181113000938.GA16783@google.com> <20181113190335.GA50985@google.com> <878t1w7hzi.fsf@igel.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Christian Kujau Cc: Guenter Roeck Suggested-by: Alexander Kapshuk Signed-off-by: Brian Norris --- 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 (\?) --- 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