- Renamed `get_all_branch_details` to `get_unmerged_branch_details` to clarify intent.
- Updated `get_prs_via_git` to only fetch merged branches, delegating open branch fetching to `get_unmerged_branch_details`.
- Refactored `main` to populate `open_branches` from `get_unmerged_branch_details` keys, avoiding redundant git calls and eliminating N+1 `git rev-list` calls in the fallback path.
- Added explicit safety check `if ahead == 0: continue` to `get_unmerged_branch_details` to guarantee merged branches are filtered out.
- Sorted open branches by commit date for better readability.
- Modified `scripts/review_pull_requests.py` to filter `git for-each-ref` output by unmerged branches.
- Reduces algorithmic complexity from O(N) to O(M) where N is total branches and M is active branches.
- Avoids expensive `ahead-behind` calculations for potentially thousands of stale merged branches.
- Replaced O(N) `git log` parsing with O(1) `git rev-list --count` for branch commit counts.
- Updated `get_all_branch_details` to return an empty `commits` list to ensure consistent data structure with `get_branch_info`, preventing potential runtime errors.
- Changed base branch reference from `main` to `origin/main` to support CI/CD environments and shallow clones where local `main` might be missing.
- Removed unused `commits` list generation in `get_branch_info` to improve fallback performance.
Replaced per-branch git log calls with a single git for-each-ref command using the ahead-behind atom. This optimizes the script from O(N) to O(1) git subprocess calls.
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>