feat: thread SVN auth (username/password) through all svn call sites
This commit is contained in:
+10
-6
@@ -177,6 +177,7 @@ def _build_tree_from_changes(
|
||||
changes: List[Tuple],
|
||||
svn_url: str,
|
||||
revision: int,
|
||||
auth_args: Optional[List[str]] = None,
|
||||
) -> str:
|
||||
"""Build a new Git tree by applying SVN changes to the parent tree.
|
||||
|
||||
@@ -202,7 +203,7 @@ def _build_tree_from_changes(
|
||||
# ── 2. Apply changes ──────────────────────────────────────
|
||||
for action, kind, rel_path, full_path, cf_path, cf_rev in changes:
|
||||
if action in ("A", "M") and kind == "file":
|
||||
content = svn_get_file(svn_url, full_path, revision)
|
||||
content = svn_get_file(svn_url, full_path, revision, auth_args=auth_args)
|
||||
blob_oid = _git_bytes(git_dir, "hash-object", "-w", "--stdin",
|
||||
input=content, timeout=60)
|
||||
entries[rel_path] = ("100644", blob_oid)
|
||||
@@ -218,7 +219,7 @@ def _build_tree_from_changes(
|
||||
|
||||
elif action == "R" and kind == "file":
|
||||
entries.pop(rel_path, None)
|
||||
content = svn_get_file(svn_url, full_path, revision)
|
||||
content = svn_get_file(svn_url, full_path, revision, auth_args=auth_args)
|
||||
blob_oid = _git_bytes(git_dir, "hash-object", "-w", "--stdin",
|
||||
input=content, timeout=60)
|
||||
entries[rel_path] = ("100644", blob_oid)
|
||||
@@ -311,7 +312,8 @@ def _find_copy_source(cfg, db, changes) -> Optional[str]:
|
||||
# ─── Per-revision sync ────────────────────────────────────────
|
||||
|
||||
|
||||
def sync_svn_revision(mirror: Mirror, revision: int) -> bool:
|
||||
def sync_svn_revision(mirror: Mirror, revision: int,
|
||||
auth_args: Optional[List[str]] = None) -> bool:
|
||||
"""Translate a single SVN revision into Git commit(s).
|
||||
|
||||
Returns True if at least one Git commit was created.
|
||||
@@ -320,7 +322,7 @@ def sync_svn_revision(mirror: Mirror, revision: int) -> bool:
|
||||
git_dir = str(mirror.canonical_dir)
|
||||
|
||||
# Fetch SVN metadata
|
||||
log_entry = svn_get_log(cfg.svn.url, revision)
|
||||
log_entry = svn_get_log(cfg.svn.url, revision, auth_args=auth_args)
|
||||
branch_changes = group_changes_by_branch(log_entry.paths, cfg.svn)
|
||||
|
||||
if not branch_changes:
|
||||
@@ -348,6 +350,7 @@ def sync_svn_revision(mirror: Mirror, revision: int) -> bool:
|
||||
# Build new tree
|
||||
new_tree = _build_tree_from_changes(
|
||||
git_dir, parent_hash, changes, cfg.svn.url, revision,
|
||||
auth_args=auth_args,
|
||||
)
|
||||
|
||||
# Map author
|
||||
@@ -423,10 +426,11 @@ def sync_all(mirror: Mirror) -> int:
|
||||
|
||||
|
||||
def _sync_all_impl(mirror: Mirror) -> int:
|
||||
auth_args = mirror.config.svn.auth_args()
|
||||
state_rev = mirror.db.get_state("last_svn_revision")
|
||||
trunk_name = mirror.config.svn.trunk
|
||||
last_rev = int(state_rev) if state_rev else (mirror.db.get_last_svn_revision(trunk_name) or 0)
|
||||
latest_rev = svn_get_latest_revision(mirror.config.svn.url)
|
||||
latest_rev = svn_get_latest_revision(mirror.config.svn.url, auth_args=auth_args)
|
||||
|
||||
if latest_rev <= last_rev:
|
||||
logger.debug("Mirror %s is up to date (r%d)", mirror.config.id, last_rev)
|
||||
@@ -440,7 +444,7 @@ def _sync_all_impl(mirror: Mirror) -> int:
|
||||
count = 0
|
||||
for rev in range(last_rev + 1, latest_rev + 1):
|
||||
try:
|
||||
if sync_svn_revision(mirror, rev):
|
||||
if sync_svn_revision(mirror, rev, auth_args=auth_args):
|
||||
count += 1
|
||||
except Exception:
|
||||
logger.exception("Failed to sync SVN r%d for %s", rev, mirror.config.id)
|
||||
|
||||
Reference in New Issue
Block a user