From 661c9dbb9d0c0e690f4ecea6570493a1c4ad0010 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Mon, 27 Apr 2026 10:29:43 -0700 Subject: [PATCH] cli: refine gerrit metadata discovery from local branch configs --- git-recent | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/git-recent b/git-recent index f6516a2..7951924 100755 --- a/git-recent +++ b/git-recent @@ -98,7 +98,8 @@ filterarg=${GIT_RECENT_QUERY:+"--filter=$GIT_RECENT_QUERY"} # Chromium/Gerrit/GitHub hackers may want reference to their relevant CL/PR. if [[ "$show_links" = true ]]; then # 1. Try Gerrit/git-cl configs (very fast, but only works if cl has been uploaded) - GERRIT_CONFIGS=$(git config --get-regexp "branch\..*\.gerritissue" 2>/dev/null) + # We fetch all gerrit-related configs for branches to avoid multiple git calls. + GERRIT_CONFIGS=$(git config --get-regexp "branch\..*\.gerrit" 2>/dev/null) GERRIT_SERVER=$(git config --get "gerritserver" 2>/dev/null) GERRIT_PROJECT=$(git config --get "gerrit.project" 2>/dev/null) @@ -163,11 +164,21 @@ _browse_branches() { if [[ "$sl" == true ]]; then # Check Gerrit configs first cl_num=$(echo "$gc" | grep "branch\.${branch_name}\.gerritissue" | awk '{print $2}') - if [[ -n "$cl_num" && -n "$gs" ]]; then + if [[ -n "$cl_num" ]]; then + # Use branch-specific server if available, otherwise fallback to inferred/global server + branch_server=$(echo "$gc" | grep "branch\.${branch_name}\.gerritserver" | awk '{print $2}' | sed -E 's|https?://||') + current_gs="${branch_server:-$gs}" + + # Special case: If we inferred an internal Google host but the config has a public one, + # we prefer the internal one for better connectivity/UX. + if [[ "$gs" == *.git.corp.google.com && "$branch_server" == *.googlesource.com ]]; then + current_gs="$gs" + fi + if [[ -n "$gp" ]]; then - link_url="https://$gs/c/$gp/+/$cl_num" + link_url="https://$current_gs/c/$gp/+/$cl_num" else - link_url="https://$gs/c/$cl_num" + link_url="https://$current_gs/c/$cl_num" fi link_label="$cl_num" elif [[ -n "$cs" ]]; then