From: Petr Baudis Date: Sun, 3 Aug 2008 17:50:04 +0000 (+0200) Subject: needs_update(): Return non-zero if update is required X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=commitdiff_plain;h=5b78a37b9c29a106980ffe2f24e0dd6b2b60387c;ds=sidebyside needs_update(): Return non-zero if update is required tg summary can avoid a single extra fork this way, and will be able to harvest extra status information from needs_update. --- diff --git a/tg-info.sh b/tg-info.sh index c95677f..21b69dc 100644 --- a/tg-info.sh +++ b/tg-info.sh @@ -43,7 +43,7 @@ echo "Depends: $deps" depcheck="$(mktemp)" missing_deps= -needs_update "$name" >"$depcheck" +needs_update "$name" >"$depcheck" || : if [ -n "$missing_deps" ]; then echo "MISSING: $missing_deps" fi diff --git a/tg-summary.sh b/tg-summary.sh index 55e9764..12b60d8 100644 --- a/tg-summary.sh +++ b/tg-summary.sh @@ -21,7 +21,7 @@ git for-each-ref refs/top-bases | nonempty= ! branch_empty "$name" || nonempty='0' deps_update=' ' - [ -z "$(needs_update "$name")" ] || deps_update='D' + needs_update "$name" >/dev/null || deps_update='D' base_update=' ' branch_contains "$name" "refs/top-bases/$name" || base_update='B' diff --git a/tg-update.sh b/tg-update.sh index 5bd9de5..563a62d 100644 --- a/tg-update.sh +++ b/tg-update.sh @@ -23,7 +23,7 @@ base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" depcheck="$(mktemp)" missing_deps= -needs_update "$name" >"$depcheck" +needs_update "$name" >"$depcheck" || : [ -z "$missing_deps" ] || die "some dependencies are missing: $missing_deps" if [ -s "$depcheck" ]; then # We need to switch to the base branch diff --git a/tg.sh b/tg.sh index ee14e62..e987561 100644 --- a/tg.sh +++ b/tg.sh @@ -85,12 +85,13 @@ branch_contains() # 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. +# 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() { - { - git cat-file blob "$1:.topdeps" 2>/dev/null | + git cat-file blob "$1:.topdeps" 2>/dev/null | { + _ret=0 while read _dep; do if !git rev-parse --verify "$_dep" >/dev/null 2>&1; then # All hope is lost @@ -103,7 +104,9 @@ needs_update() _dep_is_tgish= # Shoo shoo, keep our environment alone! - [ -z "$_dep_is_tgish" ] || (needs_update "$_dep" "$@") + [ -z "$_dep_is_tgish" ] || + (needs_update "$_dep" "$@") || + _ret=$? _dep_base_uptodate=1 if [ -n "$_dep_is_tgish" ]; then @@ -113,12 +116,15 @@ needs_update() if [ -z "$_dep_base_uptodate" ]; then # _dep needs to be synced with its base echo ": $_dep $*" + _ret=1 elif ! branch_contains "refs/top-bases/$1" "$_dep"; then # Some new commits in _dep echo "$_dep $*" + _ret=1 fi done - } || : # $1 is not tracked by TopGit anymore + exit $_ret + } } # branch_empty NAME