Skip to content

refactor: simplify ParseCatFileTreeLine and catBatchParseTreeEntries#37210

Merged
wxiaoguang merged 7 commits into
mainfrom
copilot/refactor-catbatchparsetreeentries
Apr 14, 2026
Merged

refactor: simplify ParseCatFileTreeLine and catBatchParseTreeEntries#37210
wxiaoguang merged 7 commits into
mainfrom
copilot/refactor-catbatchparsetreeentries

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Simplify ParseCatFileTreeLine: it is faster without the preset buffers, and easier to read and maintain.

Copilot AI and others added 3 commits April 14, 2026 06:40
Replace the manual switch statement for mode parsing with a call to
ParseEntryMode, which already handles all the same cases including edge
cases like "40755" via its fallback logic.

Co-Authored-By: GitHub Copilot <copilot@github.com>

Agent-Logs-Url: https://github.com/go-gitea/gitea/sessions/c93c0d76-8a70-478f-a549-2f120c5f45c4

Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
…pre-provided buffers

Replace the three caller-provided buffer parameters (modeBuf, fnameBuf, shaBuf)
with internal allocation. Use rd.ReadBytes('\x00') to read mode+fname in one
call and slice the result directly. Allocate sha internally. Update both callers
(catBatchParseTreeEntries and lfs_nogogit.go) to drop the buffer setup.

Co-Authored-By: GitHub Copilot <copilot@github.com>

Agent-Logs-Url: https://github.com/go-gitea/gitea/sessions/43dab9a5-8c12-41c7-8da6-77c268a65ada

Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
…safe slices

Co-Authored-By: GitHub Copilot <copilot@github.com>

Agent-Logs-Url: https://github.com/go-gitea/gitea/sessions/43dab9a5-8c12-41c7-8da6-77c268a65ada

Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Git tree-entry parsing in the cat-file --batch pipeline to simplify ParseCatFileTreeLine, centralize mode parsing via ParseEntryMode, and update downstream consumers to use the new return types.

Changes:

  • Expand ParseEntryMode to accept tree modes with/without a leading zero ("040000" and "40000").
  • Refactor ParseCatFileTreeLine to return EntryMode, name string, and ObjectID, with updated buffering behavior for long names.
  • Update tree parsing and LFS scanning to use the new ParseCatFileTreeLine signature and typed results.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
modules/git/tree_entry_mode.go Accept non-zero-padded tree mode string and rely on shared mode parsing logic.
modules/git/pipeline/lfs_nogogit.go Adapt LFS scan logic to new tree-line parser outputs (typed mode + ObjectID).
modules/git/parse_treeentry.go Simplify cat-file tree entry parsing by using EntryMode and ObjectID directly.
modules/git/catfile_batch_reader.go Major refactor of ParseCatFileTreeLine API and implementation, including buffer handling changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/git/pipeline/lfs_nogogit.go
Comment thread modules/git/catfile_batch_reader.go
Comment thread modules/git/tree_entry_mode.go
@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 Apr 14, 2026
@wxiaoguang wxiaoguang marked this pull request as ready for review April 14, 2026 08:17
@wxiaoguang wxiaoguang added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Apr 14, 2026
Comment thread modules/git/tree_entry_mode.go
@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 Apr 14, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) April 14, 2026 11:33
@wxiaoguang wxiaoguang merged commit 84d5c99 into main Apr 14, 2026
30 checks passed
@wxiaoguang wxiaoguang deleted the copilot/refactor-catbatchparsetreeentries branch April 14, 2026 12:03
@GiteaBot GiteaBot added this to the 1.27.0 milestone Apr 14, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 17, 2026
* main:
  Replace `dropzone` with `@deltablot/dropzone` (go-gitea#37237)
  Add `ExternalIDClaim` option for OAuth2 OIDC auth source (go-gitea#37229)
  Remove error returns from crypto random helpers and callers (go-gitea#37240)
  Use Content-Security-Policy: script nonce (go-gitea#37232)
  Remove htmx (go-gitea#37224)
  Refactor "htmx" to "fetch action" (go-gitea#37208)
  Fix UI regression (go-gitea#37218)
  Fix corrupted JSON caused by goccy library (go-gitea#37214)
  Add test for "fetch redirect", add CSS value validation for external render (go-gitea#37207)
  Fix incorrect concurrency check (go-gitea#37205)
  refactor: simplify ParseCatFileTreeLine and catBatchParseTreeEntries (go-gitea#37210)
  Update go js py dependencies (go-gitea#37204)
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/refactoring Existing code has been cleaned up. There should be no new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants