Debian Codegraph @

contrib/adjust-pytype-cache.sh

raw
1 #!/bin/bash
2
3 set -e
4 set -u
5 set -o pipefail
6
7 cd "$(hg root)"
8
9 if [ ! -e .pytype ]; then
10 echo "no cache available" >&2
11 exit 0
12 fi
13
14 if [ ! -e .pytype/CACHE_COMMIT ]; then
15 echo "no cache origin information" >&2
16 echo "purging the cache" >&2
17 rm -rf .pytype
18 exit 0
19 fi
20
21 SOURCE_COMMIT=`cat .pytype/CACHE_COMMIT`
22
23 if ! hg log --rev "id($SOURCE_COMMIT)" -T 'HAS MATCH' | grep -q 'HAS MATCH' ; then
24 echo "unknown cache source" >&2
25 echo "purging the cache" >&2
26 rm -rf .pytype
27 exit 0
28 fi
29
30 ### lets fiddle with time stamp !
31 # ninja use timestamp for its cache validation
32
33 changed=`hg status --no-status --removed --added --modified --rev "id($SOURCE_COMMIT)" | wc -l`
34 echo "reusing cache from $SOURCE_COMMIT ($changed file changes)" >&2
35 # first mark the cache content as newer than the repostiory content
36 sleep 1
37 find .pytype -exec touch '{}' ';'
38
39 # then update the timestamp of the file changed between the cache source and the changeset we test
40 sleep 1
41 hg status --no-status --added --modified --rev "id($SOURCE_COMMIT)" | while read f; do
42 touch "$f"
43 done