Date: Thu, 18 Feb 2021 16:00:54 GMT From: Mark Johnston <markj@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 57ba8673d7de - main - git-arc: Globally save and restore the git checkout head Message-ID: <202102181600.11IG0sPW086138@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=57ba8673d7de509c9f2d23fdc1a5e179ff4ff3cc commit 57ba8673d7de509c9f2d23fdc1a5e179ff4ff3cc Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2021-02-18 15:59:32 +0000 Commit: Mark Johnston <markj@FreeBSD.org> 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} $@
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102181600.11IG0sPW086138>