|
|
@@ -1,10 +1,17 @@
|
|
|
# From inside the SVN subdir you want to extract:
|
|
|
set -euo pipefail
|
|
|
|
|
|
-DEST="${1:-trunk-git}"
|
|
|
+SRC_DIR="$(pwd)"
|
|
|
+MIRROR_ROOT="${GIT_SVN_MIRROR_ROOT:-$HOME/git_svn_mirror}"
|
|
|
+
|
|
|
+# Derive a collision-resistant mirror name from the full path (unless overridden).
|
|
|
+raw_name="${1:-$(pwd -P)}"
|
|
|
+BASE_NAME="$(printf "%s" "$raw_name" | sed 's#^[\\/]*##; s#[\\/]#_#g')"
|
|
|
+DEST="${MIRROR_ROOT}/${BASE_NAME}"
|
|
|
|
|
|
echo "Exporting SVN working copy to $DEST (versioned files only)..."
|
|
|
rm -rf -- "$DEST"
|
|
|
+mkdir -p "$MIRROR_ROOT"
|
|
|
|
|
|
# Optionally compute total items upfront for a rough percentage
|
|
|
total_items=""
|
|
|
@@ -13,6 +20,11 @@ if total=$(svn list -R . 2>/dev/null | wc -l || true); then
|
|
|
fi
|
|
|
|
|
|
start_ts="$(date +%s.%N)"
|
|
|
+elapsed() {
|
|
|
+ local now
|
|
|
+ now="${1:-$(date +%s.%N)}"
|
|
|
+ awk -v s="$start_ts" -v n="$now" 'BEGIN{split(s,sa,".");split(n,na,".");printf "%.1f", (na[1]-sa[1]) + (na[2]-sa[2])/1e9}'
|
|
|
+}
|
|
|
|
|
|
# Run export in background so we can emit our own progress based on files created.
|
|
|
svn export --quiet . "$DEST" &
|
|
|
@@ -28,13 +40,12 @@ while kill -0 "$export_pid" 2>/dev/null; do
|
|
|
|
|
|
# Only log when count changes to reduce noise.
|
|
|
if [[ "$current" -ne "$last_reported" ]]; then
|
|
|
- now="$(date +%s.%N)"
|
|
|
- elapsed=$(awk -v s="$start_ts" -v n="$now" 'BEGIN{split(s,sa,".");split(n,na,".");printf "%.1f", (na[1]-sa[1]) + (na[2]-sa[2])/1e9}')
|
|
|
+ elapsed_val="$(elapsed)"
|
|
|
pct=""
|
|
|
if [[ -n "$total_items" && "$total_items" -gt 0 ]]; then
|
|
|
pct=$(awk -v c="$current" -v t="$total_items" 'BEGIN{printf(" (%.1f%%)", (c*100)/t)}')
|
|
|
fi
|
|
|
- printf "[%ss] Exported %d items%s\n" "$elapsed" "$current" "$pct"
|
|
|
+ printf "[%ss] Exported %d items%s\n" "$elapsed_val" "$current" "$pct"
|
|
|
last_reported="$current"
|
|
|
fi
|
|
|
|
|
|
@@ -44,12 +55,34 @@ done
|
|
|
wait "$export_pid"
|
|
|
|
|
|
final_count=$(find "$DEST" -mindepth 1 -print | wc -l 2>/dev/null || echo 0)
|
|
|
-end_now="$(date +%s.%N)"
|
|
|
-end_elapsed=$(awk -v s="$start_ts" -v n="$end_now" 'BEGIN{split(s,sa,".");split(n,na,".");printf "%.1f", (na[1]-sa[1]) + (na[2]-sa[2])/1e9}')
|
|
|
-printf "[%ss] Exported %d items (done)\n" "$end_elapsed" "$final_count"
|
|
|
+printf "[%ss] Exported %d items (done)\n" "$(elapsed)" "$final_count"
|
|
|
|
|
|
cd "$DEST"
|
|
|
-git init
|
|
|
+
|
|
|
+echo "[$(elapsed) s] Initializing git repository..."
|
|
|
+GIT_QUIET=1 git init >/dev/null
|
|
|
git config init.defaultBranch trunk || true
|
|
|
+git config core.fileMode false || true
|
|
|
+git config core.autocrlf true || true
|
|
|
+git config core.safecrlf false || true
|
|
|
+
|
|
|
+echo "[$(elapsed) s] Staging files..."
|
|
|
git add -A
|
|
|
-git commit -m "Import SVN snapshot" || true
|
|
|
+
|
|
|
+echo "[$(elapsed) s] Creating initial commit..."
|
|
|
+GIT_QUIET=1 git commit -q -m "Import SVN snapshot" || true
|
|
|
+
|
|
|
+# Reuse the repo for the source working tree by linking .git back to the new repo.
|
|
|
+echo "[$(elapsed) s] Linking git metadata to source working tree..."
|
|
|
+DEST_ABS="$(pwd -P)"
|
|
|
+cd "$SRC_DIR"
|
|
|
+if [[ -e .git || -L .git ]]; then
|
|
|
+ echo "[$(elapsed)s] Replacing existing .git in $SRC_DIR..."
|
|
|
+ rm -rf -- .git
|
|
|
+fi
|
|
|
+printf "gitdir: %s/.git\n" "$DEST_ABS" > .git
|
|
|
+echo "[$(elapsed)s] Linked .git to $DEST_ABS/.git"
|
|
|
+
|
|
|
+# Normalize working tree to match repo filters (e.g., CRLF handling).
|
|
|
+echo "[$(elapsed) s] Syncing working tree to repo content..."
|
|
|
+GIT_QUIET=1 git checkout -q -- .
|