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 to a revision of the upstream
8# repository. Modified from Chromium src/third_party/libvpx/update_libvpx.sh
9
10# Usage:
11#
12# $ ./update_libvpx.sh [branch | revision | file or url containing a revision]
13# When specifying a branch it may be necessary to prefix with origin/
14
15# Tools required for running this tool:
16#
17# 1. Linux / Mac
18# 2. git
19
20export LC_ALL=C
21
22# Location for the remote git repository.
23GIT_REPO="https://chromium.googlesource.com/webm/libvpx"
24
25# Update to TOT by default.
26GIT_BRANCH="origin/master"
27
28# Relative path of target checkout.
29LIBVPX_SRC_DIR="libvpx"
30
31BASE_DIR=`pwd`
32
33if [ -n "$1" ]; then
34  GIT_BRANCH="$1"
35  if [ -f "$1"  ]; then
36    GIT_BRANCH=$(<"$1")
37  elif [[ $1 = http* ]]; then
38    GIT_BRANCH=`curl $1`
39  fi
40fi
41
42prev_hash="$(egrep "^Commit: [[:alnum:]]" README.android | awk '{ print $2 }')"
43echo "prev_hash:$prev_hash"
44
45rm -rf $LIBVPX_SRC_DIR
46mkdir $LIBVPX_SRC_DIR
47cd $LIBVPX_SRC_DIR
48
49# Start a local git repo.
50git clone $GIT_REPO .
51
52# Switch the content to the desired revision.
53git checkout -b tot $GIT_BRANCH
54
55add="$(git diff-index --diff-filter=A $prev_hash | \
56tr -s [:blank:] ' ' | cut -f6 -d\ )"
57delete="$(git diff-index --diff-filter=D $prev_hash | \
58tr -s [:blank:] ' ' | cut -f6 -d\ )"
59
60# Get the current commit hash.
61hash=$(git log -1 --format="%H")
62
63# README reminder.
64echo "Update README.android:"
65echo "==============="
66echo "Date: $(date +"%A %B %d %Y")"
67echo "Branch: $GIT_BRANCH"
68echo "Commit: $hash"
69echo "==============="
70echo ""
71
72# Commit message header.
73echo "Commit message:"
74echo "==============="
75echo "libvpx: Pull from upstream"
76echo ""
77
78# Output the current commit hash.
79echo "Current HEAD: $hash"
80echo ""
81
82# Output log for upstream from current hash.
83if [ -n "$prev_hash" ]; then
84  echo "git log from upstream:"
85  pretty_git_log="$(git log \
86                    --no-merges \
87                    --topo-order \
88                    --pretty="%h %s" \
89                    --max-count=20 \
90                    $prev_hash..$hash)"
91  if [ -z "$pretty_git_log" ]; then
92    echo "No log found. Checking for reverts."
93    pretty_git_log="$(git log \
94                      --no-merges \
95                      --topo-order \
96                      --pretty="%h %s" \
97                      --max-count=20 \
98                      $hash..$prev_hash)"
99  fi
100  echo "$pretty_git_log"
101  # If it makes it to 20 then it's probably skipping even more.
102  if [ `echo "$pretty_git_log" | wc -l` -eq 20 ]; then
103    echo "<...>"
104  fi
105fi
106
107# Commit message footer.
108echo ""
109echo "==============="
110
111# Git is useless now, remove the local git repo.
112rm -rf .git .gitignore .gitattributes
113
114# Add and remove files.
115echo "$add" | xargs -I {} git add {}
116echo "$delete" | xargs -I {} git rm --ignore-unmatch {}
117
118# Find empty directories and remove them.
119find . -type d -empty -exec git rm {} \;
120
121chmod 755 build/make/*.sh build/make/*.pl configure
122
123cd $BASE_DIR
124