Repository navigation
fix(search): make last_n_commits mean N commits, not N first-parents - #530
Conversation
|
Summary: The PR fixes the HEAD~N failure on merge history and the root-commit case. It still doesn't return exactly N commits on merge history, because the commit ordering is wrong. #### Strengths
Issues Major
Minor
Reusability
|
|
CI note: the only red jobs on this PR are
My guess is a stale build or DuckDB cache in Actions, since the macOS log shows a cache hit on the Rust build artifacts. I can't confirm that. If a maintainer can clear the Actions caches and re-run, that should show whether it's the cause. Happy to rebase and re-push once it's sorted. |
|
The issue with rust is unrelated to your PR. It is being handled. |
|
@tharunsridhar The rust-checks issue is resolved in main. Please pull the fix. |
last_n_commits was converted to HEAD~N..HEAD. ~N walks first parents, so with merge commits it covered more than N commits, and past the first-parent depth git failed with a raw 'bad revision' error, leaving the older commits unreachable. Resolve N against the commits git reports (rev-list --parents) and diff from the Nth commit's parent. When the window reaches the root commit, diff the repository's empty tree against HEAD so it is included, in SHA-1 and SHA-256 repositories. A value above the reachable history is clamped to the full history with one warning. The diff itself stays a single git invocation. Tool descriptions and CLI help state the semantics. Fixes #512
…shallow clones Address review of #530: - rev-list now uses --topo-order, so the window no longer depends on commit dates (clock skew could pick a different set of commits). - The base is derived from the window's boundary commits: a single boundary gives an exact N-commit range; several boundaries (merged branches) use their common ancestor, which can include extra commits from those branches. The docstring says so. - A parentless commit in a shallow clone is the edge of the fetched history, not the root. Diff from it with a warning instead of reporting its whole snapshot as additions. - Share the git subprocess handling between the empty-tree lookup, rev-list, rev-parse and merge-base through _run_git_capture, which also gives rev-list the shielded cleanup the empty-tree lookup had. - Drop the stale "first-parent" wording, wrap the CLI help, document the local import, make services a required argument, and state that a value above the history covers the full history. - Tests assert exact file sets for the merge, two-boundary, skewed-date and shallow cases, and the integration tests no longer patch in HEAD~5..HEAD. Refs #512
265942f to
b2c09a3
Compare
|
Thanks, I pulled the fix. I rebased this branch and #531 onto the latest main (b171ede) and force-pushed both. I also ran the tests locally on the rebased branch: CI hasn't started on the new commits (no checks are reported). If it needs approval to run for a fork PR, could you approve the workflow run when you get a chance? Thanks. |
|
CI has run on this PR now and Two macOS jobs show as cancelled rather than failed: Also, #531 (same author) still has no checks and looks like it is waiting for a workflow approval. Could you approve it as well? Thanks. |
|
@tharunsridhar Thanks. |
|
looks good |
Fixes #512
last_n_commits=Nwas turned intoHEAD~N..HEAD.~Nfollows first parents only, so in a history with merge commits the window covered more than N commits, and once N exceeded the first-parent depth git failed with a rawbad revisionerror, leaving the older commits unreachable.N is now resolved against the commits git actually reports (
rev-list --parents) and the diff starts at the parent of the Nth commit.HEADso the root commit is included. Works for SHA-1 and SHA-256 repositories.Tests
tests/unit/test_last_n_commits_range.py(7 tests) builds real git repositories, including a merge history where the oldHEAD~5..HEADrange fails, plus the root-commit, SHA-256 and clamping cases.tests/integration/test_deep_research_with_diff.pyis adjusted for the new resolution path. 59 tests across the neighbouring suites pass.Note on running them: the repo-root
chunkhound_nativestub shadows the compiled extension under pytest's default import mode, so I ran with--import-mode=importlib.