svn_git_init 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. count=0
  7. start_ts="$(date +%s.%N)"
  8. if command -v script >/dev/null 2>&1; then
  9. # script(1) forces a pseudo-tty so svn flushes output immediately
  10. export_cmd=(script -q -c "svn export . \"$DEST\"" /dev/null)
  11. elif command -v stdbuf >/dev/null 2>&1; then
  12. export_cmd=(stdbuf -o0 -e0 svn export . "$DEST")
  13. else
  14. export_cmd=(svn export . "$DEST")
  15. fi
  16. # Keep awk unbuffered too
  17. if command -v stdbuf >/dev/null 2>&1; then
  18. awk_cmd=(stdbuf -o0 awk -v start="$start_ts")
  19. else
  20. awk_cmd=(awk -W interactive -v start="$start_ts")
  21. fi
  22. "${export_cmd[@]}" | "${awk_cmd[@]}" '
  23. function elapsed() {
  24. cmd = "date +%s.%N"
  25. cmd | getline now
  26. close(cmd)
  27. split(start, s, ".")
  28. split(now, n, ".")
  29. return (n[1]-s[1]) + (n[2]-s[2])/1e9
  30. }
  31. {
  32. count++
  33. if (count % 25 == 0) {
  34. t = elapsed()
  35. printf("[%.1fs] Exported %d items\n", t, count)
  36. fflush()
  37. }
  38. }
  39. END {
  40. t = elapsed()
  41. printf("[%.1fs] Exported %d items (done)\n", t, count)
  42. }
  43. '
  44. cd "$DEST"
  45. git init
  46. git config init.defaultBranch trunk || true
  47. git add -A
  48. git commit -m "Import SVN snapshot" || true