borenet@google.com | 405ebbc | 2012-08-27 19:37:48 +0000 | [diff] [blame] | 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 | |
| 13 | REPO=${REPO:-"https://skia-autogen.googlecode.com"} |
| 14 | REVS_TO_KEEP=${REVS_TO_KEEP:-50} |
| 15 | REPO_SVN="${REPO}/svn" |
| 16 | CLONE_DIR="local_clone_dir" |
| 17 | LOCAL_CLONE="$(pwd)/${CLONE_DIR}" |
| 18 | |
| 19 | echo "Creating local repository in ${LOCAL_CLONE}" |
| 20 | svnadmin create ${LOCAL_CLONE} |
| 21 | pushd ${LOCAL_CLONE}/hooks > /dev/null |
| 22 | echo "#!/bin/sh" > pre-revprop-change |
| 23 | chmod 755 pre-revprop-change |
| 24 | popd > /dev/null |
| 25 | |
| 26 | # Determine the latest revision. Note that any revisions committed while we |
| 27 | # were syncing will be lost forever! |
| 28 | END=`svn info ${REPO_SVN} | grep Revision | cut -c11-` |
| 29 | START=$((END-REVS_TO_KEEP)) |
| 30 | DUMPFILE="skia-autogen_r${START}-${END}.dump" |
| 31 | |
| 32 | echo "Cloning ${REPO_SVN} into ${LOCAL_CLONE}..." |
| 33 | svnsync init file://${LOCAL_CLONE} ${REPO_SVN} |
| 34 | svnsync --non-interactive sync file://${LOCAL_CLONE} |
| 35 | |
| 36 | echo "Dumping revisions ${START} to ${END} to ${DUMPFILE}." |
| 37 | svnadmin dump --revision ${START}:${END} ${LOCAL_CLONE} > ${DUMPFILE} |
| 38 | |
| 39 | echo "Removing temporary local clone." |
| 40 | rm -rf ${LOCAL_CLONE} |
| 41 | |
| 42 | echo "Re-creating local clone from ${DUMPFILE}." |
| 43 | svnadmin create ${LOCAL_CLONE} |
| 44 | svnadmin load ${LOCAL_CLONE} < ${DUMPFILE} |
| 45 | |
| 46 | echo "Deleting ${DUMPFILE}" |
| 47 | rm ${DUMPFILE} |
| 48 | |
| 49 | echo "Now you need to reset the remote repository. Typically, a link to do this" |
| 50 | echo "can be found at (${REPO}/adminSource). |
| 51 | echo "Please do so and press any key to continue." |
| 52 | read -n 1 -s |
| 53 | |
| 54 | echo "Syncing ${LOCAL_CLONE} to ${REPO_SVN}." |
| 55 | svnsync init ${REPO_SVN} file://${LOCAL_CLONE} |
| 56 | svnsync sync ${REPO_SVN} |
| 57 | |
| 58 | echo "Removing temporary local clone." |
| 59 | rm -rf ${LOCAL_CLONE} |
| 60 | |
| 61 | echo "Removing local checkout." |
| 62 | rm -rf ${CHECKOUT_DIR} |
| 63 | |
| 64 | echo "Finished!" |