Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2828373imu; Mon, 19 Nov 2018 06:45:44 -0800 (PST) X-Google-Smtp-Source: AJdET5caXjWoQwixAE6PsxP0q20wcv/+/NH3U7t0gvLeyvMIVkHDdbciKn/4jDy+HXH0QSnUG4mD X-Received: by 2002:a17:902:aa08:: with SMTP id be8-v6mr22803077plb.294.1542638744485; Mon, 19 Nov 2018 06:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542638744; cv=none; d=google.com; s=arc-20160816; b=s7rVMPki/pj1GmFXUPsVSBysChHFb6Z6cOQGuVri8XK5fb1lZ4h4p/jPEmascHigIS saVrNcJdeCMGU3JHLTOOna6QwF0evIsqflZiROYyTFuQcq6e3Pb4bbajLkFmd0upa1eG 8tB8+TH2inQrqme4MvQDBmf/gULwnTLCaZb1+gsSJzzS57llM3BcwJMOg5NJPUMz+sXG +Ui1237wLger+z7lvifO8o3U0qvwUdcJkANnUxK9znYZt4C3a7NsmkScS+VlNDLhriOh 5l3uu9pq9NawV2OS0p5OVPXURQdcwfKu7q5Y6Oehy/UZsR/MbQ23twdbC36J/A3pbJkO sIhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=W+HmOS41MvFNGmZWp1Sg20VIsCpePisC0GdiMwACNfQ=; b=cHlDIzThUYhypyk4obbYXr6RV1IgsMrd7+fXloLZNR+RD/P9oGaf3fx16OVrfYw9Ow vnQHiCjXunTdmNgGlxf2ARbF+CIw0lNgZegTUrc+UW/RDBWqvKCrfu4nxYELTbWlAU8w 9q8DE+17FOeLKAh5jofl7P8z1V91n6I2bC7lb7ojtcDcWsTPEdtfV/24xQ2O691a0Fjx quvpgnGJFVulelB0fO6vWGKpMxdcrX9LOIormJsXJcLvaLYORp6bLOdkmcorcWIp2SuL tV3qZl6iCy+eLQi8cuUWu6FQSHveBIirLfyRJ7txyEohdoMiqM1STPcx3QUjnN4Uxfhg qdNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=m1elgbwD; 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 a35si1002004pla.226.2018.11.19.06.45.28; Mon, 19 Nov 2018 06:45:44 -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=@nifty.com header.s=dec2015msa header.b=m1elgbwD; 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 S1729581AbeKTBG5 (ORCPT + 99 others); Mon, 19 Nov 2018 20:06:57 -0500 Received: from conssluserg-06.nifty.com ([210.131.2.91]:34158 "EHLO conssluserg-06.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727419AbeKTBG5 (ORCPT ); Mon, 19 Nov 2018 20:06:57 -0500 Received: from mail-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53]) (authenticated) by conssluserg-06.nifty.com with ESMTP id wAJEgjwu025681 for ; Mon, 19 Nov 2018 23:42:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com wAJEgjwu025681 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1542638566; bh=W+HmOS41MvFNGmZWp1Sg20VIsCpePisC0GdiMwACNfQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=m1elgbwDv1PaN6mtmkL1OvpBLU0QZKvmnpp0wxF/JeDA3lEgYuWUUb+Z7pS2ZjDcs l1kfQEab1HnnK310my3W06l9VjNaIng0EWim7cMrSpv9Xl43qzD3ahYEZpQT/6mk4N 4uzCeOjicsY9lozBQ0EDl6HCAr+Z8AXqNXfY+ReWazE92wpWH3jBn52eBTYgvqKIAy c1OIUlmUCmX9c1Z6q0NKQ3pa+qByj1zb9GMMYE33sZI37wBN6rMTbknW1eWuYd1E13 ckcjh+FNLPP0hXjeA1OjkwShxAPMllxW9gafpvXPzJ5kvkLQpFvE4FYXyFRzRVDrTD oxFccR664EqZg== X-Nifty-SrcIP: [209.85.217.53] Received: by mail-vs1-f53.google.com with SMTP id r14so17861261vsc.13 for ; Mon, 19 Nov 2018 06:42:46 -0800 (PST) X-Gm-Message-State: AGRZ1gJhtpMXik47KJeyL1/+Zrowgev2q/rnSMyKxrUooeYMA/8xBLWR MszQRHXML8aLap4kLUNinjs1j7JEyik6xRwrUsc= X-Received: by 2002:a67:485:: with SMTP id 127mr9617960vse.54.1542638564929; Mon, 19 Nov 2018 06:42:44 -0800 (PST) MIME-Version: 1.0 References: <20181111.174140.002789201@genki.is> <20181113000938.GA16783@google.com> <20181113190335.GA50985@google.com> <878t1w7hzi.fsf@igel.home> <20181115021116.GA195691@google.com> In-Reply-To: <20181115021116.GA195691@google.com> From: Masahiro Yamada Date: Mon, 19 Nov 2018 23:42:08 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks To: Brian Norris Cc: Alexander Kapshuk , Genki Sky , Douglas Anderson , Guenter Roeck , Christian Kujau , Linux Kernel Mailing List , schwab@linux-m68k.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 15, 2018 at 11:12 AM Brian Norris 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 > 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 > (\?) > --- 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