OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 force_branch=no | 7 force_branch=no |
8 quiet=no | 8 quiet=no |
| 9 svn_lkgr= |
9 | 10 |
10 while [ $# -gt 0 ]; do | 11 while [ $# -gt 0 ]; do |
11 case "$1" in | 12 case "$1" in |
12 --force-branch) | 13 --force-branch) |
13 force_branch=yes | 14 force_branch=yes |
14 ;; | 15 ;; |
15 -q|--quiet) | 16 -q|--quiet) |
16 quiet=yes | 17 quiet=yes |
17 ;; | 18 ;; |
| 19 -r|--revision) |
| 20 svn_lkgr="$2" |
| 21 shift |
| 22 ;; |
18 *) | 23 *) |
19 echo "Unknown option: $1" | 24 echo "Unknown option: $1" |
20 ;; | 25 ;; |
21 esac | 26 esac |
22 shift | 27 shift |
23 done | 28 done |
24 | 29 |
25 svn_lkgr=`curl -s http://chromium-status.appspot.com/lkgr` | 30 if [ -z "$svn_lkgr" ]; then |
26 if [ $? != 0 -o -z "$svn_lkgr" ]; then | 31 svn_lkgr=`curl -s http://chromium-status.appspot.com/lkgr` |
27 echo 'Could not get svn lkgr from chromium-status.appspot.com/lkgr' | 32 if [ $? != 0 -o -z "$svn_lkgr" ]; then |
28 exit 1 | 33 echo 'Could not get svn lkgr from chromium-status.appspot.com/lkgr' |
| 34 exit 1 |
| 35 fi |
| 36 fi |
| 37 |
| 38 if [ "${svn_lkgr:0:1}" = "r" ]; then |
| 39 svn_lkgr="${svn_lkgr:1}" |
29 fi | 40 fi |
30 | 41 |
31 # Run a trivial git-svn command to force it to update the revision cache | 42 # Run a trivial git-svn command to force it to update the revision cache |
32 # (which causes spew that might otherwise confuse the next command). | 43 # (which causes spew that might otherwise confuse the next command). |
33 git svn info > /dev/null | 44 git svn info > /dev/null |
34 if [ $? != 0 ]; then | 45 if [ $? != 0 ]; then |
35 cat <<EOF 1>&2 | 46 cat <<EOF 1>&2 |
36 Could not run a trivial git-svn command. You probably need to set up your | 47 Could not run a trivial git-svn command. You probably need to set up your |
37 working directory for git-svn, by following these instructions: | 48 working directory for git-svn, by following these instructions: |
38 | 49 |
39 http://code.google.com/p/chromium/wiki/UsingNewGit#Initial_checkout | 50 http://code.google.com/p/chromium/wiki/UsingNewGit#Initial_checkout |
40 EOF | 51 EOF |
41 exit 1 | 52 exit 1 |
42 fi | 53 fi |
43 | 54 |
44 git_lkgr=`git svn find-rev r${svn_lkgr}` | 55 git_lkgr=`git svn find-rev r${svn_lkgr}` |
45 if [ $? != 0 -o -z "$git_lkgr" ]; then | 56 if [ $? != 0 -o -z "$git_lkgr" ]; then |
46 cat <<EOF 1>&2 | 57 cat <<EOF 1>&2 |
47 Could not map svn revision ${svn_lkgr} to a git commit. | 58 Could not map svn revision ${svn_lkgr} to a git commit. |
48 You may need to `git fetch` and try again. | 59 You may need to `git fetch` and try again. |
49 EOF | 60 EOF |
50 exit 1 | 61 exit 1 |
51 fi | 62 fi |
52 | 63 |
53 set -o pipefail | 64 set -o pipefail |
54 closest_commit=`git rev-list --ancestry-path \ | 65 closest_commit=`git rev-list --ancestry-path \ |
55 --grep='SVN changes up to revision [0-9]*' \ | 66 --grep='SVN changes up to revision [0-9]*' \ |
56 ${git_lkgr}..refs/remotes/origin/master | tail -1` | 67 ${git_lkgr}..refs/remotes/origin/master | tail -1` |
57 if [ $? != 0 -o -z "$closest_commit" ]; then | 68 if [ $? != 0 -o -z "$closest_commit" ]; then |
58 cat <<EOF 1>&2 | 69 closest_commit= |
59 Could not find a blessed git commit (with accurate .DEPS.git and submodules) | 70 closest_svn_commit= |
60 after svn lkgr revision $svn_lkgr. | 71 else |
| 72 closest_svn_commit=`git rev-list -n 1 ${closest_commit}^1` |
| 73 if [ $? != 0 -o -z "$closest_svn_commit" ]; then |
| 74 cat <<EOF 1>&2 |
| 75 I am thoroughly confused. Please file a bug report at http://new.crbug.com. |
61 EOF | 76 EOF |
62 exit 1 | 77 exit 1 |
63 fi | 78 fi |
64 | |
65 closest_svn_commit=`git rev-list -n 1 ${closest_commit}^1` | |
66 if [ $? != 0 -o -z "$closest_svn_commit" ]; then | |
67 cat <<EOF 1>&2 | |
68 I am thoroughly confused. Please file a bug report at http://new.crbug.com. | |
69 EOF | |
70 exit 1 | |
71 fi | 79 fi |
72 | 80 |
73 # Pick a name for the new branch. Use `git rev-parse` to make sure the branch | 81 # Pick a name for the new branch. Use `git rev-parse` to make sure the branch |
74 # doesn't already exist; if it does, iterate an integer suffix to uniquify it. | 82 # doesn't already exist; if it does, iterate an integer suffix to uniquify it. |
75 lkgr_branch="git_lkgr_r${svn_lkgr}" | 83 lkgr_branch="git_lkgr_r${svn_lkgr}" |
76 digit=1 | 84 digit=1 |
77 git rev-parse --verify -q "${lkgr_branch}" >/dev/null | 85 git rev-parse --verify -q "${lkgr_branch}" >/dev/null |
78 while [ $? -eq 0 ]; do | 86 while [ $? -eq 0 ]; do |
79 lkgr_branch="git_lkgr_r${svn_lkgr}_${digit}" | 87 lkgr_branch="git_lkgr_r${svn_lkgr}_${digit}" |
80 digit=`expr $digit + 1` | 88 digit=`expr $digit + 1` |
81 git rev-parse --verify -q "${lkgr_branch}" >/dev/null | 89 git rev-parse --verify -q "${lkgr_branch}" >/dev/null |
82 done | 90 done |
83 | 91 |
84 if [ "${closest_svn_commit}" = "${git_lkgr}" ]; then | 92 if [ "${closest_svn_commit}" = "${git_lkgr}" ]; then |
85 echo "${closest_commit}" | 93 echo "${closest_commit}" |
86 if [ "$force_branch" = "yes" ]; then | 94 if [ "$force_branch" = "yes" ]; then |
87 git checkout -b "${lkgr_branch}" "${closest_commit}" | 95 git checkout -b "${lkgr_branch}" "${closest_commit}" |
88 fi | 96 fi |
89 exit 0 | 97 exit 0 |
90 elif [ "${quiet}" = "yes" ]; then | 98 elif [ "${quiet}" = "yes" ]; then |
91 exit 1 | 99 exit 1 |
92 elif [ "${force_branch}" = "no" ]; then | 100 elif [ "${force_branch}" = "no" ]; then |
93 cat <<EOF | 101 echo "There is no master commit which corresponds exactly to svn revision ${sv
n_lkgr}." |
94 There is no master commit which corresponds exactly to lkgr. | 102 if [ -n "$closest_commit" ]; then |
95 The closest commit is ${closest_commit}. | 103 echo "The closest commit is ${closest_commit}." |
96 EOF | 104 fi |
97 read -n 1 -p 'Would you like to create a new branch based on lkgr? (y/N) ' | 105 read -n 1 -p "Would you like to create a new branch based on r${svn_lkgr}? (y/
N) " |
98 echo | 106 echo |
99 if [ "x$REPLY" != "xy" -a "x$REPLY" != "xY" ]; then | 107 if [ "x$REPLY" != "xy" -a "x$REPLY" != "xY" ]; then |
100 exit 0 | 108 exit 0 |
101 fi | 109 fi |
102 fi | 110 fi |
103 | 111 |
104 current_head=`git branch | grep '^\*' | cut -c3-` | 112 current_head=`git branch | grep '^\*' | cut -c3-` |
105 if [ "${current_head}" = "(no branch)" ]; then | 113 if [ "${current_head}" = "(no branch)" ]; then |
106 current_head=`git rev-parse HEAD` | 114 current_head=`git rev-parse HEAD` |
107 fi | 115 fi |
(...skipping 20 matching lines...) Expand all Loading... |
128 exit 1 | 136 exit 1 |
129 fi | 137 fi |
130 | 138 |
131 cat <<EOF | 139 cat <<EOF |
132 | 140 |
133 -------------------------------------------------------------------------------- | 141 -------------------------------------------------------------------------------- |
134 The new branch "$lkgr_branch" was branched from this commit: | 142 The new branch "$lkgr_branch" was branched from this commit: |
135 | 143 |
136 $git_lkgr | 144 $git_lkgr |
137 | 145 |
138 ... which maps to the svn lkgr commit r${svn_lkgr}. The new branch | 146 ... which maps to the svn commit r${svn_lkgr}. The new branch |
139 has one additional commit, to bring .DEPS.git, .gitmodules, and the | 147 has one additional commit, to bring .DEPS.git, .gitmodules, and the |
140 invisible git submodule files up to date with DEPS. | 148 invisible git submodule files up to date with DEPS. |
141 | 149 |
142 To create a working branch, do this: | 150 To create a working branch, do this: |
143 | 151 |
144 \$ git branch --track my_new_branch $lkgr_branch | 152 \$ git branch --track my_new_branch $lkgr_branch |
145 | 153 |
146 'git-cl upload' will do the right thing, i.e., it will cherry-pick all | 154 'git-cl upload' will do the right thing, i.e., it will cherry-pick all |
147 your changes from my_new_branch, but *not* the .DEPS.git+.gitmodules+submodules | 155 your changes from my_new_branch, but *not* the .DEPS.git+.gitmodules+submodules |
148 commit on $lkgr_branch. | 156 commit on $lkgr_branch. |
149 -------------------------------------------------------------------------------- | 157 -------------------------------------------------------------------------------- |
150 | 158 |
151 EOF | 159 EOF |
OLD | NEW |