Gitea supports git 2.34 and newer, but with git 2.34.1 `go test
./modules/git/` panics in `TestReadingBlameOutput/sha256` (nil pointer
dereference), which aborts the rest of the package, and `services/pull`
fails its `*-MergeTree` cases with `exit status 129`. These tests use
sha256 repositories, `cat-file --batch-command` and `merge-tree
--write-tree`, which production code only uses when `DefaultFeatures()`
says git is new enough (2.42, 2.36 and 2.40).
Those cases now skip on the same `DefaultFeatures()` flags, as the
check-attr tests in `modules/git/attribute` already do. With git 2.34.1
both packages failed before; now they pass with those cases skipped, and
`make test-backend` passes as a whole. With git 2.42.0, 2.43.0 and
2.56.1 nothing is skipped; with 2.41.3 only the sha256 cases are.
Related: https://github.com/go-gitea/gitea/pull/39565
Assisted-by: Hermes Agent:claude-opus-5-5
Unfortunately, we can't completely remove the ctx from git.Repository,
because the CatFileBatch still heavily depends on a parent context.
If we remove the Repository ctx, the CatFileBatch will become a mess and
create a lot of unnecessary git processes.
http://localhost:3000/-/admin/monitor/perftrace
* Before: open a repo home, dozens of git processes (duplicate cat-file)
* After: only a few (no duplicate cat-file)
before: gitrepo vs git packages
after: git package fully handle all git operations
by the way, use `WithRepo(repo)` instead of `WithDir(repo.Path)` to hide
path details.
benefits:
1. remove all unnecessary wrappers, developers no need to struggle with
"which package should be used"
2. simplify code, RepositoryFacade can (will) be used everywhere, all
"path" details are (will be) hidden
1. Storing "ctx" in a long-living object is wrong
2. Make the commit & tree cacheable (for the future performance
optimization)
3. Also fix some bad designs like `// FIXME: bad design, this field can
be nil if the commit is from "last commit cache"`
ref:
* #33893
Most time, when invoking `git.OpenRepository`, `objectFormat` will not
be used, so it's a waste to invoke commandline to get the object format.
This PR make it a lazy operation, only invoke that when necessary.