index : asp32 | |
Archlinux32 fork of asp - obsolete | gitolite user |
summaryrefslogtreecommitdiff |
author | Dave Reisner <dreisner@archlinux.org> | 2014-08-16 23:05:40 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2014-08-16 23:05:40 -0400 |
commit | 784a38709849f25b71cab585c73c6ba509de38ad (patch) | |
tree | 626dea04695a1991f633a1722595c772b473a94c /remote.inc.sh | |
parent | f40e18e6d1e442aecb41be365832a86aa9acab5d (diff) |
-rw-r--r-- | remote.inc.sh | 33 |
diff --git a/remote.inc.sh b/remote.inc.sh index a615d24..2cce6ba 100644 --- a/remote.inc.sh +++ b/remote.inc.sh @@ -1,14 +1,37 @@ declare -A refcache=() +__remote_refcache_get() { + local remote=$1 ttl=3600 now= cachetime= cachefile=$ASPCACHE/remote-$remote + + # miss + cachetime=$(stat -c %Y "$cachefile" 2>/dev/null) || return 1 + + printf -v now '%(%s)T' -1 + + # miss + (( now > (cachetime + ttl) )) && return 1 + + # hit + mapfile -t "$2" <"$cachefile" +} + +__remote_refcache_update() { + local remote=$1 cachefile=$ASPCACHE/remote-$remote + + trap "rm -f '$cachefile~'" RETURN + + git ls-remote "$remote" 'refs/heads/packages/*' | + awk '{ sub(/refs\/heads\//, "", $2); print $2 }' >"$cachefile~" && + mv "$cachefile"{~,} +} + remote_get_all_refs() { local remote=$1 - if [[ -z ${refcache["$remote"]+cached} ]]; then - refcache["$remote"]=$(git ls-remote "$remote" 'refs/heads/packages/*' | - awk '{ sub(/refs\/heads\//, "", $2); print $2 }') + if ! __remote_refcache_get "$remote" "$2"; then + __remote_refcache_update "$remote" + __remote_refcache_get "$remote" "$2" fi - - mapfile -t "$2" <<<"${refcache["$remote"]}" } remote_has_package() { |