From 822da84f802472e621ec61c4c035103f85900599 Mon Sep 17 00:00:00 2001 From: Wesley Bomar Date: Sat, 12 Mar 2022 12:28:01 -0600 Subject: [PATCH 1/5] FP-1544: Annotate Lightweight Tags --- .gitignore | 3 ++ bin/git_annotate_existing_tags.sh | 56 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 bin/git_annotate_existing_tags.sh diff --git a/.gitignore b/.gitignore index e59994e06..9cb357b87 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ *.pyo __pycache__ +# Shell +git_annotate_existing_tags + # Project /public/static /public/media diff --git a/bin/git_annotate_existing_tags.sh b/bin/git_annotate_existing_tags.sh new file mode 100755 index 000000000..0a16f3bdc --- /dev/null +++ b/bin/git_annotate_existing_tags.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# Bug: (2022-03-12) (for a commit after v3.15.0) +# Running `git describe` gave unexpected output. +# - expect: "v3.15.0-…-g…" +# - actual: "v3.7.0-…-g…" +# Why: 1. Most tags after (and before) v3.7.0 were not annotated. Similar: +# https://github.com/Reference-LAPACK/lapack/issues/123 +# 2. Because GitHub uses lightweight tags. Feedback for GitHub: +# https://github.com/github/feedback/discussions/4924 +# Fix: Run this script to retroactively annotate lightweight tags. +# (Note, this script also re-annotates annotated tags.) + +function annotate() { + local date=$1 + local file=$2 + local hash=$3 + + GIT_COMMITTER_DATE=$date \ + git tag --annotate --force --file $file $tag $hash +} + +function save_tag_summary() { + local path=$1 + + echo "$(git tag --format='%(creatordate)%09%(refname:strip=2) %(taggerdate) %(contents)')" > $path +} + +for tag in "$@" +do + # get data for tag (some is new for annotation, some must be preserved) + date="$(echo $(git tag --format='%(creatordate)' --list $tag))" + msg="$(git tag --format='%(contents)' --list $tag)" + hash="$(git rev-list -n 1 $tag)" + + # make output directory + output_dir='_git_annotate_existing_tags' + mkdir -p "$output_dir" + + # save message to file to preserve new lines + msg_file_path="$output_dir/message.temp" + echo "$msg" > $msg_file_path + + # save current status to file for comparison + save_tag_summary "$output_dir/summary_before.temp" + + # show the user what we will do, then do it + echo "Annotate tag $(printf "%9s" $tag) (commit ${hash:0:7}) with date \"$date\" and retain its message \"${msg:0:30}...\"." + annotate "$date" "$msg_file_path" "$hash" + + # save new status to file for comparison + save_tag_summary "$output_dir/summary_after.temp" + + # clean up + rm $msg_file_path +done From aa93787991250e78b69615daa0d1f485551b7da7 Mon Sep 17 00:00:00 2001 From: Wesley Bomar Date: Sat, 12 Mar 2022 12:42:56 -0600 Subject: [PATCH 2/5] FP-1544: Fix Gitignore Addition --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9cb357b87..7ae0ce5bd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ __pycache__ # Shell -git_annotate_existing_tags +_git_annotate_existing_tags # Project /public/static From 3667bc985e8b45ae1d49b71471487f0984ee7777 Mon Sep 17 00:00:00 2001 From: Wesley Bomar Date: Sat, 12 Mar 2022 12:43:23 -0600 Subject: [PATCH 3/5] FP-1544: Fix Tag Summary/Status Output --- bin/git_annotate_existing_tags.sh | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/bin/git_annotate_existing_tags.sh b/bin/git_annotate_existing_tags.sh index 0a16f3bdc..c2814941c 100755 --- a/bin/git_annotate_existing_tags.sh +++ b/bin/git_annotate_existing_tags.sh @@ -11,46 +11,46 @@ # Fix: Run this script to retroactively annotate lightweight tags. # (Note, this script also re-annotates annotated tags.) -function annotate() { - local date=$1 - local file=$2 - local hash=$3 - - GIT_COMMITTER_DATE=$date \ - git tag --annotate --force --file $file $tag $hash -} +# make output directory +OUTPUT_DIR='_git_annotate_existing_tags' +mkdir -p "$OUTPUT_DIR" +# define how to save current status of tag annotation function save_tag_summary() { local path=$1 echo "$(git tag --format='%(creatordate)%09%(refname:strip=2) %(taggerdate) %(contents)')" > $path } -for tag in "$@" -do - # get data for tag (some is new for annotation, some must be preserved) - date="$(echo $(git tag --format='%(creatordate)' --list $tag))" - msg="$(git tag --format='%(contents)' --list $tag)" - hash="$(git rev-list -n 1 $tag)" +# define how to annotate tags (will also re-annotate tags) +function annotate() { + local tag=$1 - # make output directory - output_dir='_git_annotate_existing_tags' - mkdir -p "$output_dir" + # get data for tag (some is new for annotation, some must be preserved) + local date="$(echo $(git tag --format='%(creatordate)' --list $tag))" + local msg="$(git tag --format='%(contents)' --list $tag)" + local hash="$(git rev-list -n 1 $tag)" # save message to file to preserve new lines - msg_file_path="$output_dir/message.temp" + local msg_file_path="$OUTPUT_DIR/message.temp" echo "$msg" > $msg_file_path - # save current status to file for comparison - save_tag_summary "$output_dir/summary_before.temp" - - # show the user what we will do, then do it + # tell the user what we will do echo "Annotate tag $(printf "%9s" $tag) (commit ${hash:0:7}) with date \"$date\" and retain its message \"${msg:0:30}...\"." - annotate "$date" "$msg_file_path" "$hash" - # save new status to file for comparison - save_tag_summary "$output_dir/summary_after.temp" + # annotate + GIT_COMMITTER_DATE=$date \ + git tag --annotate --force --file "$msg_file_path" "$tag" "$hash" # clean up rm $msg_file_path -done +} + +# save current status to file for comparison +save_tag_summary "$OUTPUT_DIR/summary_before.temp" + +# annotate each tag passed +for tag in "$@"; do annotate "$tag"; done + +# save new status to file for comparison +save_tag_summary "$OUTPUT_DIR/summary_after.temp" From 36e702c6afae1803ce435d7044a84ada0ae125a5 Mon Sep 17 00:00:00 2001 From: "W. Bomar" <62723358+tacc-wbomar@users.noreply.github.com> Date: Mon, 14 Mar 2022 14:38:20 -0500 Subject: [PATCH 4/5] Quick: Link to alternatives for the script --- bin/git_annotate_existing_tags.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/git_annotate_existing_tags.sh b/bin/git_annotate_existing_tags.sh index c2814941c..9b1f4307d 100755 --- a/bin/git_annotate_existing_tags.sh +++ b/bin/git_annotate_existing_tags.sh @@ -10,6 +10,8 @@ # https://github.com/github/feedback/discussions/4924 # Fix: Run this script to retroactively annotate lightweight tags. # (Note, this script also re-annotates annotated tags.) +# Alt: See answers to https://stackoverflow.com/q/21738647/11817077 +# (These solutions are more elegant but might not preserve all lines, including new lines, in tag message.) # make output directory OUTPUT_DIR='_git_annotate_existing_tags' From d0dc3ef0c45415be965a1cf5118f8563a5e86c1d Mon Sep 17 00:00:00 2001 From: "W. Bomar" <62723358+tacc-wbomar@users.noreply.github.com> Date: Mon, 14 Mar 2022 14:40:15 -0500 Subject: [PATCH 5/5] Quick: Reduce verbosity of comment from 36e702c --- bin/git_annotate_existing_tags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git_annotate_existing_tags.sh b/bin/git_annotate_existing_tags.sh index 9b1f4307d..6157ba699 100755 --- a/bin/git_annotate_existing_tags.sh +++ b/bin/git_annotate_existing_tags.sh @@ -11,7 +11,7 @@ # Fix: Run this script to retroactively annotate lightweight tags. # (Note, this script also re-annotates annotated tags.) # Alt: See answers to https://stackoverflow.com/q/21738647/11817077 -# (These solutions are more elegant but might not preserve all lines, including new lines, in tag message.) +# (More elegant but may not preserve all of tag message with new lines.) # make output directory OUTPUT_DIR='_git_annotate_existing_tags'