svn_git_init 1022 B

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