mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-08-30 00:29:49 +00:00
e5bbb5c9e6
Benchmark (100 untouched projects): * GetUploadableBranches: 0.985s -> 0.0004s (2,200x faster) * repo upload (3,045 projects): saves ~2.5s of redundant ref scans During `repo upload`, `GetUploadableBranches()` currently scans `self._allrefs` across all projects in the workspace. In large manifests (e.g. Android with 3,000+ projects), `self._allrefs` executes `git for-each-ref`, `git symbolic-ref`, and full filesystem mtime traversals on thousands of projects where no local branch was ever started or modified. Any branch that can be uploaded for review must have upstream tracking configured via `[branch "..."]` sections in `.git/config` (otherwise `branch.LocalMerge` is None and `GetUploadableBranch` returns None). This patch introduces early-pruning fast paths: 1. When no branch subsections exist in `.git/config` (or only 2-part keys like `branch.autosetupmerge`), return [] immediately without touching `_allrefs`. 2. When a `selected_branch` is specified (e.g. `repo upload --br=...`), query `branch.LocalMerge`, `refs/heads/<branch>`, and `refs/published/<branch>` directly, skipping the whole-tree ref scan. 3. In `subcmds/upload.py`, optimize `_GetMergeBranch` to resolve the merge branch in-memory via `project.CurrentBranch` and `project.GetBranch()` instead of spawning two `GitCommand` processes. Test: ./run_tests tests/test_project.py tests/test_subcmds_upload.py Change-Id: I3c2c9d63a68a393d478e1fb50f548ec8b7d44639 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/623021 Reviewed-by: Brian Gan <brgan@google.com> Commit-Queue: James Hawkins <jhawkins@google.com> Tested-by: James Hawkins <jhawkins@google.com>
Repo Tests
There is a mixture of pytest & Python unittest in here. We adopted pytest later on but didn't migrate existing tests (since they still work). New tests should be written using pytest only.
File layout
test_xxx.py: Unittests for thexxxmodule in the main repo codebase. Modules that are in subdirs normalize the/into_. For example, test_error.py is for the error.py module, and test_subcmds_forall.py is for the subcmds/forall.py module.- conftest.py: Custom pytest fixtures for sharing.
- utils_for_test.py: Helpers for sharing in tests.