Created
February 2, 2026 23:09
-
-
Save edgarcosta/146113d70f4da096da24e8e8a8633eed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # clone-proper.sh - Clone MAGMA SVN with proper tags/branches as git refs | |
| # | |
| # This creates a git-svn clone where: | |
| # - / (root) is the trunk, excluding Tags/Export/Branches | |
| # - Main branch contains: Prog/, Doc/, Web/ | |
| # - Tags/* become refs/remotes/svn/tags/* | |
| # - Branches/* become refs/remotes/svn/branches/* | |
| # - Export/* become refs/remotes/svn/export/* | |
| # | |
| # git svn fetch/dcommit will continue to work! | |
| set -e | |
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | |
| SVN_URL="${SVN_URL:-file:///home/edgarcosta/magma/mirror}" | |
| REWRITE_ROOT="${REWRITE_ROOT:-svn://magma}" | |
| OUTPUT_DIR="${1:-$SCRIPT_DIR/../../magma-proper}" | |
| AUTHORS_FILE="${AUTHORS_FILE:-$SCRIPT_DIR/authors.txt}" | |
| echo "=== MAGMA git-svn Clone with Proper Layout ===" | |
| echo "SVN URL: $SVN_URL" | |
| echo "Rewrite Root: $REWRITE_ROOT" | |
| echo "Output: $OUTPUT_DIR" | |
| echo "Authors: $AUTHORS_FILE" | |
| echo "" | |
| # Check prerequisites | |
| if ! git svn --version &> /dev/null; then | |
| echo "Error: git-svn not found" | |
| echo "Install with: sudo apt install git-svn" | |
| exit 1 | |
| fi | |
| if [ ! -f "$AUTHORS_FILE" ]; then | |
| echo "Warning: Authors file not found: $AUTHORS_FILE" | |
| echo "Commits will use SVN usernames instead of full names/emails" | |
| echo "" | |
| read -p "Continue without authors file? (y/N) " -n 1 -r | |
| echo | |
| if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
| exit 1 | |
| fi | |
| AUTHORS_ARG="" | |
| else | |
| AUTHORS_ARG="--authors-file=$AUTHORS_FILE" | |
| fi | |
| if [ -d "$OUTPUT_DIR" ]; then | |
| echo "Error: Output directory already exists: $OUTPUT_DIR" | |
| exit 1 | |
| fi | |
| echo "Initializing git-svn..." | |
| git svn init \ | |
| --trunk=/ \ | |
| --tags=Tags \ | |
| --branches=Branches \ | |
| --branches=Export \ | |
| --prefix=svn/ \ | |
| --rewrite-root="$REWRITE_ROOT" \ | |
| "$SVN_URL" "$OUTPUT_DIR" | |
| cd "$OUTPUT_DIR" | |
| # Exclude Tags/Export/Branches from trunk (they're tracked as separate refs) | |
| git config svn-remote.svn.ignore-paths '^(Tags|Export|Branches)/' | |
| echo "" | |
| echo "Configuration:" | |
| git config --get-regexp 'svn-remote' | |
| echo "" | |
| # Performance tuning | |
| git config core.fsync none | |
| git config core.compression 1 | |
| git config pack.threads 0 | |
| git config pack.deltaCacheSize 512m | |
| git config pack.windowMemory 512m | |
| echo "Starting fetch (this will take a while for 72k+ revisions)..." | |
| echo "The fetch is resumable if interrupted - just run 'git svn fetch' again." | |
| echo "" | |
| if [ -n "$AUTHORS_ARG" ]; then | |
| git svn fetch --log-window-size=10000 $AUTHORS_ARG | |
| else | |
| git svn fetch --log-window-size=10000 | |
| fi | |
| echo "" | |
| echo "=== Fetch Complete ===" | |
| echo "" | |
| # Create main branch from trunk | |
| git checkout -b main svn/trunk 2>/dev/null || git checkout main | |
| # Convert remote tags to real git tags | |
| echo "Converting SVN tags to git tags..." | |
| for ref in $(git for-each-ref --format='%(refname:short)' refs/remotes/svn/tags/); do | |
| tag_name=$(echo "$ref" | sed 's|svn/tags/||' | tr '[:upper:]' '[:lower:]') | |
| git tag "$tag_name" "$ref" 2>/dev/null && echo " Created tag: $tag_name" | |
| done | |
| echo "" | |
| echo "=== Summary ===" | |
| echo "Repository: $OUTPUT_DIR" | |
| echo "" | |
| echo "Main branch contents:" | |
| ls -la | |
| echo "" | |
| echo "Commits on main: $(git rev-list --count main 2>/dev/null || echo 'N/A')" | |
| echo "Git tags: $(git tag | wc -l)" | |
| echo "" | |
| echo "Remote refs:" | |
| git for-each-ref --format='%(refname:short)' refs/remotes/svn/ | head -20 | |
| echo "..." | |
| echo "" | |
| echo "=== git-svn commands will work ===" | |
| echo " git svn fetch - pull new SVN commits" | |
| echo " git svn dcommit - push commits to SVN" | |
| echo " git svn rebase - rebase on latest SVN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment