exit 1
}
-# cat_file "topic:file"
-# Like `git cat-file blob $1`, but topics '(i)' and '(w)' means index and worktree
+# cat_file TOPIC:PATH [FROM]
+# cat the file PATH from branch TOPIC when FROM is empty.
+# FROM can be -i or -w, than the file will be from the index or worktree,
+# respectively. The caller should than ensure that HEAD is TOPIC, to make sense.
cat_file()
{
- arg="$1"
- case "$arg" in
- '(w):'*)
- cat "${arg#(w):}"
+ path="$1"
+ case "${2-}" in
+ -w)
+ cat "$root_dir/${path#*:}"
;;
- '(i):'*)
+ -i)
# ':file' means cat from index
- git cat-file blob "${arg#(i)}"
+ git cat-file blob ":${path#*:}"
+ ;;
+ '')
+ git cat-file blob "$path"
;;
*)
- git cat-file blob "$arg"
+ die "Wrong argument to cat_file: '$2'"
;;
esac
}
recurse_deps branch_needs_update "$@"
}
-# branch_empty NAME
+# branch_empty NAME [-i | -w]
branch_empty()
{
- [ -z "$(git diff-tree "refs/top-bases/$1" "$1" -- | fgrep -v " .top")" ]
+ [ "$(pretty_tree "$1" -b)" = "$(pretty_tree "$1" ${2-})" ]
}
-# list_deps
+# list_deps [-i | -w]
+# -i/-w apply only to HEAD
list_deps()
{
+ local head
+ local head_from
+ local from
+ head_from=${1-}
+ head="$(git symbolic-ref -q HEAD)" ||
+ head="..detached.."
+
git for-each-ref refs/top-bases |
while read rev type ref; do
name="${ref#refs/top-bases/}"
continue;
fi
- git cat-file blob "$name:.topdeps" | while read dep; do
+ from=$head_from
+ [ "refs/heads/$name" = "$head" ] ||
+ from=
+ cat_file "$name:.topdeps" $from | while read dep; do
dep_is_tgish=true
ref_exists "refs/top-bases/$dep" ||
dep_is_tgish=false