From patchwork Sun Jan 22 14:14:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 46949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1169623wrn; Sun, 22 Jan 2023 06:17:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXuITznWXqud+1poAvlojYq7V62i3BEzO1GIkJI5BMkFxlP5LRQDSJQOmob97qsvoPbEdu3Z X-Received: by 2002:a17:907:8c06:b0:7c1:a0e:1607 with SMTP id ta6-20020a1709078c0600b007c10a0e1607mr24693948ejc.12.1674397022881; Sun, 22 Jan 2023 06:17:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674397022; cv=none; d=google.com; s=arc-20160816; b=GepzptGXO+BayBOb8eWvRWw33HCDeIS7Dk2yyuQm8vDxUUrl6tRjgt9hYTwxvRFVEb Br77874R4AkIvOlPSScDiuUvra/RLIFhBtGiJQZltuTEXZpN6A09LhmR6JtjhcAEVd8k 9hdyMMAqCg4T0k78S+e/U19AZbPdOJVFgn6zNZmE9V0Ty1mduWBO0VlyiCcFS0rA71hA Ar8i9jz8BIay41aluVOudHXT62yHXhkYWK8EaO6sWvYmnzBV7S3KrlbjCDptOMadl4ur UHXUE38653Xm30S/mjOjtSnnW+va8am5HPg0rgNjbnE+wUXWlWwgkXZhVm1puYsUoIQd J32A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ksd/SJhyg0NIAMYgGJKOiU9eak2PCaFmhsoJcrKFiVU=; b=oE5iCeucQXyXotPGPrBn3mN1flKnXDggTMdYHrbUbI/s0/eVfV5dPJKE0irDN37qtF fMDClIRZx8F8m4g8Na9Cq5djHMTzk3ReZvs+C94fIDkxf40jWAaD2ev3eRUfco7+tZb2 4W61p2YeBeLqtIlRLOd7PCMtOLYxa4Bb0IttS3hiG741XN80jKjq6Mm2DrZm7XX4TIYN tH5YdqHa+okw/6s6hgoR3ju/m54UW36I5KhzS8gMhaibRAaXvteZW2ltX6p44NpFmJTM M+IZYp2NCdHMDWReE0Z78yVYGKX+dHzyxpHG1n5CIyJpaqh5FaTPJKm3KvZLBMjypl/g I93g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fJ0O049/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne35-20020a1709077ba300b008722ef50e43si19013552ejc.925.2023.01.22.06.16.39; Sun, 22 Jan 2023 06:17:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fJ0O049/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjAVOOp (ORCPT + 99 others); Sun, 22 Jan 2023 09:14:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbjAVOOk (ORCPT ); Sun, 22 Jan 2023 09:14:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8D7610406; Sun, 22 Jan 2023 06:14:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 96ADAB80AE0; Sun, 22 Jan 2023 14:14:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6661BC433D2; Sun, 22 Jan 2023 14:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674396876; bh=SlZozu6ilR07Tjhnx/kZyFTMO+EN6Gn/UTedC9bFFfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJ0O049/CuHxs0De475Oabnp1r21608SN07nlFaFJlkyHVEzeMQ4/Z3E0P+a0z1jh NLX2aRwzUDqOP2P35CBFj7fbVuQl6mqGevmRlXVKernXyqTdyZfw12V+KoY0Moxq1Q 1DtqvrMY7zDrmiAnPD/Y2fKSs3HT9GRXaHiZHcIDI2wM1se8CEje/TrLhVtdmSjsl+ /gv789zFRyK86qCAamcAPM2sH6Afgo/Kz1VqhXY49zzC0FoIYU5HOOe8yHyTSHi+O8 aGGk9ZYGVX//PKLoXvFoGoW+C892PNj+SfnEKKEz8Cc8JejPXcxEYcnTB91nGpXZ9Q Q4n2tYDf3gNUg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes , Masahiro Yamada Subject: [PATCH 3/7] setlocalversion: make indentation shallower Date: Sun, 22 Jan 2023 23:14:23 +0900 Message-Id: <20230122141428.115372-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230122141428.115372-1-masahiroy@kernel.org> References: <20230122141428.115372-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755732532791352885?= X-GMAIL-MSGID: =?utf-8?q?1755732532791352885?= Return earlier if we are not in the correct git repository. This makes the code more readable. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/setlocalversion | 79 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 5cdf409204aa..b8e1018d611e 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -34,46 +34,49 @@ scm_version() short=true fi - # Check for git and a git repo. - if test -z "$(git rev-parse --show-cdup 2>/dev/null)" && - head=$(git rev-parse --verify HEAD 2>/dev/null); then - - # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore - # it, because this version is defined in the top level Makefile. - if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then - - # If only the short version is requested, don't bother - # running further git commands - if $short; then - echo "+" - return - fi - # If we are past a tagged commit (like - # "v2.6.30-rc5-302-g72357d5"), we pretty print it. - if atag="$(git describe 2>/dev/null)"; then - echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}' - fi - - # Add -g and exactly 12 hex chars. - printf '%s%s' -g "$(echo $head | cut -c1-12)" - fi + if test -n "$(git rev-parse --show-cdup 2>/dev/null)"; then + return + fi + + if ! head=$(git rev-parse --verify HEAD 2>/dev/null); then + return + fi + + # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it + # because this version is defined in the top level Makefile. + if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then - # Check for uncommitted changes. - # This script must avoid any write attempt to the source tree, - # which might be read-only. - # You cannot use 'git describe --dirty' because it tries to - # create .git/index.lock . - # 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 - } | read dummy; then - printf '%s' -dirty + # If only the short version is requested, don't bother + # running further git commands + if $short; then + echo "+" + return fi + # If we are past a tagged commit (like + # "v2.6.30-rc5-302-g72357d5"), we pretty print it. + if atag="$(git describe 2>/dev/null)"; then + echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}' + fi + + # Add -g and exactly 12 hex chars. + printf '%s%s' -g "$(echo $head | cut -c1-12)" + fi + + # Check for uncommitted changes. + # This script must avoid any write attempt to the source tree, which + # might be read-only. + # You cannot use 'git describe --dirty' because it tries to create + # .git/index.lock . + # 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 + } | read dummy; then + printf '%s' -dirty fi }