File: adjust-pytype-cache.sh

package info (click to toggle)
mercurial 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,080 kB
  • sloc: python: 208,589; ansic: 56,460; tcl: 3,715; sh: 1,839; lisp: 1,483; cpp: 864; makefile: 769; javascript: 649; xml: 36
file content (43 lines) | stat: -rwxr-xr-x 1,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash

set -e
set -u
set -o pipefail

cd "$(hg root)"

if [ ! -e .pytype ]; then
    echo "no cache available" >&2
    exit 0
fi

if [ ! -e .pytype/CACHE_COMMIT ]; then
    echo "no cache origin information" >&2
    echo "purging the cache" >&2
    rm -rf .pytype
    exit 0
fi

SOURCE_COMMIT=`cat .pytype/CACHE_COMMIT`

if ! hg log --rev "id($SOURCE_COMMIT)" -T 'HAS MATCH' | grep -q 'HAS MATCH' ; then
    echo "unknown cache source" >&2
    echo "purging the cache" >&2
    rm -rf .pytype
    exit 0
fi

### lets fiddle with time stamp !
# ninja use timestamp for its cache validation

changed=`hg status --no-status --removed --added --modified --rev "id($SOURCE_COMMIT)" | wc -l`
echo "reusing cache from $SOURCE_COMMIT ($changed file changes)" >&2
# first mark the cache content as newer than the repostiory content
sleep 1
find .pytype -exec touch '{}' ';'

# then update the timestamp of the file changed between the cache source and the changeset we test
sleep 1
hg status --no-status --added --modified --rev "id($SOURCE_COMMIT)" | while read f; do
    touch "$f"
done