From e7adb3e88b2965392d55c2b8b4097759ead4ba4a Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Fri, 2 Oct 2026 14:41:26 +0300 Subject: [PATCH] Latest review note --- scripts/review-note | 19 +++++++++++++++++++ scripts/review-note-test | 21 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/scripts/review-note b/scripts/review-note index 24587d3..3e2dafc 100755 --- a/scripts/review-note +++ b/scripts/review-note @@ -57,12 +57,31 @@ cmd_write() { fi } +cmd_latest() { + local branch="${1:-$(git branch --show-current)}" + local blob obj note br rnd best="" best_round=-1 + while read -r blob obj; do + note=$(git notes --ref="$NOTES_REF" show "$obj") || continue + br=$(sed -n 's/^branch: //p' <<<"$note") + [ "$br" = "$branch" ] || continue + rnd=$(sed -n 's/^round: //p' <<<"$note") + [[ "$rnd" =~ ^[0-9]+$ ]] || continue + if [ "$rnd" -gt "$best_round" ]; then + best_round=$rnd + best=$note + fi + done < <(git notes --ref="$NOTES_REF" list) + [ -n "$best" ] || die "no review notes for branch: $branch" + printf '%s\n' "$best" +} + main() { local cmd="${1:-}" if [ $# -gt 0 ]; then shift; fi case "$cmd" in show) cmd_show "$@" ;; write) cmd_write "$@" ;; + latest) cmd_latest "$@" ;; *) usage ;; esac } diff --git a/scripts/review-note-test b/scripts/review-note-test index 4eca429..4749c01 100755 --- a/scripts/review-note-test +++ b/scripts/review-note-test @@ -49,4 +49,23 @@ sed 's/^verdict: request-changes/verdict: approve/' "$note" > "$tmp/note1b" "$rn" write "$tmp/note1b" --force "$rn" show | grep -q '^verdict: approve$' || fail "show should print the replaced note" -echo "ok: show/write" +# latest finds the note by branch, even from a newer unreviewed tip +echo three > c.txt && git add c.txt && git commit -qm three +"$rn" latest main | grep -q '^verdict: approve$' || fail "latest should find the round 1 note" + +# a note for another branch must not leak into the result +sed -e 's/^branch: main/branch: other/' -e 's/^round: 1/round: 9/' "$tmp/note1b" > "$tmp/other" +"$rn" write "$tmp/other" +"$rn" latest main | grep -q '^verdict: approve$' || fail "latest should ignore other branches" + +# round 2 on the new tip wins and carries previous (replaces the +# other-branch note on the same commit, so --force) +PREV=$(git rev-parse HEAD~1) +sed -e 's/^round: 1/round: 2/' -e "s/^previous: none/previous: $PREV/" "$tmp/note1b" > "$tmp/note2" +"$rn" write "$tmp/note2" --force +"$rn" latest main | grep -q '^round: 2$' || fail "latest should pick the highest round" +"$rn" latest main | grep -q "^previous: $PREV$" || fail "round 2 should carry previous" + +if "$rn" latest nosuch >/dev/null 2>&1; then fail "latest should exit 1 for an unknown branch"; fi + +echo "ok: show/write/latest"