summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2014-08-02 20:10:30 -0400
committerDave Reisner <dreisner@archlinux.org>2014-08-02 20:10:30 -0400
commit640958d36225cbf6d482e193ed4d7d3d44a01d1d (patch)
tree40fc92b028a836dde0a6f1cfb5f36f036b1a78c8
parent504845a766c6cdd6f994e61fb0d73ac5e576dbd0 (diff)
downloadasp32-640958d36225cbf6d482e193ed4d7d3d44a01d1d.tar.xz
remote: cache contents of remotes
-rw-r--r--remote.inc.sh16
1 files changed, 12 insertions, 4 deletions
diff --git a/remote.inc.sh b/remote.inc.sh
index 389f105..1554d3a 100644
--- a/remote.inc.sh
+++ b/remote.inc.sh
@@ -1,14 +1,22 @@
+declare -A refcache=()
+
remote_get_all_refs() {
local remote=$1
- mapfile -t "$2" < <(git ls-remote "$remote" 'refs/heads/packages/*' |
- awk '{ sub(/refs\/heads\//, "", $2); print $2 }')
+ if [[ -z ${refcache["$remote"]} ]]; then
+ refcache["$remote"]=$(git ls-remote "$remote" 'refs/heads/packages/*' |
+ awk '{ sub(/refs\/heads\//, "", $2); print $2 }')
+ fi
+
+ mapfile -t "$2" <<<"${refcache["$remote"]}"
}
remote_has_package() {
- local remote=$1 pkgname=$2
+ local remote=$1 pkgname=$2 refs
+
+ remote_get_all_refs "$remote" refs
- git ls-remote --heads --exit-code "$remote" "$pkgname" &>/dev/null
+ in_array "$remote/$pkgname" "${refs[@]}"
}
remote_is_tracking() {