# From inside the SVN subdir you want to extract: set -euo pipefail DEST="${1:-trunk-git}" echo "Exporting SVN working copy to $DEST (versioned files only)..." rm -rf -- "$DEST" # Optionally compute total items upfront for a rough percentage total_items="" if total=$(svn list -R . 2>/dev/null | wc -l || true); then total_items="$total" fi start_ts="$(date +%s.%N)" # Run export in background so we can emit our own progress based on files created. svn export --quiet . "$DEST" & export_pid=$! last_reported=-1 while kill -0 "$export_pid" 2>/dev/null; do if [[ -d "$DEST" ]]; then current=$(find "$DEST" -mindepth 1 -print | wc -l) else current=0 fi # Only log when count changes to reduce noise. if [[ "$current" -ne "$last_reported" ]]; then now="$(date +%s.%N)" elapsed=$(awk -v s="$start_ts" -v n="$now" 'BEGIN{split(s,sa,".");split(n,na,".");printf "%.1f", (na[1]-sa[1]) + (na[2]-sa[2])/1e9}') pct="" if [[ -n "$total_items" && "$total_items" -gt 0 ]]; then pct=$(awk -v c="$current" -v t="$total_items" 'BEGIN{printf(" (%.1f%%)", (c*100)/t)}') fi printf "[%ss] Exported %d items%s\n" "$elapsed" "$current" "$pct" last_reported="$current" fi sleep 1 done wait "$export_pid" final_count=$(find "$DEST" -mindepth 1 -print | wc -l 2>/dev/null || echo 0) end_now="$(date +%s.%N)" end_elapsed=$(awk -v s="$start_ts" -v n="$end_now" 'BEGIN{split(s,sa,".");split(n,na,".");printf "%.1f", (na[1]-sa[1]) + (na[2]-sa[2])/1e9}') printf "[%ss] Exported %d items (done)\n" "$end_elapsed" "$final_count" cd "$DEST" git init git config init.defaultBranch trunk || true git add -A git commit -m "Import SVN snapshot" || true