svn_git_init 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # From inside the SVN subdir you want to extract:
  2. set -euo pipefail
  3. DEST="${1:-trunk-git}"
  4. echo "Exporting SVN working copy to $DEST (versioned files only)..."
  5. rm -rf -- "$DEST"
  6. # Optionally compute total items upfront for a rough percentage
  7. total_items=""
  8. if total=$(svn list -R . 2>/dev/null | wc -l || true); then
  9. total_items="$total"
  10. fi
  11. start_ts="$(date +%s.%N)"
  12. # Run export in background so we can emit our own progress based on files created.
  13. svn export --quiet . "$DEST" &
  14. export_pid=$!
  15. last_reported=-1
  16. while kill -0 "$export_pid" 2>/dev/null; do
  17. if [[ -d "$DEST" ]]; then
  18. current=$(find "$DEST" -mindepth 1 -print | wc -l)
  19. else
  20. current=0
  21. fi
  22. # Only log when count changes to reduce noise.
  23. if [[ "$current" -ne "$last_reported" ]]; then
  24. now="$(date +%s.%N)"
  25. 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}')
  26. pct=""
  27. if [[ -n "$total_items" && "$total_items" -gt 0 ]]; then
  28. pct=$(awk -v c="$current" -v t="$total_items" 'BEGIN{printf(" (%.1f%%)", (c*100)/t)}')
  29. fi
  30. printf "[%ss] Exported %d items%s\n" "$elapsed" "$current" "$pct"
  31. last_reported="$current"
  32. fi
  33. sleep 1
  34. done
  35. wait "$export_pid"
  36. final_count=$(find "$DEST" -mindepth 1 -print | wc -l 2>/dev/null || echo 0)
  37. end_now="$(date +%s.%N)"
  38. 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}')
  39. printf "[%ss] Exported %d items (done)\n" "$end_elapsed" "$final_count"
  40. cd "$DEST"
  41. git init
  42. git config init.defaultBranch trunk || true
  43. git add -A
  44. git commit -m "Import SVN snapshot" || true