refactor: split traversal logic in start_iter for clearer chain/cycle handling

Refactors `startIter` to separate the traversal into two distinct passes: one for chain starts (nodes without left extension) and another specifically targeting cycle nodes. Also simplifies `nextUnitigKmer` by removing the redundant `_at_start_ parameter and unifying traversal direction logic. Updates `UnitigIter` to manage visited marking internally, improving encapsulation and cycle detection reliability.
This commit is contained in:
Eric Coissac
2026-05-02 16:28:44 +02:00
parent 86e9cb7026
commit 0b784242cf
+16 -9
View File
@@ -1,15 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# jj_commit_msg.sh — generate a commit message from the current jj change using aichat # jj_commit_msg.sh — generate a commit message from the current jj change using aichat
# #
# Usage: jj_commit_msg.sh # Usage: jj_commit_msg.sh [REV]
# Summarises each changed file's diff individually, then combines all # Summarises each changed file's diff individually, then combines all
# summaries into a single commit message via aichat. # summaries into a single commit message via aichat.
# REV defaults to `@` (current working copy). Accepts any jj revision:
# `@-`, `lk`, a commit ID, a branch name, etc.
# #
# Typical use: # Typical use:
# jj describe -m "$(jj_commit_msg.sh)" # jj describe -m "$(jj_commit_msg.sh)"
# jj describe -m "$(jj_commit_msg.sh @-)"
# jj describe -m "$(jj_commit_msg.sh lk)"
set -euo pipefail set -euo pipefail
# Optional revision to diff (default: @ = current working copy)
REV="${1:-@}"
# Log to stderr so progress doesn't pollute the commit message on stdout # Log to stderr so progress doesn't pollute the commit message on stdout
log() { printf '\033[1;34m==>\033[0m %s\n' "$*" >&2; } log() { printf '\033[1;34m==>\033[0m %s\n' "$*" >&2; }
info() { printf ' \033[0;37m%s\033[0m\n' "$*" >&2; } info() { printf ' \033[0;37m%s\033[0m\n' "$*" >&2; }
@@ -23,7 +30,7 @@ ok() { printf ' \033[0;32m✓\033[0m %s\n' "$*" >&2; }
_readable_diff() { _readable_diff() {
local file="$1" local file="$1"
local raw_diff local raw_diff
raw_diff=$(jj diff -- "$file") raw_diff=$(jj diff -r "$REV" -- "$file")
[[ -z "$raw_diff" ]] && return 0 [[ -z "$raw_diff" ]] && return 0
# Detect pathological diff: any +/- content line longer than 500 chars # Detect pathological diff: any +/- content line longer than 500 chars
@@ -40,8 +47,8 @@ _readable_diff() {
local pretty_old pretty_new local pretty_old pretty_new
case "$ext" in case "$ext" in
json) json)
pretty_old=$(jj file show -r @- -- "$file" 2>/dev/null | python3 -m json.tool 2>/dev/null || true) pretty_old=$(jj file show -r "$REV@-" -- "$file" 2>/dev/null | python3 -m json.tool 2>/dev/null || true)
pretty_new=$(jj file show -- "$file" 2>/dev/null | python3 -m json.tool 2>/dev/null || true) pretty_new=$(jj file show -r "$REV" -- "$file" 2>/dev/null | python3 -m json.tool 2>/dev/null || true)
;; ;;
js|mjs|cjs|css|ts) js|mjs|cjs|css|ts)
local node_fmt=' local node_fmt='
@@ -56,13 +63,13 @@ _readable_diff() {
.replace(/,\s*/g, ",\n "); .replace(/,\s*/g, ",\n ");
process.stdout.write(out); process.stdout.write(out);
});' });'
pretty_old=$(jj file show -r @- -- "$file" 2>/dev/null | node -e "$node_fmt" 2>/dev/null || true) pretty_old=$(jj file show -r "$REV@-" -- "$file" 2>/dev/null | node -e "$node_fmt" 2>/dev/null || true)
pretty_new=$(jj file show -- "$file" 2>/dev/null | node -e "$node_fmt" 2>/dev/null || true) pretty_new=$(jj file show -r "$REV" -- "$file" 2>/dev/null | node -e "$node_fmt" 2>/dev/null || true)
;; ;;
*) *)
# Generic fallback: fold long lines at 120 chars # Generic fallback: fold long lines at 120 chars
pretty_old=$(jj file show -r @- -- "$file" 2>/dev/null | fold -s -w 120 || true) pretty_old=$(jj file show -r "$REV@-" -- "$file" 2>/dev/null | fold -s -w 120 || true)
pretty_new=$(jj file show -- "$file" 2>/dev/null | fold -s -w 120 || true) pretty_new=$(jj file show -r "$REV" -- "$file" 2>/dev/null | fold -s -w 120 || true)
;; ;;
esac esac
@@ -75,7 +82,7 @@ _readable_diff() {
} }
# Collect changed files in the current working copy change # Collect changed files in the current working copy change
changed_files=$(jj diff --name-only) changed_files=$(jj diff -r "$REV" --name-only)
if [[ -z "$changed_files" ]]; then if [[ -z "$changed_files" ]]; then
echo "No changed files." >&2 echo "No changed files." >&2