feat: thread SVN auth (username/password) through all svn call sites
This commit is contained in:
+15
-9
@@ -28,7 +28,10 @@ class SVNLogEntry:
|
||||
paths: List[SVNPathChange] = field(default_factory=list)
|
||||
|
||||
|
||||
def _run_svn(args: list, input: bytes = None, timeout: int = 120) -> subprocess.CompletedProcess:
|
||||
def _run_svn(args: list, input: bytes = None, timeout: int = 120,
|
||||
auth_args: Optional[list] = None) -> subprocess.CompletedProcess:
|
||||
if auth_args:
|
||||
args = auth_args + args
|
||||
try:
|
||||
r = subprocess.run(
|
||||
["svn"] + args,
|
||||
@@ -48,9 +51,9 @@ def _run_svn(args: list, input: bytes = None, timeout: int = 120) -> subprocess.
|
||||
return r
|
||||
|
||||
|
||||
def get_latest_revision(url: str) -> int:
|
||||
def get_latest_revision(url: str, auth_args: Optional[list] = None) -> int:
|
||||
"""Return the HEAD revision number of an SVN repository."""
|
||||
r = _run_svn(["info", "--xml", url], timeout=60)
|
||||
r = _run_svn(["info", "--xml", url], timeout=60, auth_args=auth_args)
|
||||
root = ET.fromstring(r.stdout)
|
||||
entry = root.find(".//entry")
|
||||
if entry is None:
|
||||
@@ -61,11 +64,11 @@ def get_latest_revision(url: str) -> int:
|
||||
return int(rev)
|
||||
|
||||
|
||||
def get_log(url: str, revision: int) -> SVNLogEntry:
|
||||
def get_log(url: str, revision: int, auth_args: Optional[list] = None) -> SVNLogEntry:
|
||||
"""Fetch log entry with changed paths for a single SVN revision."""
|
||||
r = _run_svn(
|
||||
["log", "-r", str(revision), "--verbose", "--xml", url],
|
||||
timeout=120,
|
||||
timeout=120, auth_args=auth_args,
|
||||
)
|
||||
root = ET.fromstring(r.stdout)
|
||||
logentry = root.find("logentry")
|
||||
@@ -108,14 +111,15 @@ def get_log(url: str, revision: int) -> SVNLogEntry:
|
||||
)
|
||||
|
||||
|
||||
def get_log_range(url: str, start_rev: int, end_rev: int) -> List[SVNLogEntry]:
|
||||
def get_log_range(url: str, start_rev: int, end_rev: int,
|
||||
auth_args: Optional[list] = None) -> List[SVNLogEntry]:
|
||||
"""Fetch log entries for a range of SVN revisions in one call.
|
||||
|
||||
Returns entries from *start_rev* to *end_rev* (inclusive), oldest first.
|
||||
"""
|
||||
r = _run_svn(
|
||||
["log", "-r", f"{start_rev}:{end_rev}", "--verbose", "--xml", url],
|
||||
timeout=300,
|
||||
timeout=300, auth_args=auth_args,
|
||||
)
|
||||
root = ET.fromstring(r.stdout)
|
||||
entries: List[SVNLogEntry] = []
|
||||
@@ -163,11 +167,13 @@ def get_log_range(url: str, start_rev: int, end_rev: int) -> List[SVNLogEntry]:
|
||||
return entries
|
||||
|
||||
|
||||
def get_file(url: str, path: str, revision: int) -> bytes:
|
||||
def get_file(url: str, path: str, revision: int,
|
||||
auth_args: Optional[list] = None) -> bytes:
|
||||
"""Return the full content of a file at a given SVN revision.
|
||||
|
||||
`path` is the absolute SVN path, e.g. /trunk/src/main.c.
|
||||
"""
|
||||
full_url = url.rstrip("/") + path
|
||||
r = _run_svn(["cat", "-r", str(revision), full_url], timeout=60)
|
||||
r = _run_svn(["cat", "-r", str(revision), full_url], timeout=60,
|
||||
auth_args=auth_args)
|
||||
return r.stdout
|
||||
|
||||
Reference in New Issue
Block a user