Added helper script for easier V8 updates
authorSimon Hausmann <simon.hausmann@nokia.com>
Thu, 5 Jan 2012 13:18:03 +0000 (14:18 +0100)
committerSimon Hausmann <simon.hausmann@nokia.com>
Thu, 5 Jan 2012 13:44:38 +0000 (14:44 +0100)
It won't take away the pain of resolving conflicts, but it'll hide
the git magic from you :)

Change-Id: I6901ca8edb8263ea733a3d4b94393a06e8f25731
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
README
bin/update-v8.sh [new file with mode: 0755]

diff --git a/README b/README
index 2672f6d..3b66d25 100644 (file)
--- a/README
+++ b/README
@@ -5,16 +5,19 @@ affects V8 itself and not the build system around it.
 
 Updating v8:
 
-1) Reset src/3rdparty/v8 to a V8 commit of your choice, for example:
+Run
 
-    git fetch https://github.com/v8/v8.git refs/tags/3.7.2
-    git rm --cached -r src/3rdparty/v8
-    git read-tree --prefix=src/3rdparty/v8 FETCH_HEAD
-    git checkout src/3rdparty/v8
-    git commit
+    ./bin/update-v8.sh [url] [refspec]
 
-2) Cherry-pick our modifications from before:
+to update src/3rdparty/v8 to a specific v8 version. The script will remove
+all Qt specific modifications and save them in /tmp/v8_patch, where they
+can be applied from using git am.
 
-    gitk src/3rdparty/v8
+For example:
 
-   and then cherry-pick the changes since the last v8 import.
+    ./bin/update-v8.sh https://github.com/v8/v8.git refs/tags/3.7.3
+    git commit -e -F commitlog.txt
+    git am -3 /tmp/v8_patch
+
+In the likely case of conflicts, follow the git instructions about continuing
+the patch application process after resolving the conflicts.
diff --git a/bin/update-v8.sh b/bin/update-v8.sh
new file mode 100755 (executable)
index 0000000..d6f7826
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+die() {
+    echo $*
+    exit 1
+}
+
+if [ $# -eq 2 ]; then
+    repository=$1
+    tag=$2
+else
+    die "usage: $0 [url] [commit]"
+fi
+
+require_clean_work_tree() {
+    # test if working tree is dirty
+    git rev-parse --verify HEAD > /dev/null &&
+    git update-index --refresh &&
+    git diff-files --quiet &&
+    git diff-index --cached --quiet HEAD ||
+    die "Working tree is dirty"
+}
+
+test -z "$(git rev-parse --show-cdup)" || {
+       exit=$?
+       echo >&2 "You need to run this command from the toplevel of the working tree."
+       exit $exit
+}
+
+echo "checking working tree"
+require_clean_work_tree
+
+echo "fetching"
+git fetch $repository $tag
+if [ $? != 0 ]; then
+    die "git fetch failed"
+fi
+
+rev=`git rev-parse FETCH_HEAD`
+
+srcdir=src/3rdparty/v8
+absSrcDir=$PWD/$srcdir
+localDiff=
+
+echo "replacing $srcdir"
+if [  -d $srcdir ]; then
+    git ls-files $srcdir | xargs rm
+    git ls-files -z $srcdir | git update-index --force-remove -z --stdin
+    lastImport=`git rev-list --max-count=1 HEAD -- $srcdir/ChangeLog`
+    changes=`git rev-list --no-merges --reverse $lastImport.. -- $srcdir`
+    localDiff=/tmp/v8_patch
+    echo -n>$localDiff
+    for change in $changes; do
+        echo "Saving commit $change"
+        git show -p --stat "--pretty=format:%nFrom %H Mon Sep 17 00:00:00 2001%nFrom: %an <%ae>%nDate: %ad%nSubject: %s%n%b%n" $change -- $srcdir >> $localDiff
+        echo "-- " >> $localDiff
+        echo "1.2.3" >> $localDiff
+        echo >> $localDiff
+    done
+    if [ -s $localDiff ]; then
+        echo "Saved locally applied patches to $localDiff"
+    else
+        localDiff=""
+    fi
+else
+    mkdir -p $srcdir
+fi
+
+git read-tree --prefix=$srcdir $rev
+git checkout $srcdir
+
+cat >commitlog.txt <<EOT
+Updated V8 from $repository to $rev
+EOT
+
+echo "Changes:"
+echo
+git --no-pager diff --name-status --cached $srcdir
+
+echo
+echo "Wrote commitlog.txt. Use with"
+echo
+echo "    git commit -e -F commitlog.txt"
+echo
+echo "to commit your changes"
+
+if [ -n "$localDiff" ]; then
+    echo
+    echo "The Qt specific modifications to V8 are now stored as a git patch in $localDiff"
+    echo "You may want to appy them with"
+    echo
+    echo "    git am -3 $localDiff"
+    echo
+fi