mirror of https://github.com/garrytan/gstack.git
fix: REPO_MODE defaults to unknown when helper emits nothing
- Remove head -20 truncation that biased solo classification by dropping low-volume contributors from the denominator - Use atomic write (mktemp + mv) for cache to prevent concurrent preamble reads from seeing partial JSON Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
51bd9a5a63
commit
f6b8360269
|
|
@ -57,12 +57,13 @@ if [ -z "$DEFAULT_BRANCH" ]; then
|
||||||
DEFAULT_BRANCH="HEAD"
|
DEFAULT_BRANCH="HEAD"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
SHORTLOG=$(git shortlog -sn --since="90 days ago" --no-merges "$DEFAULT_BRANCH" 2>/dev/null | head -20)
|
SHORTLOG=$(git shortlog -sn --since="90 days ago" --no-merges "$DEFAULT_BRANCH" 2>/dev/null)
|
||||||
if [ -z "$SHORTLOG" ]; then
|
if [ -z "$SHORTLOG" ]; then
|
||||||
echo "REPO_MODE=unknown"
|
echo "REPO_MODE=unknown"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Compute TOTAL from ALL authors (not truncated) to avoid solo bias
|
||||||
TOTAL=$(echo "$SHORTLOG" | awk '{s+=$1} END {print s}')
|
TOTAL=$(echo "$SHORTLOG" | awk '{s+=$1} END {print s}')
|
||||||
TOP=$(echo "$SHORTLOG" | head -1 | awk '{print $1}')
|
TOP=$(echo "$SHORTLOG" | head -1 | awk '{print $1}')
|
||||||
AUTHORS=$(echo "$SHORTLOG" | wc -l | tr -d ' ')
|
AUTHORS=$(echo "$SHORTLOG" | wc -l | tr -d ' ')
|
||||||
|
|
@ -82,8 +83,11 @@ else
|
||||||
MODE=collaborative
|
MODE=collaborative
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cache result (fail silently if ~/.gstack is unwritable)
|
# Cache result atomically (fail silently if ~/.gstack is unwritable)
|
||||||
mkdir -p "$CACHE_DIR" 2>/dev/null || true
|
mkdir -p "$CACHE_DIR" 2>/dev/null || true
|
||||||
echo "{\"mode\":\"$MODE\",\"top_pct\":$TOP_PCT,\"authors\":$AUTHORS,\"total\":$TOTAL,\"computed\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" > "$CACHE_FILE" 2>/dev/null || true
|
CACHE_TMP=$(mktemp "$CACHE_DIR/.repo-mode-XXXXXX" 2>/dev/null || true)
|
||||||
|
if [ -n "$CACHE_TMP" ]; then
|
||||||
|
echo "{\"mode\":\"$MODE\",\"top_pct\":$TOP_PCT,\"authors\":$AUTHORS,\"total\":$TOTAL,\"computed\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" > "$CACHE_TMP" 2>/dev/null && mv "$CACHE_TMP" "$CACHE_FILE" 2>/dev/null || rm -f "$CACHE_TMP" 2>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
echo "REPO_MODE=$MODE"
|
echo "REPO_MODE=$MODE"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue