@@ -1880,45 +1880,35 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
1880
1880
}
1881
1881
1882
1882
/*
1883
- * Lookup the upstream branch for the given branch and if present, optionally
1884
- * compute the commit ahead/behind values for the pair.
1883
+ * Compute the commit ahead/behind values for the pair branch_name, base.
1885
1884
*
1886
1885
* If abf is AHEAD_BEHIND_FULL, compute the full ahead/behind and return the
1887
1886
* counts in *num_ours and *num_theirs. If abf is AHEAD_BEHIND_QUICK, skip
1888
1887
* the (potentially expensive) a/b computation (*num_ours and *num_theirs are
1889
1888
* set to zero).
1890
1889
*
1891
- * The name of the upstream branch (or NULL if no upstream is defined) is
1892
- * returned via *upstream_name, if it is not itself NULL.
1893
- *
1894
- * Returns -1 if num_ours and num_theirs could not be filled in (e.g., no
1895
- * upstream defined, or ref does not exist). Returns 0 if the commits are
1896
- * identical. Returns 1 if commits are different.
1890
+ * Returns -1 if num_ours and num_theirs could not be filled in (e.g., ref
1891
+ * does not exist). Returns 0 if the commits are identical. Returns 1 if
1892
+ * commits are different.
1897
1893
*/
1898
- int stat_tracking_info (struct branch * branch , int * num_ours , int * num_theirs ,
1899
- const char * * upstream_name , enum ahead_behind_flags abf )
1894
+
1895
+ static int stat_branch_pair (const char * branch_name , const char * base ,
1896
+ int * num_ours , int * num_theirs ,
1897
+ enum ahead_behind_flags abf )
1900
1898
{
1901
1899
struct object_id oid ;
1902
1900
struct commit * ours , * theirs ;
1903
1901
struct rev_info revs ;
1904
- const char * base ;
1905
1902
struct argv_array argv = ARGV_ARRAY_INIT ;
1906
1903
1907
- /* Cannot stat unless we are marked to build on top of somebody else. */
1908
- base = branch_get_upstream (branch , NULL );
1909
- if (upstream_name )
1910
- * upstream_name = base ;
1911
- if (!base )
1912
- return -1 ;
1913
-
1914
1904
/* Cannot stat if what we used to build on no longer exists */
1915
1905
if (read_ref (base , & oid ))
1916
1906
return -1 ;
1917
1907
theirs = lookup_commit_reference (the_repository , & oid );
1918
1908
if (!theirs )
1919
1909
return -1 ;
1920
1910
1921
- if (read_ref (branch -> refname , & oid ))
1911
+ if (read_ref (branch_name , & oid ))
1922
1912
return -1 ;
1923
1913
ours = lookup_commit_reference (the_repository , & oid );
1924
1914
if (!ours )
@@ -1932,7 +1922,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
1932
1922
if (abf == AHEAD_BEHIND_QUICK )
1933
1923
return 1 ;
1934
1924
if (abf != AHEAD_BEHIND_FULL )
1935
- BUG ("stat_tracking_info : invalid abf '%d'" , abf );
1925
+ BUG ("stat_branch_pair : invalid abf '%d'" , abf );
1936
1926
1937
1927
/* Run "rev-list --left-right ours...theirs" internally... */
1938
1928
argv_array_push (& argv , "" ); /* ignored */
@@ -1966,6 +1956,42 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
1966
1956
return 1 ;
1967
1957
}
1968
1958
1959
+ /*
1960
+ * Lookup the tracking branch for the given branch and if present, optionally
1961
+ * compute the commit ahead/behind values for the pair.
1962
+ *
1963
+ * If for_push is true, the tracking branch refers to the push branch,
1964
+ * otherwise it refers to the upstream branch.
1965
+ *
1966
+ * The name of the tracking branch (or NULL if it is not defined) is
1967
+ * returned via *tracking_name, if it is not itself NULL.
1968
+ *
1969
+ * If abf is AHEAD_BEHIND_FULL, compute the full ahead/behind and return the
1970
+ * counts in *num_ours and *num_theirs. If abf is AHEAD_BEHIND_QUICK, skip
1971
+ * the (potentially expensive) a/b computation (*num_ours and *num_theirs are
1972
+ * set to zero).
1973
+ *
1974
+ * Returns -1 if num_ours and num_theirs could not be filled in (e.g., no
1975
+ * upstream defined, or ref does not exist). Returns 0 if the commits are
1976
+ * identical. Returns 1 if commits are different.
1977
+ */
1978
+ int stat_tracking_info (struct branch * branch , int * num_ours , int * num_theirs ,
1979
+ const char * * tracking_name , int for_push ,
1980
+ enum ahead_behind_flags abf )
1981
+ {
1982
+ const char * base ;
1983
+
1984
+ /* Cannot stat unless we are marked to build on top of somebody else. */
1985
+ base = for_push ? branch_get_push (branch , NULL ) :
1986
+ branch_get_upstream (branch , NULL );
1987
+ if (tracking_name )
1988
+ * tracking_name = base ;
1989
+ if (!base )
1990
+ return -1 ;
1991
+
1992
+ return stat_branch_pair (branch -> refname , base , num_ours , num_theirs , abf );
1993
+ }
1994
+
1969
1995
/*
1970
1996
* Return true when there is anything to report, otherwise false.
1971
1997
*/
@@ -1977,7 +2003,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
1977
2003
char * base ;
1978
2004
int upstream_is_gone = 0 ;
1979
2005
1980
- sti = stat_tracking_info (branch , & ours , & theirs , & full_base , abf );
2006
+ sti = stat_tracking_info (branch , & ours , & theirs , & full_base , 0 , abf );
1981
2007
if (sti < 0 ) {
1982
2008
if (!full_base )
1983
2009
return 0 ;
0 commit comments