Skip to content

fix(api): respect since/until when counting commits for X-Total-Count - #38204

Merged
lunny merged 4 commits into
go-gitea:mainfrom
augustocbx:issue-35886
Jun 28, 2026
Merged

fix(api): respect since/until when counting commits for X-Total-Count#38204
lunny merged 4 commits into
go-gitea:mainfrom
augustocbx:issue-35886

Conversation

@augustocbx

Copy link
Copy Markdown
Contributor

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 #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.

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
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 23, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 25, 2026
@puni9869

puni9869 commented Jun 25, 2026

Copy link
Copy Markdown
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.

@puni9869

Copy link
Copy Markdown
Member

We can go with this impl.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 28, 2026
lunny
lunny previously requested changes Jun 28, 2026
Comment thread modules/gitrepo/commit.go
@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Jun 28, 2026
@puni9869

Copy link
Copy Markdown
Member

@augustocbx I am walking this pr on your behalf.

@lunny
lunny dismissed their stale review June 28, 2026 19:33

resolved

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Jun 28, 2026
@lunny
lunny enabled auto-merge (squash) June 28, 2026 19:37
@lunny
lunny merged commit 4812e35 into go-gitea:main Jun 28, 2026
23 checks passed
@GiteaBot GiteaBot added this to the 1.28.0 milestone Jun 28, 2026
@lunny lunny modified the milestones: 1.28.0, 1.27.0 Jun 28, 2026
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>
silverwind pushed a commit that referenced this pull request Jul 2, 2026
) (#38304)

Backport #38243 by @puni9869

Follow up for #38204.

Signed-off-by: puni9869 <80308335+puni9869@users.noreply.github.com>
Co-authored-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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API /commits returns incorrect X-Total-Count when using since/until filters (v1.25)

6 participants