Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3071125imu; Sun, 11 Nov 2018 07:04:30 -0800 (PST) X-Google-Smtp-Source: AJdET5dTH3eWLPeYDVCsODZvOl9Cn3BiSj1yQaBhxKbs8zhcNzJ57N/ewzPgBLtXNbbWFqEwCgl3 X-Received: by 2002:a17:902:8ec1:: with SMTP id x1-v6mr16446711plo.130.1541948670798; Sun, 11 Nov 2018 07:04:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541948670; cv=none; d=google.com; s=arc-20160816; b=hfWc3CdC6/YKXw6tHPLYGBnSSfCVdfrdNHzYQQMz1vBXI30HhlOVlivePzx4gT8n71 swDAM6YiRKlKwnrKIG7VjlphsGGmBwIvgmU9ZX58VvWmRJMYFqcVDkXLxXxqEiW67/Uw e5fCFMfqYygo+ZGK2FweAZr9plF/G/LZtmEiB+erkVzYY6ev0nlhgIWcMQja95lD8tsd xOKir2gajLkue+U29uhFANEHP3Vn/AEpIYzd6UiqkJiKAHJlG5aJ1+VYhLLsGpFwXEDI 9EMtR7HY3KO5PqhGckINLtSTBHSpyDaK1Iv1swzMcHrIP9Mg1KcFqG0YSnb6DMARfYfu 6edA== 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; bh=KdKYPchVfzxjkO0ND5MdF2IByIaiZMeiSZQ8D1af/as=; b=SjlhBgaqC93Qt+onQk12eeFQ8r8VpDWV58MJ2YX2AZoreKFoAiNZ038TU5PxVlirjE ao9Q+eSEr+uh+XLw19JI46E8RkxKTGOa7aLfmIiEJgS4g5GHi0caiWEJKwFcs4RBsSnv rDwwRDoX7WKiZNOElIyte07xie1EL7Lnr7FndnWp7zxNRsnrvjwVqBrr+xHyX1Y33nji 8VGPejjn3YopHYdg9yRCyjqEM2Uk2mDPy2ZrUWsMScoKe41iAtUHrm9kLn0TL0ZV3Zt2 A08JCPdegRjvImB2qXMjJsg/WOGB/2PlQY0SK6AEuNc4RzJT7IceP/OxzfvoJzP+bGIy 1VNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GXf7Rwu2; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k35si323811pgm.225.2018.11.11.07.04.09; Sun, 11 Nov 2018 07:04:30 -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=@gmail.com header.s=20161025 header.b=GXf7Rwu2; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728549AbeKLAwf (ORCPT + 99 others); Sun, 11 Nov 2018 19:52:35 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:35955 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728331AbeKLAwf (ORCPT ); Sun, 11 Nov 2018 19:52:35 -0500 Received: by mail-it1-f196.google.com with SMTP id w7-v6so9863757itd.1 for ; Sun, 11 Nov 2018 07:03:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KdKYPchVfzxjkO0ND5MdF2IByIaiZMeiSZQ8D1af/as=; b=GXf7Rwu2lUlmTeFAiD/eV0M//Ruw4xkJWIf2F2bislGO3Vk3jBsUauiiPs3YnhEOLh XKKSX9fVbaAIrfshahskSccXmA54fWpFhXhH3BiulFod7EiQQUtbQSb85xlIq8N/p8g5 6NjZhl3HoWGSQJzX7jBmLpykYcpy3ExgLF6KbflfhMW/WvDmAYY/t9JHe4X5pzqj7ysV UGtFI+H9Gl3X1zvgnMzvXUKOHJgVVMQq98UtnpFzjvPbce+kLoxUkX7CqMC/s45SvnzQ ViN/DnUp2pBvl9CraaL1Oy5psbjGeF3IQ9Me36Z8ihDgQnyaILzK8KHkuu2IAMS8IVI+ hxXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KdKYPchVfzxjkO0ND5MdF2IByIaiZMeiSZQ8D1af/as=; b=IgCcxzQoHGrxtINAHSW9VJzYiJw+W6yQhWcIQw3kaQEJkMl97P12tOUlWcejL/WK+A f69hTlLr5QsLfEtN7YWRtA4rv2X2Xh2FnbUEXVymkpJI/AbdHpfk5x3CAk8kknfhhrAm S7BEvcW2/G4+JW+wLTHGVR5fLrqDCuLLuHSLFKefUETYw3PnFwY2QKPzJ3ICFslSBFwq 5NZfW1hJvZvlATaXNdW4gjM0n2uXubxZW8oQI+9Zx1yRPtwyi0s86XU/Bg4w/81twKQS TEIHpkU1UXdEFI/w9zbs56KQx3UXZ4EB9UzOHJBSo6ewItwGQwJzWaGREmuFgbVSQigN VFqg== X-Gm-Message-State: AGRZ1gJSN8nLUhDRmhrkFCMxQzJRKRi8ppqxcd799ObFcybb5XMlggJt vdZRX4E7jBvL3cxJdkSW7OzNNqm/glADYvBW+bQ= X-Received: by 2002:a24:5e93:: with SMTP id h141-v6mr9175242itb.103.1541948627020; Sun, 11 Nov 2018 07:03:47 -0800 (PST) MIME-Version: 1.0 References: <20181107022156.GA254567@google.com> <20181107184435.GA168339@google.com> <20181107.204358.257636196@genki.is> <20181107205514.GB12273@roeck-us.net> <20181107.210731.330601031@genki.is> <20181109183436.GA45531@google.com> <20181110.085826.230851261@genki.is> <20181110.201050.925673938@genki.is> In-Reply-To: From: Alexander Kapshuk Date: Sun, 11 Nov 2018 17:03:29 +0200 Message-ID: Subject: Re: [PATCH] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks To: sky@genki.is Cc: schwab@linux-m68k.org, briannorris@chromium.org, Masahiro Yamada , dianders@chromium.org, Guenter Roeck , lists@nerdbynature.de, linux-kernel 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 Sun, Nov 11, 2018 at 4:48 PM Alexander Kapshuk wrote: > > On Sat, Nov 10, 2018 at 10:12 PM Genki Sky wrote: > > > > Hi Andreas, > > > > On Sat, 10 Nov 2018 11:42:11 +0100, Andreas Schwab wrote: > > > On Nov 10 2018, Genki Sky wrote: > > > > On Fri, 9 Nov 2018 10:34:37 -0800, Brian Norris wrote: > > > >> + git_status="$(git --no-optional-locks status -uno --porcelain 2>/dev/null)" > > > >> + if [ $? -eq 0 ]; then > > > >> + if echo "$git_status" | grep -qv '^.. scripts/package'; then > > > > > > > > Shouldn't this be: > > > > > > > > if printf '%s' "$git_status" | grep -qv '^.. scripts/package'; then > > > > > > > > I.e., use printf not echo? Because of echo introducing a newline. > > > > > > The input to grep should be a text file, thus should end with a newline. > > > > Ah okay, thanks. I guess GNU grep was being lenient. Well then, I > > think the line at least needs to be changed to: > > > > if [ -n "$git_status" ] && echo "$git_status" | grep -qv '^.. scripts/package'; then > > > > I'm just trying to say that in the proposed patch, if git doesn't > > print anything, the echo adds a newline that wasn't there before. This > > causes the grep -qv to exit with status 0 (because there's at least > > one line that doesn't contain '^.. scripts/package'). Meaning it will > > print dirty. > > Piping the output of the git command to grep and using the return status > of grep as the test condition within the if block, would be sufficient > to determine whether or not '-dirty' should be printed. > > Sample run: > % if git --no-optional-locks \ > status -uno --porcelain \ > 2>/dev/null | > grep -qv '^.. scripts/package' > then > printf '%s' -dirty > fi > % To improve the readability, the git command may be stored in a variable and substituted into a command within the if block like so: % cmd='git --no-optional-locks status -uno --porcelain' % if $cmd 2>/dev/null | grep -qv '^.. scripts/package'; then printf '%s' -dirty fi %