| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- # From inside the SVN subdir you want to extract:
- # Discover URLs (works on older svn too)
- REPO_ROOT="$(svn info --show-item repos-root-url 2>/dev/null || svn info | awk -F': ' '/^Repository Root:/ {print $2; exit}')"
- CURR_URL="$(svn info --show-item url 2>/dev/null || svn info | awk -F': ' '/^URL:/ {print $2; exit}')"
- # Find FIRST and HEAD that touched *this* path
- FIRST_REV="$(svn log -q --stop-on-copy "$CURR_URL" | awk '/^r[0-9]+/ {rev=$1} END {sub(/^r/,"",rev); print rev}')"
- [[ -z "$FIRST_REV" ]] && FIRST_REV=1
- HEAD_REV="$(svn info -r HEAD "$CURR_URL" 2>/dev/null | awk -F': ' '/^Revision:/ {print $2; exit}')"
- [[ -z "$HEAD_REV" ]] && HEAD_REV="$(svn log -q -r HEAD "$CURR_URL" | awk '/^r[0-9]+/ {sub(/^r/,"",$1); print $1; exit}')"
- TOTAL=$(( HEAD_REV - FIRST_REV + 1 ))
- (( TOTAL > 0 )) || { echo "Nothing to import (HEAD < FIRST)"; exit 0; }
- TARGET_DIR="trunk-git"
- rm -rf -- "$TARGET_DIR"
- # Init against the *subdir* URL (no ignore-paths needed)
- git svn init --no-minimize-url --no-metadata "$CURR_URL" "$TARGET_DIR"
- cd "$TARGET_DIR"
- # Optional cosmetics
- git config init.defaultBranch trunk || true
- # Stream fetch with live percentage (no --verbose needed)
- echo "Importing SVN history with progress..."
- git svn fetch -r "${FIRST_REV}:HEAD" 2>&1 | \
- awk -v first="$FIRST_REV" -v last="$HEAD_REV" -v total="$TOTAL" '
- BEGIN { imported=0 }
- { print $0
- if ($1 ~ /^r[0-9]+$/ && $2 == "=") {
- rev = substr($1,2)
- if (rev >= first && rev <= last) {
- imported++
- pct = int((imported*100)/total)
- printf("\r[%3d%%] Imported %d/%d revisions (r%d)", pct, imported, total, rev) > "/dev/stderr"
- fflush("/dev/stderr")
- }
- }
- }
- END { printf("\n") > "/dev/stderr" }
- '
- # Optional: make this subdir the repo root (should already be, since we targeted the subdir URL)
- # If you still see extra path components, you can use:
- # if command -v git-filter-repo >/dev/null 2>&1; then
- # git filter-repo --force
- # fi
- # Rename branch to trunk (if needed)
- curr_branch="$(git symbolic-ref --short HEAD 2>/dev/null || true)"
- if [[ -n "$curr_branch" && "$curr_branch" != "trunk" ]]; then
- git branch -m trunk || true
- fi
|