fix(api): respect since/until when counting commits for X-Total-Count - #38204
Merged
Conversation
The repository commits API accepts `since`/`until` query parameters and filters the returned page accordingly, but the `X-Total-Count` /`X-Total` headers reported the full commit count. `CommitsCount` declared `Since` and `Until` options yet never appended `--since`/`--until` to the underlying `git rev-list --count`, so the date filters were silently dropped and the total could exceed the number of commits actually returned. Pass the options through to git, mirroring the existing commit-listing code path, so the reported total matches the filtered range. Fixes go-gitea#35886. Assisted-by: Claude Code:claude-opus-4-8
bircni
approved these changes
Jun 25, 2026
Member
|
Just check for gitrepo.CommitsCount is not being used any more places and test when you pass Sha or since or until combination for this api. |
Member
|
We can go with this impl. |
puni9869
approved these changes
Jun 28, 2026
lunny
previously requested changes
Jun 28, 2026
Member
|
@augustocbx I am walking this pr on your behalf. |
lunny
enabled auto-merge (squash)
June 28, 2026 19:37
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jun 30, 2026
* 'main' of https://github.com/go-gitea/gitea: (50 commits) [skip ci] Updated translations via Crowdin ci: regenerate codemirror languages on renovate npm updates (go-gitea#38267) build: fix snapcraft release (go-gitea#38260) chore(deps): update dependency js-yaml to v5 (go-gitea#38262) chore(deps): update actions/cache action to v6 (go-gitea#38261) fix(deps): update module gitlab.com/gitlab-org/api/client-go/v2 to v2.42.0 (go-gitea#38266) fix(deps): update go dependencies (go-gitea#38194) chore: various UI problems (go-gitea#38263) fix: update npm dependencies, fix misc issues (go-gitea#38257) chore(deps): update action dependencies (go-gitea#38258) fix(packages): validate debian distribution and component names (go-gitea#38116) chore(deps): update python dependencies (go-gitea#38256) fix: flex divided list item shrink (go-gitea#38255) [skip ci] Updated translations via Crowdin fix(actions): authenticate snapcraft before nightly remote build (go-gitea#38252) revert(sign): restore gpg (go-gitea#38251) fix(api): respect since/until when counting commits for X-Total-Count (go-gitea#38204) build(sign): move to sigstore (go-gitea#38250) fix: codemirror regressions (go-gitea#38248) fix(api): support HEAD requests on all API GET endpoints (go-gitea#38245) ...
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jun 30, 2026
* main: (50 commits) [skip ci] Updated translations via Crowdin ci: regenerate codemirror languages on renovate npm updates (go-gitea#38267) build: fix snapcraft release (go-gitea#38260) chore(deps): update dependency js-yaml to v5 (go-gitea#38262) chore(deps): update actions/cache action to v6 (go-gitea#38261) fix(deps): update module gitlab.com/gitlab-org/api/client-go/v2 to v2.42.0 (go-gitea#38266) fix(deps): update go dependencies (go-gitea#38194) chore: various UI problems (go-gitea#38263) fix: update npm dependencies, fix misc issues (go-gitea#38257) chore(deps): update action dependencies (go-gitea#38258) fix(packages): validate debian distribution and component names (go-gitea#38116) chore(deps): update python dependencies (go-gitea#38256) fix: flex divided list item shrink (go-gitea#38255) [skip ci] Updated translations via Crowdin fix(actions): authenticate snapcraft before nightly remote build (go-gitea#38252) revert(sign): restore gpg (go-gitea#38251) fix(api): respect since/until when counting commits for X-Total-Count (go-gitea#38204) build(sign): move to sigstore (go-gitea#38250) fix: codemirror regressions (go-gitea#38248) fix(api): support HEAD requests on all API GET endpoints (go-gitea#38245) ...
bircni
pushed a commit
that referenced
this pull request
Jul 1, 2026
) Follow up for #38204. --------- Signed-off-by: puni9869 <80308335+puni9869@users.noreply.github.com>
zeekay
pushed a commit
to hanzoai/forge
that referenced
this pull request
Jul 26, 2026
…go-gitea#38204) The repository commits API (`GET /repos/{owner}/{repo}/commits`) accepts `since` and `until` query parameters and filters the returned page of commits by commit date. However, the `X-Total-Count` and `X-Total` response headers reported the *unfiltered* total number of commits, so the advertised total could be far larger than the number of commits actually returned for the requested date range. With a range that matches no commits, the page is correctly empty while the headers still claim the full repository total. ## Root cause `gitrepo.CommitsCount` declared `Since` and `Until` options and the API handler populated them, but the function never appended `--since`/`--until` to the underlying `git rev-list --count` invocation. The date filters were silently dropped, so the count always reflected the entire revision history. ## Fix Pass the `Since`/`Until` options through to `git rev-list`, mirroring the existing commit-listing path (`commitsByRangeWithTime`). The reported total now matches the filtered range used to build the page. ## Testing Added `TestCommitsCountWithSinceUntil` in `modules/gitrepo/commit_test.go`, a table-driven unit test against the `repo1_bare` fixture covering `since`, `until`, and a bounded `since`+`until` range. It fails on the pre-fix code (every case returns the full count of 3) and passes after the change. Existing `CommitsCount` tests remain green. ## Notes - No new settings, no default changes; this corrects an incorrect header value and is backward compatible. Clients that depend on `since`/`until` already filter the returned commits, and the headers now agree with that filtering. Fixes go-gitea#35886. --- *AI-assistance disclosure:* this change was developed with the assistance of agent (Claude Opus 4.8). I have reviewed and understand the change and take responsibility for it.
zeekay
pushed a commit
to hanzoai/forge
that referenced
this pull request
Jul 26, 2026
…gitea#38243) Follow up for go-gitea#38204. --------- Signed-off-by: puni9869 <80308335+puni9869@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The repository commits API (
GET /repos/{owner}/{repo}/commits) acceptssinceanduntilquery parameters and filters the returned page of commits by commit date. However, theX-Total-CountandX-Totalresponse headers reported the unfiltered total number of commits, so the advertised total could be far larger than the number of commits actually returned for the requested date range. With a range that matches no commits, the page is correctly empty while the headers still claim the full repository total.Root cause
gitrepo.CommitsCountdeclaredSinceandUntiloptions and the API handler populated them, but the function never appended--since/--untilto the underlyinggit rev-list --countinvocation. The date filters were silently dropped, so the count always reflected the entire revision history.Fix
Pass the
Since/Untiloptions through togit rev-list, mirroring the existing commit-listing path (commitsByRangeWithTime). The reported total now matches the filtered range used to build the page.Testing
Added
TestCommitsCountWithSinceUntilinmodules/gitrepo/commit_test.go, a table-driven unit test against therepo1_barefixture coveringsince,until, and a boundedsince+untilrange. It fails on the pre-fix code (every case returns the full count of 3) and passes after the change. ExistingCommitsCounttests remain green.Notes
since/untilalready filter the returned commits, and the headers now agree with that filtering.Fixes #35886.
AI-assistance disclosure: this change was developed with the assistance of Claude Code (Claude Opus 4.8). I have reviewed and understand the change and take responsibility for it.