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

Function build_or_update_graph

code_review_graph/tools/build.py:361–437  ·  view source on GitHub ↗

Build or incrementally update the code knowledge graph. Args: full_rebuild: If True, re-parse every file. If False (default), only re-parse files changed since ``base``. repo_root: Path to the repository root. Auto-detected if omitted. base: Git ref

(
    full_rebuild: bool = False,
    repo_root: str | None = None,
    base: str = "HEAD~1",
    postprocess: str = "full",
    recurse_submodules: bool | None = None,
)

Source from the content-addressed store, hash-verified

359
360
361def build_or_update_graph(
362 full_rebuild: bool = False,
363 repo_root: str | None = None,
364 base: str = "HEAD~1",
365 postprocess: str = "full",
366 recurse_submodules: bool | None = None,
367) -> dict[str, Any]:
368 """Build or incrementally update the code knowledge graph.
369
370 Args:
371 full_rebuild: If True, re-parse every file. If False (default),
372 only re-parse files changed since ``base``.
373 repo_root: Path to the repository root. Auto-detected if omitted.
374 base: Git ref for incremental diff (default: HEAD~1).
375 postprocess: Post-processing level after build:
376 ``"full"`` (default) — signatures, FTS, flows, communities.
377 ``"minimal"`` — signatures + FTS only (fast, keeps search working).
378 ``"none"`` — skip all post-processing (raw parse only).
379 recurse_submodules: If True, include files from git submodules
380 via ``git ls-files --recurse-submodules``. When None
381 (default), falls back to the CRG_RECURSE_SUBMODULES
382 environment variable. Default: disabled.
383
384 Returns:
385 Summary with files_parsed/updated, node/edge counts, and errors.
386 """
387 store, root = _get_store(repo_root)
388 try:
389 if full_rebuild:
390 result = full_build(root, store, recurse_submodules)
391 build_result = {
392 "status": "ok",
393 "build_type": "full",
394 "summary": (
395 f"Full build complete: parsed {result['files_parsed']} files, "
396 f"created {result['total_nodes']} nodes and "
397 f"{result['total_edges']} edges."
398 ),
399 **result,
400 }
401 else:
402 result = incremental_update(root, store, base=base)
403 if result["files_updated"] == 0:
404 return {
405 "status": "ok",
406 "build_type": "incremental",
407 "summary": "No changes detected. Graph is up to date.",
408 "postprocess_level": postprocess,
409 **result,
410 }
411 build_result = {
412 "status": "ok",
413 "build_type": "incremental",
414 "summary": (
415 f"Incremental update: {result['files_updated']} files re-parsed, "
416 f"{result['total_nodes']} nodes and "
417 f"{result['total_edges']} edges updated. "
418 f"Changed: {result['changed_files']}. "

Calls 6

_get_storeFunction · 0.85
full_buildFunction · 0.85
incremental_updateFunction · 0.85
_run_postprocessFunction · 0.85
getMethod · 0.80
closeMethod · 0.45