@@ -2007,16 +2007,23 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
2007
2007
}
2008
2008
2009
2009
/*
2010
- * Compare a branch with its upstream, and save their differences (number
2011
- * of commits) in *num_ours and *num_theirs. The name of the upstream branch
2012
- * (or NULL if no upstream is defined) is returned via *upstream_name, if it
2013
- * is not itself NULL.
2010
+ * Lookup the upstream branch for the given branch and if present, optionally
2011
+ * compute the commit ahead/behind values for the pair.
2012
+ *
2013
+ * If abf is AHEAD_BEHIND_FULL, compute the full ahead/behind and return the
2014
+ * counts in *num_ours and *num_theirs. If abf is AHEAD_BEHIND_QUICK, skip
2015
+ * the (potentially expensive) a/b computation (*num_ours and *num_theirs are
2016
+ * set to zero).
2017
+ *
2018
+ * The name of the upstream branch (or NULL if no upstream is defined) is
2019
+ * returned via *upstream_name, if it is not itself NULL.
2014
2020
*
2015
2021
* Returns -1 if num_ours and num_theirs could not be filled in (e.g., no
2016
- * upstream defined, or ref does not exist), 0 otherwise.
2022
+ * upstream defined, or ref does not exist). Returns 0 if the commits are
2023
+ * identical. Returns 1 if commits are different.
2017
2024
*/
2018
2025
int stat_tracking_info (struct branch * branch , int * num_ours , int * num_theirs ,
2019
- const char * * upstream_name )
2026
+ const char * * upstream_name , enum ahead_behind_flags abf )
2020
2027
{
2021
2028
struct object_id oid ;
2022
2029
struct commit * ours , * theirs ;
@@ -2044,11 +2051,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2044
2051
if (!ours )
2045
2052
return -1 ;
2046
2053
2054
+ * num_theirs = * num_ours = 0 ;
2055
+
2047
2056
/* are we the same? */
2048
- if (theirs == ours ) {
2049
- * num_theirs = * num_ours = 0 ;
2057
+ if (theirs == ours )
2050
2058
return 0 ;
2051
- }
2059
+ if (abf == AHEAD_BEHIND_QUICK )
2060
+ return 1 ;
2052
2061
2053
2062
/* Run "rev-list --left-right ours...theirs" internally... */
2054
2063
argv_array_push (& argv , "" ); /* ignored */
@@ -2064,8 +2073,6 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2064
2073
die ("revision walk setup failed" );
2065
2074
2066
2075
/* ... and count the commits on each side. */
2067
- * num_ours = 0 ;
2068
- * num_theirs = 0 ;
2069
2076
while (1 ) {
2070
2077
struct commit * c = get_revision (& revs );
2071
2078
if (!c )
@@ -2081,7 +2088,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2081
2088
clear_commit_marks (theirs , ALL_REV_FLAGS );
2082
2089
2083
2090
argv_array_clear (& argv );
2084
- return 0 ;
2091
+ return 1 ;
2085
2092
}
2086
2093
2087
2094
/*
@@ -2094,7 +2101,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
2094
2101
char * base ;
2095
2102
int upstream_is_gone = 0 ;
2096
2103
2097
- if (stat_tracking_info (branch , & ours , & theirs , & full_base ) < 0 ) {
2104
+ if (stat_tracking_info (branch , & ours , & theirs , & full_base ,
2105
+ AHEAD_BEHIND_FULL ) < 0 ) {
2098
2106
if (!full_base )
2099
2107
return 0 ;
2100
2108
upstream_is_gone = 1 ;
0 commit comments