From patchwork Wed Jan 15 16:59:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 182843 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp7141290ile; Wed, 15 Jan 2020 08:59:46 -0800 (PST) X-Google-Smtp-Source: APXvYqzNe5QoZK5SRUeOEKNgENYvy89esgaBECdL/dfZ1p3PdsDPRC52NvgbJI4RTQaFOTksSdOU X-Received: by 2002:aca:5fc6:: with SMTP id t189mr609938oib.166.1579107585986; Wed, 15 Jan 2020 08:59:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579107585; cv=none; d=google.com; s=arc-20160816; b=istZYPhtlq9HbaHx29/uUKrwVCtHB6zEgFwckaiX+2CroMrO8v5JrgR5I7hUm3Jtq+ OWapPPtEn/HoGO6QC8dwy0BJpsBUw3qYilJ6poVpq4guy4c4xCjx+dPBarKbz7z7wTTR fDMYZA5TMXiddvBGyYKEKLPihWKpiG6BMNHVJtnulwSEgP1vtWP51bwoh7UF9+dVRpRm tLY52kXbNH9Oa4fbLmE05l/DrcugSQ1064TNJkD8s1pTzoIl4//SVgt5/Oqh6Q7E+rnp Ma+cX5XvBX3Q8E2Bf8Tdcu7lncQihfNhqnqlx2YD/G9yBb9Hj/C+217f7SxH+ZYkdkRN vKjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:date:message-id:subject:from:to :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=+hU9vAkAWO7v22V+hOQwTm16wQPr47mEtaFP1V69wNk=; b=sslSitetX7vHemxL+SByyQTK49af6kmwyu2Qtdd9H8QdI6GIuArqxtgFdXkGLA3pHq U9V5vPDeasQOBtxzGy/rM51k2bc9nLjcMalkr9YUa/bpRZu92UfWd7kjmOKlsGnqQK9M mOGKfSqkk36hOTWqJA7HOuEeZp4dVu3WmiyIOkXwkdTelRVx/Y4Gsi5yzvLKtHMN2GZ4 3uP2ogUbgjmSN9nRFzwoMAEMNAf4Ug4F9o6hNWhxuDmQ3uwtl14BlV4a7sZB6KxKxUBi mrA560/c4Ihztt2BRkuMb835ImnvF63QOk8UNgRJU9G4Orc5XFtJd0EGaJFTrxE6Gku/ UASg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nhOWhqKw; spf=pass (google.com: domain of gcc-patches-return-517456-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-517456-patch=linaro.org@gcc.gnu.org" Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f15si9835962oij.160.2020.01.15.08.59.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jan 2020 08:59:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-517456-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nhOWhqKw; spf=pass (google.com: domain of gcc-patches-return-517456-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-517456-patch=linaro.org@gcc.gnu.org" DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=koygt7Bzr8MtTSOgldqvt4jQjt2JKl/cfjcABer9fxx0VsN96K VjQ12x9F5aP1AUhofzOq/YkPi6/Tn90hsk2VulTnnjiOIov11ylgJZiCPN/KY1WM jeLLjnNyNywGG9emKB3wO8vGiJo0bSeChcxvDA1uacIzB6WcGORUaWwjs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=7UURYpyNiQxp1U0lMWaAIRwyKDM=; b=nhOWhqKwX9bIfrokoo8f vIf24e+N6VGUU8X6mEnezEELavU5FDu+3Gk2nGq/CWsqOQ33b6X3EQcyTgL6DWCb rZ/8vPELxnFk0/mF0mM1uC0hJ5/mq9VAntDQn/sLLFczZqqfSLoY7gdU6/sJkUzK /nYjLN1HbU7mQuQTM++gBFM= Received: (qmail 21240 invoked by alias); 15 Jan 2020 16:59:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 21230 invoked by uid 89); 15 Jan 2020 16:59:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:5078 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Jan 2020 16:59:23 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C397C328; Wed, 15 Jan 2020 08:59:21 -0800 (PST) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.78.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3AE4B3F6C4; Wed, 15 Jan 2020 08:59:21 -0800 (PST) To: "gcc-patches@gcc.gnu.org" From: "Richard Earnshaw (lists)" Subject: contrib: Check and if needed set user.name and user.email in gcc-git-customization.sh Message-ID: Date: Wed, 15 Jan 2020 16:59:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 As discussed on IRC, this adds a couple more checks in the customization setup for git. If the variables user.name and user.email are not set anywhere in the git config hierarchy, we set some local values. We always ask about the values we detect and if the user gives an answer that is new, we save that in the local config: this gives the opportunity to use different values to those configured for the global space. I've also cleaned up a couple of minor niggles, such as using $() rather than `` for subshells and some quoting issues when using eval. * gcc-git-customization.sh: Use $() instead of ``, and fix variable quoting with eval. Set user.name and user.email if not found in the local or config. diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh index dae2c35bb57..60694fd8cc0 100755 --- a/contrib/gcc-git-customization.sh +++ b/contrib/gcc-git-customization.sh @@ -11,12 +11,49 @@ ask () { read answer if [ "x$answer" = "x" ] then - eval $var=$default + eval $var=\"$default\" else - eval $var=$answer + eval $var=\"$answer\" fi } +# Search the git config in multiple scopes upto the level specified. +# Start in --local, if not set there then try global, then system. +get_conf_upto () { + if [ $# -ne 3 ] + then + echo "get_conf_upto --local|--global|--system " + exit 1 + fi + opt=$1 + conf=$2 + result=$3 + case $opt in + --local|--global|--system) ;; + *) echo "get_conf_upto --local|--global|--system " + exit 1 + ;; + esac + v=$(git config --get --local $conf) + if [ -n "$v" -o "$opt" = "--local" ] + then + eval $result=\"$v\" + return + fi + + v=$(git config --get --global $conf) + if [ -n "$v" -o "$opt" = "--global" ] + then + eval $result=\"$v\" + return + fi + + v=$(git config --get --system $conf) + eval $result=\"$v\" + return +} + + # Add a git command to find the git commit equivalent to legacy SVN revision NNN git config alias.svn-rev '!f() { rev=$1; shift; git log --all --grep="From-SVN: r\\?$rev\\b" "${@}"; } ; f' @@ -30,7 +67,52 @@ git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream) # *.md diff=md git config diff.md.xfuncname '^\(define.*$' -upstream=`git config --get "gcc-config.upstream"` +get_conf_upto --global "user.name" set_user +get_conf_upto --global "user.email" set_email + +if [ "x$set_user" = "x" ] +then + # Try to guess the user's name by looking it up in the password file + new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }') + if [ "x$new_user" = "x" ] + then + new_user="(no default)" + fi +else + new_user=$set_user +fi +ask "Your name" "${new_user}" new_user +if [ "x$new_user" = "x(no default)" ] +then + echo "Cannot continue, git needs to record your name against commits" + exit 1 +fi + +if [ "x$set_email" = "x" ] +then + new_email="(no_default)" +else + new_email=$set_email +fi + +ask "Your email address (for git commits)" "${new_email}" new_email +if [ "x$new_email" = "x(no default)" ] +then + echo "Cannot continue, git needs to record your email address against commits" + exit 1 +fi + +if [ "x$set_user" != "x$new_user" ] +then + git config "user.name" "$new_user" +fi + +if [ "x$set_email" != "x$new_email" ] +then + git config "user.email" "$new_email" +fi + +upstream=$(git config --get "gcc-config.upstream") if [ "x$upstream" = "x" ] then upstream="origin" @@ -38,27 +120,27 @@ fi ask "Local name for upstream repository" "origin" upstream git config "gcc-config.upstream" "$upstream" -remote_id=`git config --get "gcc-config.user"` +remote_id=$(git config --get "gcc-config.user") if [ "x$remote_id" = "x" ] then # See if the url specifies the remote user name. - url=`git config --get "remote.$upstream.url"` + url=$(git config --get "remote.$upstream.url") if [ "x$url" = "x" ] then # This is a pure guess, but for many people it might be OK. - remote_id=`whoami` + remote_id=$(whoami) else - remote_id=`echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|"` + remote_id=$(echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|") if [ x$remote_id = x$url ] then - remote_id=`whoami` + remote_id=$(whoami) fi fi fi ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id git config "gcc-config.user" "$remote_id" -old_pfx=`git config --get "gcc-config.userpfx"` +old_pfx=$(git config --get "gcc-config.userpfx") if [ "x$old_pfx" = "x" ] then old_pfx="me" @@ -72,7 +154,7 @@ echo "Setting up tracking for personal namespace $remote_id in remotes/$upstream git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/${upstream}/${new_pfx}/*" ":refs/remotes/${upstream}/${old_pfx}/" git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/${new_pfx}/*" ":refs/tags/${old_pfx}/" -push_rule=`git config --get "remote.${upstream}.push"` +push_rule=$(git config --get "remote.${upstream}.push") if [ "x$push_rule" != "x" ] then echo "***********************************************"