diff options
| -rwxr-xr-x | git-sonar | 52 |
1 files changed, 7 insertions, 45 deletions
@@ -6,8 +6,6 @@ GIT_SONAR_VERSION="v0.8.1" -dot_git="" - prepare_colors() { PRINT_F_OPTION="" @@ -43,58 +41,22 @@ prepare_colors() { } -dot_git() { - if [ -n "$dot_git" ]; then - # cache dot_git to save calls to rev-parse - printf '%s' "$dot_git" - elif [ -d .git ]; then - dot_git=".git" - printf '%s' $dot_git - else - dot_git="$(git rev-parse --git-dir 2>/dev/null)" - printf '%s' "$dot_git" - fi -} - is_repo() { git-precheck --quiet [ $? -lt 4 ] } -record_timestamp() { - touch "$(dot_git)/lastupdatetime" -} - -timestamp() { - if [[ $OSTYPE == darwin* ]]; then - printf '%s' "$(stat -f%m "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" - else - printf '%s' "$(stat -c %Y "$(dot_git)/lastupdatetime" 2>/dev/null || printf '%s' "0")" - fi -} - -time_now() { - printf '%s' "$(date +%s)" -} - -time_to_update() { - last_time_updated="${1:-$FETCH_TIME}" - local timesincelastupdate="$(($(time_now) - $(timestamp)))" - if (( $timesincelastupdate > $last_time_updated )); then - # time to update return 0 (which is true) - return 0 - else - # not time to update return 1 (which is false) - return 1 - fi -} - fetch() { FETCH_TIME="${GIT_RADAR_FETCH_TIME:-"$((5 * 60))"}" + TS_FILE="$(git rev-parse --git-path lastupdatetime 2>/dev/null)" + + now="$(date '+%s')" + timestamp="$(cat "$TS_FILE" 2>/dev/null)" + [ "$timestamp" -eq "$timestamp" ] >/dev/null 2>&1 || timestamp="0" - if time_to_update "$FETCH_TIME"; then - record_timestamp + if [ "$((now - timestamp))" -ge "$FETCH_TIME" ]; then nohup git fetch --quiet >/dev/null 2>&1 & + echo "$now" >"$TS_FILE" fi } |
