Skip to content

Commit ef734e2

Browse files
committed
improved cache key
Keeping the human readable part, the shasum should be on the origin url rather than the repo path. This way if multiple repos share the same project name and same origin, they share the cached check. This also means that when the origin is changed then cache invalidates and we'll immediately go off to look at the new origin.
1 parent bfe387e commit ef734e2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bin/git_cautious_check_remote

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Intended to guard against this machine auto-bombing a remote repo.
44
# Will meter out remote checks to one per hour while no remote updates.
55

6+
# cache file is part human reable, pulled from the gitDir path, and part a low
7+
# collision hash made from the origin.url. This means cache will refresh
8+
# whenever the repo base folder is renamed or origin is changed.
9+
610
# to show debug output, invoke like so:
711
# DEBUG=1 git_cautious_check_remote
812

@@ -15,7 +19,8 @@ then
1519
exit 1
1620
fi
1721

18-
if ! git config --get remote.origin.url >/dev/null 2>/dev/null
22+
remote=$( git config --get remote.origin.url 2>/dev/null)
23+
if [ $? != 0 -o -z "$remote" ]
1924
then
2025
[ $DEBUG ] && echo no upstream in this git repo
2126
exit 1
@@ -42,7 +47,7 @@ repoName=$( printf "%s" "$gitDir" | sed -e 's,/[^/]*$,,' -e 's,.*/,,g' )
4247
[ $DEBUG ] && echo repoName: $repoName
4348

4449

45-
flagFile="${repoName}-$( printf %s $gitDir | shasum | head -c 8 )"
50+
flagFile="${repoName}-$( printf %s $remote | shasum | head -c 8 )"
4651
flagFile="/tmp/${me}/${flagFile%% *}"
4752

4853
[ $DEBUG ] && echo flagfile: $flagFile

0 commit comments

Comments
 (0)