How to Register and Manage Multiple Repositories with Code-Review-Graph (CRG)
Code-Review-Graph maintains a JSON-based registry at ~/.code-review-graph/registry.json that maps repository aliases to absolute paths, allowing you to register multiple codebases and reference them via short names in CLI commands or Python API calls.
Code-Review-Graph (CRG) is designed to handle single or multiple codebases simultaneously through a lightweight registry system. Whether you're analyzing microservices or monorepos, understanding how to register and manage multiple repositories with CRG enables seamless graph generation across your entire codebase. The registry functionality is implemented in the tirth8205/code-review-graph repository and provides both programmatic Python APIs and convenient CLI commands.
Understanding the CRG Registry Architecture
Registry Storage and Configuration
The registry location is determined by code_review_graph/constants.py (lines 10-25), which checks for the $CRG_HOME environment variable. If set, CRG uses that directory; otherwise, it defaults to ~/.code-review-graph/. Within this directory, the registry.json file stores each repository's absolute path and optional alias as JSON objects.
Core Registry Implementation
The Registry class in code_review_graph/registry.py provides the primary interface for repository management:
Registry.register(path, alias=None, data_dir=None)(lines 67-95): Validates the target directory contains a.git,.svn, or.code-review-graphmarker before creating or updating an entry.Registry.unregister(path_or_alias)(lines 19-39): Removes entries by path or alias.Registry.list_repos()(lines 41-48): Returns all registered repositories.resolve_repo()(lines 91-126): Resolves user-supplied aliases or relative paths to absolute repository locations used throughout the CLI.
CLI Commands for Repository Registration
Registering New Repositories
Use the register command to add repositories to the global registry:
code-review-graph register /path/to/project --alias proj
This validates the repository markers and writes an entry to registry.json:
{"path":"/home/user/project","alias":"proj"}
Managing Registered Repositories
List all known repositories:
code-review-graph repos
Remove a repository when no longer needed:
code-review-graph unregister proj
Automating Multi-Repo Workflows with the Daemon
Persistent Daemon Configuration
For continuous monitoring, CRG uses a separate watch.toml file (stored in the same $CRG_HOME directory) managed through daemon-specific commands documented in docs/COMMANDS.md (lines 90-104).
Daemon Management Commands
code-review-graph daemon add <path> [--alias <name>]: Persists repos towatch.tomlfor automatic watching.code-review-graph daemon remove <path_or_alias>: Stops watching and removes from config.code-review-graph daemon status: Displays currently watched repositories.
The daemon spawns code-review-graph watch subprocesses for each entry, automatically rebuilding graphs when files change.
Practical Implementation Examples
Manual Repository Workflow
Register and build graphs for multiple repositories:
# Register two services
code-review-graph register ~/service-a --alias svc-a
code-review-graph register ~/service-b --alias svc-b
# Verify registration
code-review-graph repos
# Build graphs using aliases
code-review-graph --repo svc-a build
code-review-graph --repo svc-b build
Programmatic Registry Access
Interact with the registry directly in Python:
from code_review_graph.registry import Registry
reg = Registry() # Loads ~/.code-review-graph/registry.json
# Register with alias
reg.register("/home/alice/project", alias="proj")
# List all entries
print(reg.list_repos())
# Output: [{'path': '/home/alice/project', 'alias': 'proj'}]
# Remove by alias
reg.unregister("proj")
Automated Daemon Setup
Enable background watching for multiple repos:
code-review-graph daemon add ~/service-a --alias svc-a
code-review-graph daemon add ~/service-b --alias svc-b
code-review-graph daemon start
code-review-graph daemon status
Summary
- CRG stores repository metadata in
registry.jsonwithin$CRG_HOME(defaulting to~/.code-review-graph/). - The
Registryclass incode_review_graph/registry.pyhandles validation, registration, and resolution. - Use
code-review-graph registerandunregisterto manage the CLI registry. - The daemon uses
watch.tomlfor persistent multi-repo watching viadaemon addanddaemon remove. - Aliases resolve to absolute paths through
resolve_repo()for all graph operations.
Frequently Asked Questions
What repository markers does CRG validate during registration?
According to code_review_graph/registry.py (lines 67-95), CRG validates that the target directory contains a .git, .svn, or .code-review-graph marker file before allowing registration. This ensures only actual code repositories or previously initialized CRG projects are added to the registry.
Can I use relative paths when registering repositories?
While you can provide relative paths to the register command, CRG stores the absolute path in registry.json. The resolve_repo() function (lines 91-126) handles path resolution, converting any alias or relative path supplied to CLI commands into the absolute location required for graph database operations.
How do I change the default registry location?
Set the $CRG_HOME environment variable before running CRG commands. As defined in code_review_graph/constants.py (lines 10-25), this variable overrides the default ~/.code-review-graph/ directory, moving both registry.json and watch.toml to your specified location.
What is the difference between unregister and daemon remove?
The unregister command removes entries from registry.json, affecting only the static registry used for alias resolution. The daemon remove command removes entries from watch.toml, stopping the background watcher from monitoring that repository. A repository can be registered for CLI use without being watched by the daemon, and vice versa.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →