MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / reindex_helper

Function reindex_helper

src/codegraphcontext/cli/cli_helpers.py:672–715  ·  view source on GitHub ↗

Force re-index by deleting and rebuilding the repository.

(path: str, context: Optional[str] = None)

Source from the content-addressed store, hash-verified

670
671
672def reindex_helper(path: str, context: Optional[str] = None):
673 """Force re-index by deleting and rebuilding the repository."""
674 time_start = time.time()
675 path_obj = Path(path).resolve()
676 index_cwd = path_obj if path_obj.is_dir() else path_obj.parent
677 services = _initialize_services(context, cwd=index_cwd)
678 if not all(services[:3]):
679 _fail_services_init()
680
681 db_manager, graph_builder, code_finder, ctx = services
682
683 if not path_obj.exists():
684 console.print(f"[red]Error: Path does not exist: {path_obj}[/red]")
685 db_manager.close_driver()
686 raise typer.Exit(code=1)
687
688 # Check if already indexed
689 indexed_repos = code_finder.list_indexed_repositories()
690 repo_exists = any_repo_matches_path(indexed_repos, path_obj)
691
692 if repo_exists:
693 console.print(f"[yellow]Deleting existing index for: {path_obj}[/yellow]")
694 try:
695 graph_builder.delete_repository_from_graph(str(path_obj))
696 console.print("[green]✓[/green] Deleted old index")
697 except Exception as e:
698 console.print(f"[red]Error deleting old index: {e}[/red]")
699 db_manager.close_driver()
700 raise typer.Exit(code=1)
701
702 console.print(f"[cyan]Re-indexing: {path_obj}[/cyan]")
703
704 try:
705 asyncio.run(_run_index_with_progress(graph_builder, path_obj, is_dependency=False, cgcignore_path=ctx.cgcignore_path))
706 time_end = time.time()
707 elapsed = time_end - time_start
708 _print_call_resolution_diagnostics(graph_builder)
709 _print_index_execution_summary(graph_builder)
710 console.print(f"[green]Successfully re-indexed: {path} in {elapsed:.2f} seconds[/green]")
711 except Exception as e:
712 console.print(f"[bold red]An error occurred during re-indexing:[/bold red] {e}")
713 raise typer.Exit(code=1)
714 finally:
715 db_manager.close_driver()
716
717
718def update_helper(path: str, context: Optional[str] = None, quiet: bool = False):

Callers 2

indexFunction · 0.85
update_helperFunction · 0.85

Calls 12

_initialize_servicesFunction · 0.85
_fail_services_initFunction · 0.85
any_repo_matches_pathFunction · 0.85
_run_index_with_progressFunction · 0.85
printMethod · 0.80
resolveMethod · 0.45
close_driverMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected