From patchwork Wed Aug 29 03:26:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Genki Sky X-Patchwork-Id: 10579519 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A55A913B8 for ; Wed, 29 Aug 2018 03:33:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C2F82877B for ; Wed, 29 Aug 2018 03:33:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CE8B287E6; Wed, 29 Aug 2018 03:33:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDED32877B for ; Wed, 29 Aug 2018 03:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726479AbeH2H1u (ORCPT ); Wed, 29 Aug 2018 03:27:50 -0400 Received: from genki.is ([104.200.25.21]:55038 "EHLO genki.is" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725199AbeH2H1t (ORCPT ); Wed, 29 Aug 2018 03:27:49 -0400 X-Greylist: delayed 401 seconds by postgrey-1.27 at vger.kernel.org; Wed, 29 Aug 2018 03:27:49 EDT Received: by genki.is (OpenSMTPD) with ESMTP id 4e56714e; Wed, 29 Aug 2018 03:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=genki.is; h=date :mime-version:content-transfer-encoding:content-type:message-id :from:subject:to:cc; s=dkim; bh=srvBZHwP8KleAYvijAbCaX/P25A=; b= lFD4EA/0g2zGvu4JjvbFioPWc+SJMaCTQPZDGEGfm0AS8dyQh1C16hq9p9xGkH57 Tji8X9AmbSzmrvLoHGonKQ9PUOIjXXsa+RG4Oz9TBT2NnsMkXafuN31gugnNw67x D8Ew062GVXrfYYFrf8Rk7xbyNBMbMRXZzhI/HvJm9DpUJCMLg/2pYbAuIMx0PLFV 2qqljijrlU6gtSVFAAxrz5XbMywg+eGPTD7TAJ9IZhW6gfOCZ4l0OkoAgjRhJh6B pOh8EEfyS4HMDMEsRQtwJR8GFPDgwQtriWwcmgk+HBf/t9u6/vyjp8EmZPln9Hbt d63Msu0cEAC2Wvr3pXah3w== Received: by genki.is (OpenSMTPD) with ESMTPSA id 70b6869e (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Wed, 29 Aug 2018 03:26:26 +0000 (UTC) Date: Tue, 28 Aug 2018 23:26:24 -0400 MIME-Version: 1.0 Message-Id: From: Genki Sky Subject: [PATCH] scripts/setlocalversion: git: Make -dirty check more robust To: linux-kbuild@vger.kernel.org Cc: Christian Kujau , Elazar Leibovich , Junio C Hamano , Masahiro Yamada , Michal Marek , Nico Schottelius Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP $(git diff-index) relies on the index being refreshed. This refreshing of the index used to happen, but was removed in cdf2bc632ebc ("scripts/setlocalversion on write-protected source tree", 2013-06-14) due to issues with a read-only filesystem. If the index is not refreshed, one runs into problems. E.g. as described in [0], git stores the uid in its index, so even if just the uid has changed (or git is tricked into thinking so), then we will think the tree is dirty. So as in [1], if you package linux-git with a system that uses fakeroot(1), you get a "-dirty" version. Unless you manually $(git update-index --refresh) themselves. The simplest solution seems to be $(git status --porcelain), with an additional flag saying "ignore untracked files". It seems clearer about what it does, and avoids issues regarding cached indexes and writable filesystems, but still has stable output for scripting. [0]: https://public-inbox.org/git/0190ae30-b6c8-2a8b-b1fb-fd9d84e6dfdf@oracle.com/ [1]: https://bbs.archlinux.org/viewtopic.php?id=236702 Signed-off-by: Genki Sky --- Notes: Testing: I ran $(git status -uno .... && echo dirty) after each of the following commands, checking sanity: % > Makefile % git checkout Makefile % chmod -w .git % > scripts/package/Makefile % chmod +w .git % git checkout scripts/package/Makefile % touch new_file % touch scripts/package/new_file % rm new_file scripts/package/new_file % mv Makefile .clang-format % git checkout Makefile .clang-format scripts/setlocalversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.18.0 diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 71f39410691b..79f7dd57d571 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -74,7 +74,7 @@ scm_version() fi # Check for uncommitted changes - if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then + if git status -uno --porcelain | grep -qv '^.. scripts/package'; then printf '%s' -dirty fi