From patchwork Thu Oct 26 08:18:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 10027723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E582E6022E for ; Thu, 26 Oct 2017 08:19:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D447C28D1A for ; Thu, 26 Oct 2017 08:19:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C709728D48; Thu, 26 Oct 2017 08:19:48 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 247D628D1A for ; Thu, 26 Oct 2017 08:19:48 +0000 (UTC) Received: from localhost ([::1]:51595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7dOF-0001cn-BR for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 Oct 2017 04:19:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7dN4-0001aj-Ga for qemu-devel@nongnu.org; Thu, 26 Oct 2017 04:18:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7dMz-0000ft-W8 for qemu-devel@nongnu.org; Thu, 26 Oct 2017 04:18:33 -0400 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:50111) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7dMz-0000fN-Od for qemu-devel@nongnu.org; Thu, 26 Oct 2017 04:18:29 -0400 Received: by mail-io0-x241.google.com with SMTP id n137so3830015iod.6 for ; Thu, 26 Oct 2017 01:18:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ozlabs-ru.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=QtG/ttAIs9uCvua19Oq5q2CHk77Rd6yWXSYo4IrjnZk=; b=Ot9GV07jpIP7p+jhRVr9/Zyj554AF3fyhTKi7OZqeev748+5f0o+nG7PKmJUbvOsW5 hacxd6Wr+dEU8mnWprNQQ9DgaLnFt1a4Cd/QTJT9H3Hc1Zv0U4dXIZxNOqoRVJGMfgzy TedcoXtXb8iIhEcJL8O+eok3FPJQgXCLHKWChSV5RjSDcHYrOEtye/MjySUhzTgBZKOz kIRYNmbuu4DSZ490RgXs6Qd/PNn7ovu8Op4kpRuvxSFH+3E2eV5+snar9Ju6PHwp29eK nrHNTUhkpxKpliSDxNNxsk2EHVsVKFQz7ouor1yRM072UTf46zruDTA3ayd7TpiUIQKr FORg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QtG/ttAIs9uCvua19Oq5q2CHk77Rd6yWXSYo4IrjnZk=; b=WwNT48AYpz16BQdj/xIBZqEHL4KF/Pd8JKavHfuutXpu8TnPqVC2epCiwLrxYZhzgD hXD5P2UBV3ZH7Pg9LTECtLmJ4flqkiDFVdfBQOM4Fn8vyrmojsYl0pNyOyzED5jNrtAF MKb2oFuEfYYzTD5312+BtHAfLvIh2UybukyasSXh68qHJNNA0Ei+qagOEAb2JxjQ8u/p Zvp7o2Tl5H2U1e14WpMNw75Hp2AZXOgTk3MSAbbwsixagIj9T6SJVL1mKqOK23rGAGnf VK7TtdmdSWHA9igjw6xPxawY2rngnj+PVLWmMaoKPGWCIYvpBowd5DKklXn0T75Vu9ya 73NA== X-Gm-Message-State: AMCzsaXB9a4DLA5Ltn6SSOIXFEXwMFu1cPrtiZmBgm8x3JD8c+ne+brr LBIY25zi40yOXlDgR2aaRbOtKA== X-Google-Smtp-Source: ABhQp+TUE90L1OsWVeHm6e43zdapLUY2AxDZDd4q+jcJAVmYv35ZhkAVxLnxe01V3rM8/lMvSqVxXg== X-Received: by 10.107.129.149 with SMTP id l21mr31544810ioi.193.1509005909071; Thu, 26 Oct 2017 01:18:29 -0700 (PDT) Received: from [10.61.2.175] ([122.99.82.10]) by smtp.googlemail.com with ESMTPSA id z8sm454095itc.41.2017.10.26.01.18.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Oct 2017 01:18:28 -0700 (PDT) To: qemu-devel@nongnu.org, Darren Kenny References: <20171026013445.45605-1-aik@ozlabs.ru> <20171026071317.y3qjb2rsire25bz3@starbug-vm.ie.oracle.com> From: Alexey Kardashevskiy Message-ID: <8e81eed1-d16a-a289-f07e-4a083e232b79@ozlabs.ru> Date: Thu, 26 Oct 2017 19:18:24 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171026071317.y3qjb2rsire25bz3@starbug-vm.ie.oracle.com> Content-Language: en-AU X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::241 Subject: Re: [Qemu-devel] [PATCH qemu v2] git-submodule.sh: Do not try writing to source directory if not necessary X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 26/10/17 18:13, Darren Kenny wrote: > Hi Alexey, > > On Thu, Oct 26, 2017 at 12:34:45PM +1100, Alexey Kardashevskiy wrote: >> The new git-submodule.sh script writes .git-submodule-status to >> the source directory every time no matter what. This makes it conditional. >> >> Signed-off-by: Alexey Kardashevskiy >> --- >> Changes: >> v2: >> * fixed "status" branch too >> --- >> scripts/git-submodule.sh | 15 ++++++++++----- >> 1 file changed, 10 insertions(+), 5 deletions(-) >> >> diff --git a/scripts/git-submodule.sh b/scripts/git-submodule.sh >> index d8fbc7e47e..ae038d2e58 100755 >> --- a/scripts/git-submodule.sh >> +++ b/scripts/git-submodule.sh >> @@ -23,16 +23,21 @@ then >>     exit 1 >> fi >> >> +substat_tmp=$(mktemp) >> + >> case "$command" in >> status) >>     test -f "$substat" || exit 1 >> -    trap "rm -f ${substat}.tmp" EXIT >> -    git submodule status $modules > "${substat}.tmp" >> -    diff "${substat}" "${substat}.tmp" >/dev/null >> -    exit $? >> +    git submodule status $modules > "$substat_tmp" >> +    diff "${substat_tmp}" "${substat}" > /dev/null >>     ;; >> update) >>     git submodule update --init $modules 1>/dev/null 2>&1 >> -    git submodule status $modules > "${substat}" >> +    git submodule status $modules > "$substat_tmp" >> +    diff "${substat_tmp}" "${substat}" || mv "${substat_tmp}" "${substat}" > > Maybe you intended this, but the diff output here will be output to > the screen - if you don't mean this to happen you might want to > redirect the output. Well, if I do: Is this good enough to repost? ps. out of curiosity - your mail has "Mail-Followup-To" - is that intentional? > > Thanks, > > Darren. > >> +exit $myret >> --  >> 2.11.0 >> >> diff "${substat_tmp}" "${substat}" 1>/dev/null 2>&1 || mv "${substat_tmp}" "${substat}" mv: inter-device move failed: '/tmp/tmp.gfcsXCSv4W' to '.git-submodule-status'; unable to remove target: Read-only file system and with my current variant it is: GIT ui/keycodemapdb dtc 1d0 < 558cd81bdd432769b59bff01240c44f82cfb1a9d dtc (v1.4.4) 2a2 > 558cd81bdd432769b59bff01240c44f82cfb1a9d dtc (v1.4.4) mv: inter-device move failed: '/tmp/tmp.4ol9mymsZj' to '.git-submodule-status'; unable to remove target: Read-only file system which gives some clue about what is going on (I swapped 2 lines in .git-submodule-status to trigger this). > > From other lines it looks like you would prefer it wasn't output. > >>     ;; >> esac >> + >> +myret=$? > > Any small change is likely to break the value of myret here. > > You may want to put the above assignment as directly below the > commands that you want to record as the exit status, and maybe > initialize it before the case statement to the default value. > > For example, if somehow (not sure it's possible today) $command was > not one of the values in the case statement, the value of $? here > would be the return value of mktemp, which may not be your > intention. > > >> +rm "${substat_tmp}" 2>/dev/null > > Rather than doing this redirect, a simple rm -f will achieve what > you want here - that is why makefiles tend to use it. I really do not like shell :) I gave up to using "trap", seems doing the right thing and no messing is needed with "exit". diff --git a/scripts/git-submodule.sh b/scripts/git-submodule.sh index d8fbc7e47e..12f80c14a0 100755 --- a/scripts/git-submodule.sh +++ b/scripts/git-submodule.sh @@ -23,16 +23,18 @@ then exit 1 fi +substat_tmp=$(mktemp) +trap "rm -f $substat_tmp" 0 + case "$command" in status) test -f "$substat" || exit 1 - trap "rm -f ${substat}.tmp" EXIT - git submodule status $modules > "${substat}.tmp" - diff "${substat}" "${substat}.tmp" >/dev/null - exit $? + git submodule status $modules > "$substat_tmp" + diff "${substat_tmp}" "${substat}" > /dev/null ;; update) git submodule update --init $modules 1>/dev/null 2>&1 - git submodule status $modules > "${substat}" + git submodule status $modules > "$substat_tmp" + diff "${substat_tmp}" "${substat}" || mv "${substat_tmp}" "${substat}" ;; esac