Newer Older
127 lines | 4.131kb
déplacement depuis dépôt con...
Sébastien MARQUE authored on 2021-05-28
1
#!/bin/bash
2

            
3
hangar[path]=$HOME/.fgfs/flightgear-fgaddon/Aircraft
4

            
5
hangar[name]=FGADDON
6
hangar[source]=sourceforge
7
hangar[type]=svn
8
hangar[url]=https://svn.code.sf.net/p/flightgear/fgaddon/trunk/Aircraft
9
hangar[active]=1
10

            
11
function getfromrepo () {
12
    svn cat ${hangar[url]}/$1
13
}
14

            
15
function on_exit () {
16
    rm -f $aircrafts $aircraft
17
}
18

            
19
function parse_repo_history () {
20
    function getaircraftinfo () { # $1 = aircraft
21
        svn list --xml --depth files ${hangar[url]}/$1 > $aircraft
22
        unset xmlgetnext_empty_tag
23
        while xmlgetnext; do
24
            if test "$TAG" = 'name' && test "${VALUE/%-set.xml}" != "$VALUE"; then
25
                add_setxml_for_aircraft $1 ${VALUE/%-set.xml}
26
            fi
27
        done < $aircraft
28
    }
29

            
30
    aircrafts=$temppath/Aircraft-$tempid
31
    aircraft=$temppath/aircraft-$tempid
32

            
33
    if test $latest_revision -eq 1; then
34
        echo getting repository list
35
        if ! svn list --xml --depth immediates ${hangar[url]} > $aircrafts; then
36
            echo "error while retrieving list"
37
            exit
38
        fi
39
        total=$(grep -c '<entry' $aircrafts)
40
        is_ac=0
41
    else
42
        if test ${latest_revision:-0} -gt $(svn info --show-item revision ${hangar[url]}); then
43
            echo "already latest revisison"
44
            return
45
        fi
46
        echo "downloading history from revision ${latest_revision:-0}"
47
        if ! svn log --revision ${latest_revision:-0}:HEAD --xml --verbose ${hangar[url]} > $aircrafts; then
48
            echo "error while retrieving history"
49
            exit
50
        fi
51
        total=$(grep -c '<logentry' $aircrafts)
52
    fi
53

            
54
    progress=0
55

            
56
    echo parsing repository
57

            
58
    unset xmlgetnext_empty_tag
59
    while xmlgetnext; do
60

            
61
        if test $latest_revision -eq 1; then
62
            if test "$TAG" = 'entry kind="dir"'; then
63
                is_ac=1
64
                continue
65
            elif test $is_ac -eq 0 -a "$TAG" != '/list'; then
66
                continue
67
            fi
68
        else
69
            if test "${TAG%% *}" = 'logentry'; then
70
                is_ac=1
71
            elif test ${is_ac:-0} -eq 0 -a "$TAG" != '/log'; then
72
                continue
73
            fi
74
        fi
75

            
76
        case "$TAG" in
77
            'name')
78
                add_record name $VALUE
79
            ;;
80
            'logentry revision='*|'commit revision='*)
81
                add_record revision ${TAG#*=}
82
            ;;
83
            'author')
84
                add_record author ${VALUE//\'/\'\'}
85
            ;;
86
            'date')
87
                add_record date $(date +%s -d "$VALUE")
88
            ;;
89
            'path '*)
90
                TAG=${TAG#* }
91
                TAG=${TAG// /;}
92
                TAG=${TAG//-/_}
93
                eval $(echo ${TAG// /;})
94
                path=(${VALUE//\// })
95
                if test $kind = 'dir' -a ${#path[@]} -eq 3 -a $action = 'D'; then
96
                    sqlite_request "delete from setxml
97
                                    where variantof in (
98
                                        select id from aircrafts
99
                                        where name = '${path[2]}'
100
                                        and hangar = ${hangar[id]}
101
                                    )"
102
                    sqlite_request "delete from aircrafts
103
                                    where name = '${path[2]}'
104
                                    and hangar = ${hangar[id]}"
105
                    is_ac=0
106
                    continue
107
                fi
108
                is_ac=1
109
                add_record name ${path[2]}
110
            ;;
111
            '/logentry'|'/entry')
112
                getaircraftinfo $(get_record name)
113
                add_aircraft
114
                newprogress=$((++entry * 100 / $total))
115
                if test $(( $newprogress - $progress )) -ge ${progress_granularity:-1}; then
116
                    progress=$newprogress
117
                    echo "$progress% ($(sqlite_request 'select count(name) from recover_aircrafts'))"
118
                fi
119
                is_ac=0
120
            ;;
121
            '/list'|'/log')
122
                apply_revision
123
                break
124
            ;;
125
        esac
126
    done < $aircrafts
127
}