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:
@@ -1,15 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
# 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
|
||||
# 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:
|
||||
# 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
|
||||
|
||||
# Optional revision to diff (default: @ = current working copy)
|
||||
REV="${1:-@}"
|
||||
|
||||
# Log to stderr so progress doesn't pollute the commit message on stdout
|
||||
log() { printf '\033[1;34m==>\033[0m %s\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() {
|
||||
local file="$1"
|
||||
local raw_diff
|
||||
raw_diff=$(jj diff -- "$file")
|
||||
raw_diff=$(jj diff -r "$REV" -- "$file")
|
||||
[[ -z "$raw_diff" ]] && return 0
|
||||
|
||||
# Detect pathological diff: any +/- content line longer than 500 chars
|
||||
@@ -40,8 +47,8 @@ _readable_diff() {
|
||||
local pretty_old pretty_new
|
||||
case "$ext" in
|
||||
json)
|
||||
pretty_old=$(jj file show -r @- -- "$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_old=$(jj file show -r "$REV@-" -- "$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)
|
||||
local node_fmt='
|
||||
@@ -56,13 +63,13 @@ _readable_diff() {
|
||||
.replace(/,\s*/g, ",\n ");
|
||||
process.stdout.write(out);
|
||||
});'
|
||||
pretty_old=$(jj file show -r @- -- "$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_old=$(jj file show -r "$REV@-" -- "$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
|
||||
pretty_old=$(jj file show -r @- -- "$file" 2>/dev/null | fold -s -w 120 || true)
|
||||
pretty_new=$(jj file show -- "$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 -r "$REV" -- "$file" 2>/dev/null | fold -s -w 120 || true)
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -75,7 +82,7 @@ _readable_diff() {
|
||||
}
|
||||
|
||||
# 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
|
||||
echo "No changed files." >&2
|
||||
|
||||
Reference in New Issue
Block a user