Skip to content

Conversation

@sashalevin
Copy link

Enables indexing and querying across multiple git branches.

The indexer accepts --branches to index several branches at once.

The query tool and MCP server accept a branch parameter to scope queries to a specific branch.

New REPL commands (branches, branch, compare) and MCP tools (list_branches, compare_branches) provide branch management.

The LSP server supports a target_branch configuration option.

Sasha Levin added 7 commits December 10, 2025 21:55
This enables future multi-branch indexing by tracking branch state
across indexing operations.

Signed-off-by: Sasha Levin <sashal@kernel.org>
These functions enable branch resolution for queries and efficient
incremental indexing across multiple branches.

Signed-off-by: Sasha Levin <sashal@kernel.org>
- Add CLI flags for branch indexing:
  - --branch BRANCH (can be repeated)
  - --branches LIST (comma-separated)
  - --all-branches (index all local branches)
  - --remote-branches (include remote branches)
  - --update-branches (skip already-current branches)

Signed-off-by: Sasha Levin <sashal@kernel.org>
Adds the --branch CLI flag to semcode query tool allowing users to
query code at a specific branch instead of the current HEAD.

Signed-off-by: Sasha Levin <sashal@kernel.org>
Adds three new commands to the query REPL:
- `branches` (or `br`): List indexed branches with their status
- `branch`: Show current branch information and target branch
- `compare`: Compare two branches showing merge base and indexing status

Signed-off-by: Sasha Levin <sashal@kernel.org>
Adds a new `branch` parameter to MCP tools that support git_sha:
- find_function, find_type, find_callers, find_calls
- find_callchain, grep_functions, vgrep_functions

When branch is provided, it's resolved to a SHA and used for the query.
Branch takes precedence over git_sha if both are specified.

Signed-off-by: Sasha Levin <sashal@kernel.org>
Adds two new MCP tools for branch management:
- list_branches: Lists all indexed branches with their status
- compare_branches: Compares two branches showing merge base,
  ahead/behind status, and indexing status

Signed-off-by: Sasha Levin <sashal@kernel.org>
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 11, 2025
@masoncl
Copy link
Contributor

masoncl commented Dec 11, 2025

Seems pretty reasonable, I'll look harder this week. Can I ask for some documentation updates with how you're using it? Especially for the table that tracks what has already been indexed, I'm curious how you're using that part.

Also, you can use https://github.com/masoncl/semcode-devel if you'd prefer to use DCO instead of the CLA.

Add branching-example.md explaining how to use semcode's multi-branch
support for kernel stable tree maintenance.

Signed-off-by: Sasha Levin <sashal@kernel.org>
@sashalevin
Copy link
Author

Added some docs. In general, I use it for both autosel and the cve_classifier: in the case of autosel it helps identify how far a backport should go, and the range of affected kernels for cve assignments.

The --update-branches makes it easy to keep multiple stable branches up to date as new stable kernels are released.

@masoncl
Copy link
Contributor

masoncl commented Dec 18, 2025

The docs are great thank you, I can see how this would be really useful.

The changes looked good to me, claude found a few potential issues. Also, reading the docs I think you want an option to just reindex all the branches that have changed?

The only problem I really care about below is the db manager per branch, but I'll let you decide for the others.

Also, I think the semcode br
Issue 5: Initial Branch Indexing Range Bug
// index.rs:529-530
info!("Initial indexing for branch {}", branch_name);
format!("{}^..{}", tip_commit, tip_commit) // ⚠️ Only indexes 1 commit!
For initial branch indexing, this only indexes the tip commit itself, not the full branch
history. The comment says "Full indexing: index entire branch history" but the code only does
TIP^..TIP which is just the single commit.

Recommendation: For initial indexing, consider using --git flag behavior or a configurable
depth.

Issue 6: Remote Detection Logic
// index.rs:582-586
let remote = if branch_name.contains('/') {
branch_name.split('/').next()
} else {
None
};
This incorrectly marks feature/my-feature as a remote branch with remote name "feature". Should
check if it starts with a known remote name or use the is_remote flag from list_branches.

Issue 7: Creates New DatabaseManager Per Branch
// index.rs:557-561
let db_manager_arc = Arc::new(
DatabaseManager::new(&database_path, args.source.to_string_lossy().to_string())
.await?,
);
Inside the branch loop, a new DatabaseManager is created for each branch. This is inefficient
and could cause connection pool issues. Should reuse the outer db_manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants