Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5747617imu; Tue, 13 Nov 2018 11:05:17 -0800 (PST) X-Google-Smtp-Source: AJdET5diuCxWB1dRvi7a4SXkyOxSjs9HB3M9qS+B2AtrHdP4Tol6EwxXUSrau2mgC385ufbq3M+b X-Received: by 2002:a63:fd12:: with SMTP id d18-v6mr5944610pgh.164.1542135917117; Tue, 13 Nov 2018 11:05:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542135917; cv=none; d=google.com; s=arc-20160816; b=nrf3NJkqfX+a4YswKgQpUkXcZNO25g3yOCeO4+fsGSUimdfJJ7mkrNnDRxoje4sIrC R91DQrzLRaEECYKxugHxAORhI768onjpywP/CQfxmhLjzbm/g/QulJCK/6vMjrDDyJrY eNTpvyje8KXAivHQoL+TgB2vqN/Bnb/hccfYcpJpjmXRieWXRiXECNQHO9P5YIO8tE/H BAjdPjtizFLEHYAUj9Y42D8OIIybgVpNqtQOGZf5CegQqQycMGaQTML668L9Mqeb1peo D17B8zNSMSB/OZkIy0sQ0lbI64tra9GYmhfrvKA+nIVKE6DgckyoygMBOY0SzJxLHUHo 5y5Q== 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=01PCAwDbzKcdC5J29DOuEyf8Kjg21XeQWU8yKoiwgus=; b=tDGfRVdSxyGa2gDrtKi7SFNXDHBmMppqCagmjiENghRqroZBkaRFIN6U3Nlq6FM4O2 wBfr/tKNaYB4CXRkIR1Z0B453UP9vbgKO3stRiIHweojR/rvkpD0qLqpgu4aefhcEuxH nb0NcKGhEP33ZvGTieskWxniqW3m9LPB4LhjfWioWx124SUqD1e3uGYzT4jt0j0QU/LS hSGO4gawlBFHyC/VbZZgyKjBsw5/McHcLFavl9x09X3TD6RJsD3Ox0bcqe6p9MPzaFWD X8b5Hubu+yZYuXSuAKvQeaDOEU2H9W0A8CHIKsxWtVG0FMQ1F9qBhMNslgCiW0t8vhFr sJuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="c/zCrSvh"; 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 e11si15323953pgf.450.2018.11.13.11.04.43; Tue, 13 Nov 2018 11:05:17 -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="c/zCrSvh"; 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 S1727974AbeKNFDH (ORCPT + 99 others); Wed, 14 Nov 2018 00:03:07 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:47069 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725892AbeKNFDH (ORCPT ); Wed, 14 Nov 2018 00:03:07 -0500 Received: by mail-pg1-f195.google.com with SMTP id w7so6109055pgp.13 for ; Tue, 13 Nov 2018 11:03:40 -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=01PCAwDbzKcdC5J29DOuEyf8Kjg21XeQWU8yKoiwgus=; b=c/zCrSvhcUBp21GOMXqM5rEv/YiR243jO9zjg5zz7FZy5cUKsVgQKeKkk2pBvJs+Dt ZKOaszBmLKxSmIgRYE/sccb5aI7GULjwyc3w44TbEnVd4N6vw3pk57imGsVjMIjTaLAI EMeKHTAxMs4KOU9Ds9ABQPg+GDyJ05S1n/w3E= 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=01PCAwDbzKcdC5J29DOuEyf8Kjg21XeQWU8yKoiwgus=; b=jdwk0jSpwNx6qI1eaMkRtyp6/BtHU8cDnhzQ3ZX+6PD4ClTZd31o+loky21DFYb5MR E4lxhCnrR3QkO1Mm4ane8mKIU2cTjnZJO0qU+vSJIjikPDmvPKIcx56z4c2XKxgK1eug s3O/PRFQ0O85Pw893RoWdGZDWbm4Ju0GYFTVxRiPNNcOg09451/+g6yMgNd1d9OJ59RO rvTcCzDNyM5Ot22Av2x63qG3jaBxPbxnkr8oh+2YfEjRclpgT3aFQmhQJ1H1/21if/Zy W9BdxXIUpOqqVShSEQGwCxoGcOQiqX4DL3Ig+ifjNRSPvAA10CO7WXVktjF5JeRKs3RJ TRqw== X-Gm-Message-State: AGRZ1gLwfd9JLmT1wt4oLzyh42FQyrs67HkLlAWPUk7CpXEJt+wv5rQ+ K8pqg6k1Nwm8jUGoSpZ8N8RcyA== X-Received: by 2002:a62:fc52:: with SMTP id e79mr6460383pfh.8.1542135820093; Tue, 13 Nov 2018 11:03:40 -0800 (PST) Received: from google.com ([2620:15c:202:1:299d:6b87:5478:d28a]) by smtp.gmail.com with ESMTPSA id v191sm26362389pgb.77.2018.11.13.11.03.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Nov 2018 11:03:39 -0800 (PST) Date: Tue, 13 Nov 2018 11:03:36 -0800 From: Brian Norris To: alexander.kapshuk@gmail.com Cc: sky@genki.is, schwab@linux-m68k.org, yamada.masahiro@socionext.com, Doug Anderson , Guenter Roeck , lists@nerdbynature.de, Linux Kernel Subject: [PATCH v2] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks Message-ID: <20181113190335.GA50985@google.com> References: <20181110.085826.230851261@genki.is> <20181110.201050.925673938@genki.is> <20181111.174140.002789201@genki.is> <20181113000938.GA16783@google.com> 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 --- On Tue, Nov 13, 2018 at 10:32:16AM -0800, Brian Norris wrote: > I can submit it. I expect Masahiro-san would prefer a proper v2 patch > for review, given how much would change from my v1. Done 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 scripts/setlocalversion | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 71f39410691b..2190de4b57ad 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 -qv '^\(.. \)\?scripts/package'; then printf '%s' -dirty fi -- 2.19.1.930.g4563a0d9d0-goog