svn_git_init 793 B

12345678910111213141516171819202122232425262728293031323334353637
  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. svn export . "$DEST" | awk -v start="$start_ts" '
  9. function elapsed() {
  10. cmd = "date +%s.%N"
  11. cmd | getline now
  12. close(cmd)
  13. split(start, s, ".")
  14. split(now, n, ".")
  15. return (n[1]-s[1]) + (n[2]-s[2])/1e9
  16. }
  17. {
  18. count++
  19. if (count % 50 == 0) {
  20. t = elapsed()
  21. printf("\r[%.1fs] Exported %d items...", t, count)
  22. fflush()
  23. }
  24. }
  25. END {
  26. t = elapsed()
  27. printf("\r[%.1fs] Exported %d items.\n", t, count)
  28. }
  29. '
  30. cd "$DEST"
  31. git init
  32. git config init.defaultBranch trunk || true
  33. git add -A
  34. git commit -m "Import SVN snapshot" || true