Skip to content

fix(api): avoid pull files panic with whitespace ignored - #39196

Open
lunny wants to merge 4 commits into
go-gitea:mainfrom
lunny:lunny/fix-pull-files-whitespace-panic
Open

fix(api): avoid pull files panic with whitespace ignored#39196
lunny wants to merge 4 commits into
go-gitea:mainfrom
lunny:lunny/fix-pull-files-whitespace-panic

Conversation

@lunny

@lunny lunny commented Aug 31, 2026

Copy link
Copy Markdown
Member

The pull request files endpoint paginated by the shortstat file count while indexing into the filtered diff. With whitespace=ignore-change, git omits whitespace-only files, so the shortstat can report more files than the diff contains and the handler panics with an index out of range error.

Build both the diff and the shortstat from the same DiffOptions so whitespace, rename detection, and skip-to stay consistent, and clamp the page to the files actually returned by the diff.

Fixes #39191

The pull request files endpoint used the shortstat file count to page through the filtered diff. When whitespace changes are ignored, the shortstat can report more files than the diff contains, causing an index out of range panic. Apply the whitespace behavior to the shortstat and clamp the page to the files returned by the diff.

Assisted-by: Codet:unknown
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 31, 2026
@github-actions github-actions Bot added topic/api Concerns mainly the API type/bug labels Aug 31, 2026
lunny added 2 commits August 31, 2026 13:59
Reuse the same DiffOptions for both the file diff and the shortstat so options such as whitespace, rename detection, and skip-to stay consistent between the two commands.

Assisted-by: Codet:unknown
Use the same DiffOptions for the rendered diff and its shortstat on pull, commit, and compare pages. This keeps whitespace, skip-to, and file filters from making the summary count diverge from the visible diff.

Assisted-by: Codet:unknown
@lunny lunny added the backport/v1.27 This PR should be backported to Gitea 1.27 label Aug 31, 2026
The shortstat and diff now share the same DiffOptions, so the extra clamp against len(diff.Files) is no longer needed.

Assisted-by: Codet:unknown
@silverwind

Copy link
Copy Markdown
Member

I wonder if this can be fixed without introducing another git call.

@lunny

lunny commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

I wonder if this can be fixed without introducing another git call.

One is for the stats, another is for the pagination(max files). So that I don't think it can be done in one git call.

Comment thread modules/git/diff2.go
return GetDiffShortStatByCmd(ctx, repo, cmd)
}

func GetDiffShortStatByCmd(ctx context.Context, repo RepositoryFacade, cmd *gitcmd.Command) (numFiles, totalAdditions, totalDeletions int, err error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should really read the code and think about what's the right thing to do

// TODO: it can be merged with another "GetDiffShortStat" in the future

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor: GetDiffShortStat and fix panic caused by inconsistent "changed file number" - #39248

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

Labels

backport/v1.27 This PR should be backported to Gitea 1.27 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/api Concerns mainly the API type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lfs diff ws panic

4 participants