+# branch_needs_update
+# This is a helper function for determining whether given branch
+# is up-to-date wrt. its dependencies. It expects input as if it
+# is called as a recurse_deps() helper.
+# In case the branch does need update, it will echo it together
+# with the branch backtrace on the output (see needs_update()
+# description for details) and set $_ret to non-zero.
+branch_needs_update()
+{
+ _dep_base_update=
+ if [ -n "$_dep_is_tgish" ]; then
+ if has_remote "$_dep"; then
+ branch_contains "$_dep" "refs/remotes/$base_remote/$_dep" || _dep_base_update=%
+ fi
+ # This can possibly override the remote check result;
+ # we want to sync with our base first
+ branch_contains "$_dep" "refs/top-bases/$_dep" || _dep_base_update=:
+ fi
+
+ if [ -n "$_dep_base_update" ]; then
+ # _dep needs to be synced with its base/remote
+ echo "$_dep_base_update $_dep $_depchain"
+ _ret=1
+ elif [ -n "$_name" ] && ! branch_contains "refs/top-bases/$_name" "$_dep"; then
+ # Some new commits in _dep
+ echo "$_dep $_depchain"
+ _ret=1
+ fi
+}
+
+# needs_update NAME
+# This function is recursive; it outputs reverse path from NAME
+# to the branch (e.g. B_DIRTY B1 B2 NAME), one path per line,
+# inner paths first. Innermost name can be ':' if the head is
+# not in sync with the base or '%' if the head is not in sync
+# with the remote (in this order of priority).
+# It will also return non-zero status if NAME needs update.
+# If needs_update() hits missing dependencies, it will append
+# them to space-separated $missing_deps list and skip them.
+needs_update()
+{
+ recurse_deps branch_needs_update "$@"
+}
+