From owner-dev-commits-src-all@freebsd.org Thu Feb 18 16:00:54 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 46FDF53DFB1; Thu, 18 Feb 2021 16:00:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DhKF21PDNz4kWS; Thu, 18 Feb 2021 16:00:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 22E7E1AFEC; Thu, 18 Feb 2021 16:00:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 11IG0sKm086139; Thu, 18 Feb 2021 16:00:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11IG0sPW086138; Thu, 18 Feb 2021 16:00:54 GMT (envelope-from git) Date: Thu, 18 Feb 2021 16:00:54 GMT Message-Id: <202102181600.11IG0sPW086138@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 57ba8673d7de - main - git-arc: Globally save and restore the git checkout head MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 57ba8673d7de509c9f2d23fdc1a5e179ff4ff3cc Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Feb 2021 16:00:54 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=57ba8673d7de509c9f2d23fdc1a5e179ff4ff3cc commit 57ba8673d7de509c9f2d23fdc1a5e179ff4ff3cc Author: Mark Johnston AuthorDate: 2021-02-18 15:59:32 +0000 Commit: Mark Johnston CommitDate: 2021-02-18 16:00:09 +0000 git-arc: Globally save and restore the git checkout head This script uses -e, so it's prone to exiting in awkward places. In particular, if arc diff fails, the script just exits without restoring the checkout. Mitigate this for now by using a global variable to record the previous checkout and use a trap handler to restore it in the face of errors. A better solution might be to use arc diff's --head parameter but that will require more testing. Reported by: kevans Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D28631 --- tools/tools/git/git-arc.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/tools/git/git-arc.sh b/tools/tools/git/git-arc.sh index e8c84ea672f7..2de7e1858c00 100644 --- a/tools/tools/git/git-arc.sh +++ b/tools/tools/git/git-arc.sh @@ -29,7 +29,6 @@ # TODO: # - roll back after errors or SIGINT -# - current checkout # - created revs # - main (for git arc stage) @@ -320,20 +319,20 @@ show_and_prompt() save_head() { - local commit orig + local orig if ! orig=$(git symbolic-ref --short -q HEAD); then orig=$(git show -s --pretty=%H HEAD) fi - echo $orig + SAVED_HEAD=$orig } restore_head() { - local orig - - orig=$1 - git checkout -q $orig + if [ -n "$SAVED_HEAD" ]; then + git checkout -q $SAVED_HEAD + SAVED_HEAD= + fi } build_commit_list() @@ -353,8 +352,7 @@ build_commit_list() gitarc::create() { - local commit commits doprompt list o orig prev reviewers - local subscribers + local commit commits doprompt list o prev reviewers subscribers list= if eval $(git config --bool --default false --get arc.list); then @@ -391,7 +389,7 @@ gitarc::create() doprompt= fi - orig=$(save_head) + save_head prev="" for commit in ${commits}; do if create_one_review "$commit" "$reviewers" "$subscribers" "$prev" \ @@ -401,7 +399,7 @@ gitarc::create() prev="" fi done - restore_head $orig + restore_head } gitarc::list() @@ -501,7 +499,7 @@ gitarc::stage() gitarc::update() { - local commit diff orig + local commit diff commit=$1 diff=$(commit2diff $commit) @@ -510,7 +508,8 @@ gitarc::update() return fi - orig=$(save_head) + save_head + git checkout -q $commit # The linter is stupid and applies patches to the working copy. @@ -518,7 +517,7 @@ gitarc::update() # names. arc diff --allow-untracked --never-apply-patches --update $diff HEAD~ - restore_head $orig + restore_head } set -e @@ -591,4 +590,6 @@ if eval $(git config --bool --default false --get arc.browse); then BROWSE=--browse fi +trap restore_head EXIT INT + gitarc::${verb} $@