| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env bash | |
| 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 branch_name="" | |
| 8 checkout_branch=no | |
| 9 create_branch=no | |
| 10 quiet=no | |
| 11 svn_lkgr= | |
| 12 | |
| 13 while [ $# -gt 0 ]; do | |
| 14 case "$1" in | |
| 15 --checkout|--force-branch) | |
| 16 checkout_branch=yes | |
| 17 create_branch=yes | |
| 18 ;; | |
| 19 --closest) | |
| 20 use_closest=yes | |
| 21 ;; | |
| 22 --create) | |
| 23 create_branch=yes | |
| 24 ;; | |
| 25 -n|--name) | |
| 26 branch_name=$2 | |
| 27 create_branch=yes | |
| 28 shift | |
| 29 ;; | |
| 30 -q|--quiet) | |
| 31 quiet=yes | |
| 32 ;; | |
| 33 -r|--revision) | |
| 34 svn_lkgr="$2" | |
| 35 shift | |
| 36 ;; | |
| 37 *) | |
| 38 echo "Unknown option: $1" | |
| 39 echo "Usage:" | |
| 40 echo " --checkout Create a branch and check it out." | |
| 41 echo " --create Create a branch." | |
| 42 echo " --closest Use closest git commit to the target svn revisi
on." | |
| 43 echo " Otherwise --checkout may be required to creat
e" | |
| 44 echo " a git commit for a specific svn revision." | |
| 45 echo " -n, --name <name> Specify the name of branch to create or reset." | |
| 46 echo " This will force the branch using 'git branch
-f '." | |
| 47 echo " -q, --quiet Quiet." | |
| 48 echo " -r, --revision <r> Svn revision number use instead of server provi
ded lkgr." | |
| 49 exit 1 | |
| 50 ;; | |
| 51 esac | |
| 52 shift | |
| 53 done | |
| 54 | |
| 55 if [ -z "$svn_lkgr" ]; then | |
| 56 svn_lkgr=`curl -s http://chromium-status.appspot.com/lkgr` | |
| 57 if [ $? != 0 -o -z "$svn_lkgr" ]; then | |
| 58 echo 'Could not get svn lkgr from chromium-status.appspot.com/lkgr' | |
| 59 exit 1 | |
| 60 fi | |
| 61 fi | |
| 62 | |
| 63 if [ "${svn_lkgr:0:1}" = "r" ]; then | |
| 64 svn_lkgr="${svn_lkgr:1}" | |
| 65 fi | |
| 66 | |
| 67 # Run a trivial git-svn command to force it to update the revision cache | |
| 68 # (which causes spew that might otherwise confuse the next command). | |
| 69 git svn info > /dev/null | |
| 70 if [ $? != 0 ]; then | |
| 71 cat <<EOF 1>&2 | |
| 72 Could not run a trivial git-svn command. You probably need to set up your | |
| 73 working directory for git-svn, by following these instructions: | |
| 74 | |
| 75 http://code.google.com/p/chromium/wiki/UsingNewGit#Initial_checkout | |
| 76 EOF | |
| 77 exit 1 | |
| 78 fi | |
| 79 | |
| 80 git_lkgr=`git svn find-rev r${svn_lkgr}` | |
| 81 if [ $? != 0 -o -z "$git_lkgr" ]; then | |
| 82 cat <<EOF 1>&2 | |
| 83 Could not map svn revision ${svn_lkgr} to a git commit. | |
| 84 You may need to 'git fetch' and try again. | |
| 85 EOF | |
| 86 exit 1 | |
| 87 fi | |
| 88 | |
| 89 set -o pipefail | |
| 90 closest_commit=`git rev-list --ancestry-path \ | |
| 91 --grep='SVN changes up to revision [0-9]*' \ | |
| 92 ${git_lkgr}..refs/remotes/origin/master | tail -1` | |
| 93 if [ $? != 0 -o -z "$closest_commit" ]; then | |
| 94 closest_commit= | |
| 95 closest_svn_commit= | |
| 96 else | |
| 97 closest_svn_commit=`git rev-list -n 1 ${closest_commit}^1` | |
| 98 if [ $? != 0 -o -z "$closest_svn_commit" ]; then | |
| 99 cat <<EOF 1>&2 | |
| 100 I am thoroughly confused. Please file a bug report at http://new.crbug.com. | |
| 101 EOF | |
| 102 exit 1 | |
| 103 fi | |
| 104 closest_svn=`git svn find-rev ${closest_svn_commit}` | |
| 105 fi | |
| 106 | |
| 107 if [ "${use_closest}" = "yes" ]; then | |
| 108 svn_lkgr="${closest_svn}" | |
| 109 git_lkgr="${closest_svn_commit}" | |
| 110 fi | |
| 111 | |
| 112 # Determine lkgr_branch: | |
| 113 if [ "${branch_name}" != "" ]; then | |
| 114 # Use the provided name for the branch. | |
| 115 lkgr_branch="${branch_name}" | |
| 116 | |
| 117 # If the branch already exists, force the update to it. | |
| 118 git rev-parse --verify -q "${branch_name}" >/dev/null | |
| 119 if [ $? -eq 0 ]; then | |
| 120 old_branch_value=`git rev-parse "${branch_name}"` | |
| 121 echo "Will update branch ${lkgr_branch}, it previously was at ${old_branch_v
alue}." | |
| 122 force_branch="--force" | |
| 123 fi | |
| 124 else | |
| 125 # Pick a name for the new branch. Use `git rev-parse` to make sure the branch | |
| 126 # doesn't already exist; if it does, iterate an integer suffix to uniquify it. | |
| 127 lkgr_branch="lkgr_r${svn_lkgr}" | |
| 128 digit=1 | |
| 129 git rev-parse --verify -q "${lkgr_branch}" >/dev/null | |
| 130 while [ $? -eq 0 ]; do | |
| 131 lkgr_branch="lkgr_r${svn_lkgr}_${digit}" | |
| 132 digit=`expr $digit + 1` | |
| 133 git rev-parse --verify -q "${lkgr_branch}" >/dev/null | |
| 134 done | |
| 135 fi | |
| 136 | |
| 137 if [ "${closest_svn_commit}" = "${git_lkgr}" ]; then | |
| 138 echo "${closest_commit}" | |
| 139 if [ "$create_branch" = "yes" ]; then | |
| 140 echo "Creating branch ${lkgr_branch}" | |
| 141 git branch ${force_branch} "${lkgr_branch}" "${closest_commit}" || exit 1 | |
| 142 fi | |
| 143 if [ "$checkout_branch" = "yes" ]; then | |
| 144 git checkout "${lkgr_branch}" | |
| 145 fi | |
| 146 exit 0 | |
| 147 elif [ "${quiet}" = "yes" ]; then | |
| 148 exit 1 | |
| 149 elif [ "${checkout_branch}" = "no" ]; then | |
| 150 echo "There is no master commit which corresponds exactly to svn revision ${sv
n_lkgr}." | |
| 151 echo "Call 'git lkgr --checkout' to create a branch with a commit to match ${s
vn_lkgr}." | |
| 152 if [ -n "$closest_commit" ]; then | |
| 153 echo "The closest commit is r${closest_svn}, ${closest_commit}." | |
| 154 echo "Use the --closest option to use the closest instead of the target revi
sion." | |
| 155 fi | |
| 156 exit 0 | |
| 157 fi | |
| 158 | |
| 159 current_head=`git branch | grep '^\*' | cut -c3-` | |
| 160 if [ "${current_head}" = "(no branch)" ]; then | |
| 161 current_head=`git rev-parse HEAD` | |
| 162 fi | |
| 163 | |
| 164 git checkout --detach "${git_lkgr}" && | |
| 165 python tools/deps2git/deps2git.py -d DEPS -o .DEPS.git -w .. && | |
| 166 git add .DEPS.git && | |
| 167 python tools/deps2git/deps2submodules.py .DEPS.git && | |
| 168 git commit -m "SVN changes up to revision $svn_lkgr" && | |
| 169 git branch ${force_branch} "${lkgr_branch}" HEAD | |
| 170 | |
| 171 if [ $? != 0 ]; then | |
| 172 cat <<EOF | |
| 173 | |
| 174 -------------------------------------------------------------------------------- | |
| 175 Something went wrong! Restoring your previous state by checking out | |
| 176 $current_head | |
| 177 | |
| 178 Please file a bug report at http://new.crbug.com. | |
| 179 -------------------------------------------------------------------------------- | |
| 180 | |
| 181 EOF | |
| 182 git checkout --force $current_head | |
| 183 exit 1 | |
| 184 fi | |
| 185 | |
| 186 git checkout "${lkgr_branch}" | |
| 187 | |
| 188 cat <<EOF | |
| 189 | |
| 190 -------------------------------------------------------------------------------- | |
| 191 The new branch "$lkgr_branch" was branched from this commit: | |
| 192 | |
| 193 $git_lkgr | |
| 194 | |
| 195 ... which maps to the svn commit r${svn_lkgr}. The new branch | |
| 196 has one additional commit, to bring .DEPS.git, .gitmodules, and the | |
| 197 invisible git submodule files up to date with DEPS. | |
| 198 | |
| 199 To create a working branch, do this: | |
| 200 | |
| 201 \$ git branch --track my_new_branch $lkgr_branch | |
| 202 | |
| 203 'git-cl upload' will do the right thing, i.e., it will cherry-pick all | |
| 204 your changes from my_new_branch, but *not* the .DEPS.git+.gitmodules+submodules | |
| 205 commit on $lkgr_branch. | |
| 206 -------------------------------------------------------------------------------- | |
| 207 | |
| 208 EOF | |
| OLD | NEW |