chiark / gitweb /
needs_update(): Return non-zero if update is required
authorPetr Baudis <pasky@suse.cz>
Sun, 3 Aug 2008 17:50:04 +0000 (19:50 +0200)
committerPetr Baudis <pasky@suse.cz>
Sun, 3 Aug 2008 17:57:06 +0000 (19:57 +0200)
tg summary can avoid a single extra fork this way, and will be
able to harvest extra status information from needs_update.

tg-info.sh
tg-summary.sh
tg-update.sh
tg.sh

index c95677f2440a90c4a945d734b977abf06cee872b..21b69dc488893a4c7f4f2b2cf98f3cf39e6f4f74 100644 (file)
@@ -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
index 55e9764001ea23c82f38eb0f3f1f1813cdedbf0a..12b60d8d665f77ec679fc4da5a8732b80aede551 100644 (file)
@@ -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'
 
index 5bd9de55455a5b2b1397c35e9e9b9851ec544491..563a62d8fbb293b4140fdd17067caf552d215e9c 100644 (file)
@@ -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 ee14e62860c2a34bda48aecdc7162128bf83fb48..e987561d3a2693159d2b88672839ec9cdb42bad3 100644 (file)
--- 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