1#/bin/bash
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# roll_autogen.sh: Helper script for removing old revisions from an svn
7# repository.  Unfortunately, the only way to discard old revisions is to clone
8# the repository locally, use svnadmin to dump a range of commits from the local
9# copy, re-import them into a brand-new repository, "reset" the original repo,
10# and then import the commits from the new repository into the original.  This
11# script automates all of that except for resetting the original repository.
12
13REPO=${REPO:-"https://skia-autogen.googlecode.com"}
14REVS_TO_KEEP=${REVS_TO_KEEP:-50}
15REPO_SVN="${REPO}/svn"
16CLONE_DIR="local_clone_dir"
17LOCAL_CLONE="$(pwd)/${CLONE_DIR}"
18
19echo "Creating local repository in ${LOCAL_CLONE}"
20svnadmin create ${LOCAL_CLONE}
21pushd ${LOCAL_CLONE}/hooks > /dev/null
22echo "#!/bin/sh" > pre-revprop-change
23chmod 755 pre-revprop-change 
24popd > /dev/null
25
26# Determine the latest revision.  Note that any revisions committed while we
27# were syncing will be lost forever!
28END=`svn info ${REPO_SVN} | grep Revision | cut -c11-`
29START=$((END-REVS_TO_KEEP))
30DUMPFILE="skia-autogen_r${START}-${END}.dump"
31
32echo "Cloning ${REPO_SVN} into ${LOCAL_CLONE}..."
33svnsync init file://${LOCAL_CLONE} ${REPO_SVN}
34svnsync --non-interactive sync file://${LOCAL_CLONE}
35
36echo "Dumping revisions ${START} to ${END} to ${DUMPFILE}."
37svnadmin dump --revision ${START}:${END} ${LOCAL_CLONE} > ${DUMPFILE}
38
39echo "Removing temporary local clone."
40rm -rf ${LOCAL_CLONE}
41
42echo "Re-creating local clone from ${DUMPFILE}."
43svnadmin create ${LOCAL_CLONE}
44svnadmin load ${LOCAL_CLONE} < ${DUMPFILE}
45
46echo "Deleting ${DUMPFILE}"
47rm ${DUMPFILE}
48
49echo "Now you need to reset the remote repository. Typically, a link to do this"
50echo "can be found at (${REPO}/adminSource).
51echo "Please do so and press any key to continue."
52read -n 1 -s
53
54echo "Syncing ${LOCAL_CLONE} to ${REPO_SVN}."
55svnsync init ${REPO_SVN} file://${LOCAL_CLONE}
56svnsync sync ${REPO_SVN}
57
58echo "Removing temporary local clone."
59rm -rf ${LOCAL_CLONE}
60
61echo "Removing local checkout."
62rm -rf ${CHECKOUT_DIR}
63
64echo "Finished!"
65