Преглед изворни кода

Show elapsed time during svn export

cere пре 1 месец
родитељ
комит
eb4028ff33
1 измењених фајлова са 32 додато и 50 уклоњено
  1. 32 50
      svn_interact/svn_git_init

+ 32 - 50
svn_interact/svn_git_init

@@ -1,55 +1,37 @@
 # From inside the SVN subdir you want to extract:
 # 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")
-      }
+set -euo pipefail
+
+DEST="${1:-trunk-git}"
+
+echo "Exporting SVN working copy to $DEST (versioned files only)..."
+rm -rf -- "$DEST"
+count=0
+start_ts="$(date +%s.%N)"
+svn export . "$DEST" | awk -v start="$start_ts" '
+  function elapsed() {
+    cmd = "date +%s.%N"
+    cmd | getline now
+    close(cmd)
+    split(start, s, ".")
+    split(now, n, ".")
+    return (n[1]-s[1]) + (n[2]-s[2])/1e9
+  }
+  {
+    count++
+    if (count % 50 == 0) {
+      t = elapsed()
+      printf("\r[%.1fs] Exported %d items...", t, count)
+      fflush()
     }
     }
   }
   }
-  END { printf("\n") > "/dev/stderr" }
+  END {
+    t = elapsed()
+    printf("\r[%.1fs] Exported %d items.\n", t, count)
+  }
 '
 '
 
 
-# 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
+cd "$DEST"
+git init
+git config init.defaultBranch trunk || true
+git add -A
+git commit -m "Import SVN snapshot" || true