From 01265b684382261524c6624cf4c82afd0adbfa64 Mon Sep 17 00:00:00 2001 From: Sedge Date: Mon, 18 May 2026 08:32:31 -0500 Subject: [PATCH 1/3] Use libgit2 OID hex size constant --- src/cmd/log.zig | 2 +- src/cmd/show.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/log.zig b/src/cmd/log.zig index 9db0b52..8d4a1b3 100644 --- a/src/cmd/log.zig +++ b/src/cmd/log.zig @@ -28,7 +28,7 @@ pub fn run(repo: *c.git_repository, human: bool, count: usize, w: *Writer) !void const raw_summary = c.git_commit_summary(commit); const summary: []const u8 = if (raw_summary != null) std.mem.span(raw_summary) else "(empty)"; - var oid_buf: [c.GIT_OID_SHA1_HEXSIZE + 1]u8 = undefined; + var oid_buf: [c.GIT_OID_HEXSZ + 1]u8 = undefined; _ = c.git_oid_tostr(&oid_buf, oid_buf.len, &oid); const short_hash = oid_buf[0..7]; diff --git a/src/cmd/show.zig b/src/cmd/show.zig index 58db90b..e822f28 100644 --- a/src/cmd/show.zig +++ b/src/cmd/show.zig @@ -38,7 +38,7 @@ pub fn run(repo: *c.git_repository, human: bool, stat: bool, rev: ?[]const u8, w try git.check(c.git_commit_lookup(&commit, repo, &oid)); defer c.git_commit_free(commit); - var oid_buf: [c.GIT_OID_SHA1_HEXSIZE + 1]u8 = undefined; + var oid_buf: [c.GIT_OID_HEXSZ + 1]u8 = undefined; _ = c.git_oid_tostr(&oid_buf, oid_buf.len, &oid); const short_hash = oid_buf[0..7]; const raw_summary = c.git_commit_summary(commit); From f4a8a0b1a76ef1332ad21454cf9be4d34bdd2b88 Mon Sep 17 00:00:00 2001 From: sedge-bot Date: Sat, 30 May 2026 18:40:03 -0500 Subject: [PATCH 2/3] Harden conformance harness portability --- tests/conformance.sh | 68 +++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/tests/conformance.sh b/tests/conformance.sh index b636617..594fb0c 100755 --- a/tests/conformance.sh +++ b/tests/conformance.sh @@ -26,7 +26,7 @@ TMPDIR=$(mktemp -d -t nit-conformance-XXXXXX) trap "rm -rf $TMPDIR" EXIT cd "$TMPDIR" -git init -q +git init -q -b main git config user.email "test@test.com" git config user.name "Test User" @@ -131,6 +131,39 @@ check() { fi } +stat_body_additions() { + "$NIT" show --stat "$1" 2>&1 \ + | tail -n +3 \ + | grep -o '+[0-9]*' \ + | tr -d '+' \ + | awk '{sum += $1} END {print sum + 0}' +} + +stat_summary_additions() { + "$NIT" show --stat "$1" 2>&1 \ + | sed -n '2p' \ + | grep -o '+[0-9]*' \ + | tr -d '+' +} + +hex_dump() { + od -An -tx1 -v | tr -d ' \n' + echo +} + +script_tty() { + if script -q -c "true" /dev/null >/dev/null 2>&1; then + local quoted="" + local arg + for arg in "$@"; do + quoted+="$(printf '%q' "$arg") " + done + script -q -c "$quoted" /dev/null + else + script -q /dev/null "$@" + fi +} + echo "=== nit conformance tests ===" echo "repo: $TMPDIR" echo "" @@ -383,8 +416,8 @@ check "show --stat initial commit has additions" \ # Stat per-file totals add up to summary check "show --stat totals consistent" \ - "$NIT show --stat $FIRST_HASH 2>&1 | tail -n +3 | grep -o '+[0-9]*' | tr -d '+' | paste -sd+ - | bc" \ - "$NIT show --stat $FIRST_HASH 2>&1 | sed -n '2p' | grep -o '+[0-9]*' | tr -d '+'" + "stat_body_additions $FIRST_HASH" \ + "stat_summary_additions $FIRST_HASH" # --- Merge commit --- echo "" @@ -724,8 +757,8 @@ printf '\x00\x01\x02\x03BINARY\xff\xfe' > binary.dat git add binary.dat git commit -q -m "Add binary file" check "show HEAD:binary.dat matches git" \ - "git show HEAD:binary.dat | xxd" \ - "$NIT show HEAD:binary.dat 2>&1 | xxd" + "git show HEAD:binary.dat | hex_dump" \ + "$NIT show HEAD:binary.dat 2>&1 | hex_dump" # --- NIT_COLORS env var --- echo "" @@ -735,9 +768,9 @@ echo "NIT_COLORS:" # Verify that NIT_COLORS changes output when running in a TTY if command -v script >/dev/null 2>&1; then # Without NIT_COLORS: default colors in TTY - default_out=$(script -q /dev/null $NIT show -H 2>&1 | cat -v | head -3) + default_out=$(script_tty "$NIT" show -H 2>&1 | cat -v | head -3) # With NIT_COLORS: custom hash color (magenta = 35) - custom_out=$(script -q /dev/null env NIT_COLORS="hash=35" $NIT show -H 2>&1 | cat -v | head -3) + custom_out=$(script_tty env NIT_COLORS="hash=35" "$NIT" show -H 2>&1 | cat -v | head -3) if [ "$default_out" != "$custom_out" ]; then PASS=$((PASS + 1)) @@ -775,7 +808,7 @@ if command -v script >/dev/null 2>&1; then "NIT_COLORS='hash=38;2;255;165;0' $NIT log -n 1 2>&1" # Verify true-color actually produces escape sequence in TTY - truecolor_out=$(script -q /dev/null env NIT_COLORS="hash=38;2;255;0;0" $NIT show -H 2>&1 | cat -v | head -1) + truecolor_out=$(script_tty env NIT_COLORS="hash=38;2;255;0;0" "$NIT" show -H 2>&1 | cat -v | head -1) if echo "$truecolor_out" | grep -q '38;2;255;0;0'; then PASS=$((PASS + 1)) echo " PASS: NIT_COLORS true-color escape in TTY output" @@ -797,8 +830,8 @@ if command -v script >/dev/null 2>&1; then "NIT_COLORS='boguskey=32' $NIT log -n 1 2>&1" # Duplicate keys (last wins) - verify output changes with second value - dup_out1=$(script -q /dev/null env NIT_COLORS="hash=35" $NIT show -H 2>&1 | cat -v | head -1) - dup_out2=$(script -q /dev/null env NIT_COLORS="hash=33:hash=35" $NIT show -H 2>&1 | cat -v | head -1) + dup_out1=$(script_tty env NIT_COLORS="hash=35" "$NIT" show -H 2>&1 | cat -v | head -1) + dup_out2=$(script_tty env NIT_COLORS="hash=33:hash=35" "$NIT" show -H 2>&1 | cat -v | head -1) if [ "$dup_out1" = "$dup_out2" ]; then PASS=$((PASS + 1)) echo " PASS: NIT_COLORS duplicate keys (last wins)" @@ -836,7 +869,7 @@ if command -v script >/dev/null 2>&1; then "NIT_COLORS='add=31:del=32:hunk=33:context=34:staged=35:unstaged=36:hash=37:date=38:add=39:del=40:hunk=41:context=42' $NIT log -n 1 2>&1" # NIT_COLORS affects show -H (color slot: hash, date used in show) - custom_show=$(script -q /dev/null env NIT_COLORS="hash=35" $NIT show -H 2>&1 | cat -v | head -1) + custom_show=$(script_tty env NIT_COLORS="hash=35" "$NIT" show -H 2>&1 | cat -v | head -1) if [ "$default_out" != "$custom_show" ] || echo "$custom_show" | grep -q '35m'; then PASS=$((PASS + 1)) echo " PASS: NIT_COLORS affects show -H" @@ -847,8 +880,8 @@ if command -v script >/dev/null 2>&1; then fi # NIT_COLORS affects diff -H (color slot: add, del, hunk, context) - default_diff=$(script -q /dev/null $NIT diff -H 2>&1 | cat -v | head -3) - custom_diff=$(script -q /dev/null env NIT_COLORS="add=35:del=36" $NIT diff -H 2>&1 | cat -v | head -3) + default_diff=$(script_tty "$NIT" diff -H 2>&1 | cat -v | head -3) + custom_diff=$(script_tty env NIT_COLORS="add=35:del=36" "$NIT" diff -H 2>&1 | cat -v | head -3) if [ "$default_diff" != "$custom_diff" ]; then PASS=$((PASS + 1)) echo " PASS: NIT_COLORS affects diff -H" @@ -859,8 +892,8 @@ if command -v script >/dev/null 2>&1; then fi # NIT_COLORS affects log -H (color slot: hash, date) - default_log=$(script -q /dev/null $NIT log -H -n 1 2>&1 | cat -v | head -1) - custom_log=$(script -q /dev/null env NIT_COLORS="hash=35:date=36" $NIT log -H -n 1 2>&1 | cat -v | head -1) + default_log=$(script_tty "$NIT" log -H -n 1 2>&1 | cat -v | head -1) + custom_log=$(script_tty env NIT_COLORS="hash=35:date=36" "$NIT" log -H -n 1 2>&1 | cat -v | head -1) if [ "$default_log" != "$custom_log" ]; then PASS=$((PASS + 1)) echo " PASS: NIT_COLORS affects log -H" @@ -871,8 +904,8 @@ if command -v script >/dev/null 2>&1; then fi # NIT_COLORS affects status -H (color slot: staged, unstaged) - default_status=$(script -q /dev/null $NIT status -H 2>&1 | cat -v) - custom_status=$(script -q /dev/null env NIT_COLORS="staged=35:unstaged=36" $NIT status -H 2>&1 | cat -v) + default_status=$(script_tty "$NIT" status -H 2>&1 | cat -v) + custom_status=$(script_tty env NIT_COLORS="staged=35:unstaged=36" "$NIT" status -H 2>&1 | cat -v) if [ "$default_status" != "$custom_status" ]; then PASS=$((PASS + 1)) echo " PASS: NIT_COLORS affects status -H" @@ -1077,3 +1110,4 @@ if [ $FAIL -gt 0 ]; then printf "$ERRORS" exit 1 fi + From 47ed47f208480ac094fe0b06724aa37345335805 Mon Sep 17 00:00:00 2001 From: sedge Date: Tue, 2 Jun 2026 08:37:35 -0500 Subject: [PATCH 3/3] Trim conformance harness EOF blank line --- tests/conformance.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/conformance.sh b/tests/conformance.sh index 594fb0c..ce5e8b7 100755 --- a/tests/conformance.sh +++ b/tests/conformance.sh @@ -1110,4 +1110,3 @@ if [ $FAIL -gt 0 ]; then printf "$ERRORS" exit 1 fi -