1#!/bin/bash -e
2#
3# Copyright (c) 2012 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This tool is used to update libvpx source code with the latest git
8# repository.
9#
10# Make sure you run this in a svn checkout of deps/third_party/libvpx!
11
12# Usage:
13#
14# $ ./update_libvpx.sh [branch | revision | file or url containing a revision]
15# When specifying a branch it may be necessary to prefix with origin/
16
17# Tools required for running this tool:
18#
19# 1. Linux / Mac
20# 2. svn
21# 3. git
22
23export LC_ALL=C
24
25# Location for the remote git repository.
26GIT_REPO="http://git.chromium.org/webm/libvpx.git"
27
28GIT_BRANCH="origin/master"
29LIBVPX_SRC_DIR="source/libvpx"
30BASE_DIR=`pwd`
31
32if [ -n "$1" ]; then
33  GIT_BRANCH="$1"
34  if [ -f "$1"  ]; then
35    GIT_BRANCH=$(<"$1")
36  elif [[ $1 = http* ]]; then
37    GIT_BRANCH=`curl $1`
38  fi
39fi
40
41prev_hash="$(egrep "^Commit: [[:alnum:]]" README.chromium | awk '{ print $2 }')"
42echo "prev_hash:$prev_hash"
43
44rm -rf $(svn ls $LIBVPX_SRC_DIR)
45svn update $LIBVPX_SRC_DIR
46
47cd $LIBVPX_SRC_DIR
48
49# Make sure git doesn't mess up with svn.
50echo ".svn" >> .gitignore
51
52# Start a local git repo.
53git init
54git add .
55git commit -a -m "Current libvpx"
56
57# Add the remote repo.
58git remote add origin $GIT_REPO
59git fetch
60
61add="$(git diff-index --diff-filter=D $GIT_BRANCH | \
62tr -s '\t' ' ' | cut -f6 -d\ )"
63delete="$(git diff-index --diff-filter=A $GIT_BRANCH | \
64tr -s '\t' ' ' | cut -f6 -d\ )"
65
66# Switch the content to the latest git repo.
67git checkout -b tot $GIT_BRANCH
68
69# Output the current commit hash.
70hash=$(git log -1 --format="%H")
71echo "Current HEAD: $hash"
72
73# Output log for upstream from current hash.
74if [ -n "$prev_hash" ]; then
75  echo "git log from upstream:"
76  pretty_git_log="$(git log --no-merges --pretty="%h %s" $prev_hash..$hash)"
77  if [ -z "$pretty_git_log" ]; then
78    echo "No log found. Checking for reverts."
79    pretty_git_log="$(git log --no-merges --pretty="%h %s" $hash..$prev_hash)"
80  fi
81  echo "$pretty_git_log"
82fi
83
84# Git is useless now, remove the local git repo.
85rm -rf .git
86
87# Update SVN with the added and deleted files.
88echo "$add" | xargs -I {} svn add --parents {}
89echo "$delete" | xargs -I {} svn rm {}
90
91# Find empty directories and remove them from SVN.
92find . -type d -empty -not -iwholename '*.svn*' -exec svn rm {} \;
93
94chmod 755 build/make/*.sh build/make/*.pl configure
95
96cd $BASE_DIR
97