1
#!/bin/bash
2
3
die() {
4
    echo $*
5
    exit 1
6
}
7
8
tarball=""
9
10
if [ $# -eq 1 ]; then
11
    tarball=$1
12
else
13
    die "usage: $0 path_to_archive"
14
fi
15
16
require_clean_work_tree() {
17
    # test if working tree is dirty
18
    git rev-parse --verify HEAD > /dev/null &&
19
    git update-index --refresh &&
20
    git diff-files --quiet &&
21
    git diff-index --cached --quiet HEAD ||
22
    die "Working tree is dirty"
23
}
24
25
test -z "$(git rev-parse --show-cdup)" || {
26
       exit=$?
27
       echo >&2 "You need to run this command from the toplevel of the working tree."
28
       exit $exit
29
}
30
31
echo "checking working tree"
32
require_clean_work_tree
33
34
prefix=`basename $tarball .tar.gz`
35
tmptarball=`mktemp /tmp/webkit-snapshot.tar.XXXXXX` || exit 1
36
gzip -dc "$tarball" > $tmptarball || exit 1
37
tarball=$tmptarball
38
39
echo "removing unwanted files and directories"
40
for dir in Tools; do
41
    echo "    removing $dir"
42
    tar --delete --file=$tarball $prefix/$dir
43
done
44
45
srcdir=src/3rdparty/webkit
46
absSrcDir=$PWD/$srcdir
47
localDiff=
48
lastImportRevison=
49
50
tag=`cat src/3rdparty/webkit/.tag`
51
52
echo "replacing $srcdir"
53
if [  -d $srcdir ]; then
54
    lastImportRevison=$tag
55
    git ls-files $srcdir | grep -v src/3rdparty/webkit/include/ | xargs rm
56
    git ls-files -z src/3rdparty/webkit | git update-index --force-remove -z --stdin
57
    lastImport=`git rev-list --max-count=1 HEAD -- src/3rdparty/webkit/.tag`
58
    changes=`git rev-list --no-merges --reverse $lastImport.. -- src/3rdparty/webkit`
59
    localDiff=/tmp/webkit_patch
60
    echo -n>$localDiff
61
    for change in $changes; do
62
        echo "Saving commit $change"
63
        git show -p --stat "--pretty=format:%nFrom %H Mon Sep 17 00:00:00 2001%nFrom: %an <%ae>%nDate: %ad%nSubject: Re-apply change $change by %an%n%n%s%n%b%n" $change -- src/3rdparty/webkit >> $localDiff
64
        echo "-- " >> $localDiff
65
        echo "1.2.3" >> $localDiff
66
        echo >> $localDiff
67
    done
68
    if [ -s $localDiff ]; then
69
        echo "Saved locally applied patches to $localDiff"
70
    else
71
        localDiff=""
72
    fi
73
else
74
    mkdir -p $srcdir
75
fi
76
77
tar xf $tarball -C $srcdir --strip-components=1
78
git add $srcdir
79
git add -f $srcdir/WebKitLibraries/*.a
80
tag=`cat src/3rdparty/webkit/.tag`
81
82
cat >$srcdir/VERSION <<EOT
83
This is a snapshot of the Qt port of WebKit from
84
85
        git://gitorious.org/qtwebkit/qtwebkit.git
86
87
and has the sha1 checksum
88
89
        $tag
90
EOT
91
git add $srcdir/VERSION
92
93
git diff-files --name-only -z | git update-index --remove -z --stdin
94
95
rm -f $tarball
96
97
cat >commitlog.txt <<EOT
98
Updated WebKit to $tag
99
EOT
100
101
#if [ -d "$repository/.git" -a -n "$lastImportRevison" ]; then
102
#    echo >>commitlog.txt
103
#    echo "Changes in WebKit/qt since the last update:" >>commitlog.txt
104
#    echo >>commitlog.txt
105
#    git --git-dir=$repository/.git diff $lastImportRevison $rev -- WebKit/qt/ChangeLog | sed -n -e "s,^\+\(.*\),\1,p" >>commitlog.txt
106
#fi
107
108
echo "Changes:"
109
echo
110
git --no-pager diff --name-status --cached
111
112
echo
113
echo "Wrote commitlog.txt. Use with"
114
echo
115
echo "    git commit -e -F commitlog.txt"
116
echo
117
echo "to commit your changes"
118
119
if [ -n "$localDiff" ]; then
120
    echo
121
    echo "The changes that were locally stored in Perforce are now stored as a git patch in $localDiff"
122
    echo "You may want to appy them with"
123
    echo
124
    echo "    git am -3 $localDiff"
125
    echo
126
fi