@@ -2241,42 +2241,21 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
22412241 return stat_branch_pair (branch -> refname , base , num_ours , num_theirs , abf );
22422242}
22432243
2244- /*
2245- * Return true when there is anything to report, otherwise false.
2246- */
2247- int format_tracking_info (struct branch * branch , struct strbuf * sb ,
2248- enum ahead_behind_flags abf ,
2249- int show_divergence_advice )
2250- {
2251- int ours , theirs , sti ;
2252- const char * full_base ;
2253- char * base ;
2254- int upstream_is_gone = 0 ;
2255-
2256- sti = stat_tracking_info (branch , & ours , & theirs , & full_base , 0 , abf );
2257- if (sti < 0 ) {
2258- if (!full_base )
2259- return 0 ;
2260- upstream_is_gone = 1 ;
2261- }
2262-
2263- base = refs_shorten_unambiguous_ref (get_main_ref_store (the_repository ),
2264- full_base , 0 );
2265- if (upstream_is_gone ) {
2266- strbuf_addf (sb ,
2267- _ ("Your branch is based on '%s', but the upstream is gone.\n" ),
2268- base );
2269- if (advice_enabled (ADVICE_STATUS_HINTS ))
2270- strbuf_addstr (sb ,
2271- _ (" (use \"git branch --unset-upstream\" to fixup)\n" ));
2272- } else if (!sti ) {
2244+ static void format_branch_comparison (struct strbuf * sb ,
2245+ bool up_to_date ,
2246+ int ours , int theirs ,
2247+ const char * branch_name ,
2248+ enum ahead_behind_flags abf ,
2249+ bool show_divergence_advice )
2250+ {
2251+ if (up_to_date ) {
22732252 strbuf_addf (sb ,
22742253 _ ("Your branch is up to date with '%s'.\n" ),
2275- base );
2254+ branch_name );
22762255 } else if (abf == AHEAD_BEHIND_QUICK ) {
22772256 strbuf_addf (sb ,
22782257 _ ("Your branch and '%s' refer to different commits.\n" ),
2279- base );
2258+ branch_name );
22802259 if (advice_enabled (ADVICE_STATUS_HINTS ))
22812260 strbuf_addf (sb , _ (" (use \"%s\" for details)\n" ),
22822261 "git status --ahead-behind" );
@@ -2285,7 +2264,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
22852264 Q_ ("Your branch is ahead of '%s' by %d commit.\n" ,
22862265 "Your branch is ahead of '%s' by %d commits.\n" ,
22872266 ours ),
2288- base , ours );
2267+ branch_name , ours );
22892268 if (advice_enabled (ADVICE_STATUS_HINTS ))
22902269 strbuf_addstr (sb ,
22912270 _ (" (use \"git push\" to publish your local commits)\n" ));
@@ -2296,7 +2275,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
22962275 "Your branch is behind '%s' by %d commits, "
22972276 "and can be fast-forwarded.\n" ,
22982277 theirs ),
2299- base , theirs );
2278+ branch_name , theirs );
23002279 if (advice_enabled (ADVICE_STATUS_HINTS ))
23012280 strbuf_addstr (sb ,
23022281 _ (" (use \"git pull\" to update your local branch)\n" ));
@@ -2309,12 +2288,47 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
23092288 "and have %d and %d different commits each, "
23102289 "respectively.\n" ,
23112290 ours + theirs ),
2312- base , ours , theirs );
2291+ branch_name , ours , theirs );
23132292 if (show_divergence_advice &&
23142293 advice_enabled (ADVICE_STATUS_HINTS ))
23152294 strbuf_addstr (sb ,
23162295 _ (" (use \"git pull\" if you want to integrate the remote branch with yours)\n" ));
23172296 }
2297+ }
2298+
2299+ /*
2300+ * Return true when there is anything to report, otherwise false.
2301+ */
2302+ int format_tracking_info (struct branch * branch , struct strbuf * sb ,
2303+ enum ahead_behind_flags abf ,
2304+ int show_divergence_advice )
2305+ {
2306+ int ours , theirs , cmp_fetch ;
2307+ const char * full_base ;
2308+ char * base ;
2309+ int upstream_is_gone = 0 ;
2310+
2311+ cmp_fetch = stat_tracking_info (branch , & ours , & theirs , & full_base , 0 , abf );
2312+ if (cmp_fetch < 0 ) {
2313+ if (!full_base )
2314+ return 0 ;
2315+ upstream_is_gone = 1 ;
2316+ }
2317+
2318+ base = refs_shorten_unambiguous_ref (get_main_ref_store (the_repository ),
2319+ full_base , 0 );
2320+
2321+ if (upstream_is_gone ) {
2322+ strbuf_addf (sb ,
2323+ _ ("Your branch is based on '%s', but the upstream is gone.\n" ),
2324+ base );
2325+ if (advice_enabled (ADVICE_STATUS_HINTS ))
2326+ strbuf_addstr (sb ,
2327+ _ (" (use \"git branch --unset-upstream\" to fixup)\n" ));
2328+ } else {
2329+ format_branch_comparison (sb , !cmp_fetch , ours , theirs , base , abf , show_divergence_advice );
2330+ }
2331+
23182332 free (base );
23192333 return 1 ;
23202334}
0 commit comments