MCPcopy Index your code
hub / github.com/CodeGraphContext/CodeGraphContext / reindex_helper

Function reindex_helper

src/codegraphcontext/cli/cli_helpers.py:508–547  ·  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

506
507
508def reindex_helper(path: str, context: Optional[str] = None):
509 """Force re-index by deleting and rebuilding the repository."""
510 time_start = time.time()
511 services = _initialize_services(context)
512 if not all(services[:3]):
513 return
514
515 db_manager, graph_builder, code_finder, ctx = services
516 path_obj = Path(path).resolve()
517
518 if not path_obj.exists():
519 console.print(f"[red]Error: Path does not exist: {path_obj}[/red]")
520 db_manager.close_driver()
521 return
522
523 # Check if already indexed
524 indexed_repos = code_finder.list_indexed_repositories()
525 repo_exists = any_repo_matches_path(indexed_repos, path_obj)
526
527 if repo_exists:
528 console.print(f"[yellow]Deleting existing index for: {path_obj}[/yellow]")
529 try:
530 graph_builder.delete_repository_from_graph(str(path_obj))
531 console.print("[green]✓[/green] Deleted old index")
532 except Exception as e:
533 console.print(f"[red]Error deleting old index: {e}[/red]")
534 db_manager.close_driver()
535 return
536
537 console.print(f"[cyan]Re-indexing: {path_obj}[/cyan]")
538
539 try:
540 asyncio.run(_run_index_with_progress(graph_builder, path_obj, is_dependency=False, cgcignore_path=ctx.cgcignore_path))
541 time_end = time.time()
542 elapsed = time_end - time_start
543 console.print(f"[green]Successfully re-indexed: {path} in {elapsed:.2f} seconds[/green]")
544 except Exception as e:
545 console.print(f"[bold red]An error occurred during re-indexing:[/bold red] {e}")
546 finally:
547 db_manager.close_driver()
548
549
550def update_helper(path: str, context: Optional[str] = None):

Callers 2

indexFunction · 0.85
update_helperFunction · 0.85

Calls 8

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

Tested by

no test coverage detected