MCPcopy
hub / github.com/tirth8205/code-review-graph / get_changed_files

Function get_changed_files

code_review_graph/incremental.py:493–527  ·  view source on GitHub ↗

Get list of changed files via git diff or svn status. For SVN working copies the *base* parameter is ignored; modified/added/ deleted files are detected from ``svn status``. Pass an SVN revision range (e.g. ``"r100:HEAD"``) as *base* to compare against a specific revision instead.

(repo_root: Path, base: str = "HEAD~1")

Source from the content-addressed store, hash-verified

491
492
493def get_changed_files(repo_root: Path, base: str = "HEAD~1") -> list[str]:
494 """Get list of changed files via git diff or svn status.
495
496 For SVN working copies the *base* parameter is ignored; modified/added/
497 deleted files are detected from ``svn status``. Pass an SVN revision
498 range (e.g. ``"r100:HEAD"``) as *base* to compare against a specific
499 revision instead.
500 """
501 if detect_vcs(repo_root) == "svn":
502 return _get_svn_changed_files(repo_root, base if _SAFE_SVN_REV.match(base) else None)
503 # Git path
504 if not _SAFE_GIT_REF.match(base):
505 logger.warning("Invalid git ref rejected: %s", base)
506 return []
507 try:
508 result = subprocess.run(
509 ["git", "diff", "--name-only", base, "--"],
510 capture_output=True,
511 text=True, encoding='utf-8', cwd=str(repo_root),
512 timeout=_GIT_TIMEOUT,
513 stdin=subprocess.DEVNULL,
514 )
515 if result.returncode != 0:
516 # Fallback: try diff against empty tree (initial commit)
517 result = subprocess.run(
518 ["git", "diff", "--name-only", "--cached"],
519 capture_output=True,
520 text=True, encoding='utf-8', cwd=str(repo_root),
521 timeout=_GIT_TIMEOUT,
522 stdin=subprocess.DEVNULL,
523 )
524 files = [f.strip() for f in result.stdout.splitlines() if f.strip()]
525 return files
526 except (FileNotFoundError, subprocess.TimeoutExpired):
527 return []
528
529
530def _get_svn_changed_files(repo_root: Path, rev_range: str | None = None) -> list[str]:

Callers 11

incremental_updateFunction · 0.85
mainFunction · 0.85
get_review_contextFunction · 0.85
get_affected_flows_funcFunction · 0.85
detect_changes_funcFunction · 0.85
get_impact_radiusFunction · 0.85

Calls 2

detect_vcsFunction · 0.85
_get_svn_changed_filesFunction · 0.85