Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: tools/sync-webkit-git.py

Issue 8769001: Enhance sync-webkit-git.py to support more actions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Apply changes with piman's review. Add me in AUTHORS. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Update third_party/WebKit using git. 6 """Update third_party/WebKit using git.
7 7
8 Under the assumption third_party/WebKit is a clone of git.webkit.org, 8 Under the assumption third_party/WebKit is a clone of git.webkit.org,
9 we can use git commands to make it match the version requested by DEPS. 9 we can use git commands to make it match the version requested by DEPS.
10 10
11 See http://code.google.com/p/chromium/wiki/UsingWebKitGit for details on 11 See http://code.google.com/p/chromium/wiki/UsingWebKitGit for details on
12 how to use this. 12 how to use this.
13 """ 13 """
14 14
15 import logging 15 import logging
16 import optparse 16 import optparse
17 import os 17 import os
18 import re 18 import re
19 import subprocess 19 import subprocess
20 import sys 20 import sys
21 import urllib
21 22
22 23
23 def RunGit(command): 24 def RunGit(command):
24 """Run a git subcommand, returning its output.""" 25 """Run a git subcommand, returning its output."""
25 # On Windows, use shell=True to get PATH interpretation. 26 # On Windows, use shell=True to get PATH interpretation.
26 command = ['git'] + command 27 command = ['git'] + command
27 logging.info(' '.join(command)) 28 logging.info(' '.join(command))
28 shell = (os.name == 'nt') 29 shell = (os.name == 'nt')
29 proc = subprocess.Popen(command, shell=shell, stdout=subprocess.PIPE) 30 proc = subprocess.Popen(command, shell=shell, stdout=subprocess.PIPE)
30 out = proc.communicate()[0].strip() 31 out = proc.communicate()[0].strip()
(...skipping 29 matching lines...) Expand all
60 61
61 62
62 def GetWebKitRev(): 63 def GetWebKitRev():
63 """Extract the 'webkit_revision' variable out of DEPS.""" 64 """Extract the 'webkit_revision' variable out of DEPS."""
64 locals = {'Var': lambda _: locals["vars"][_], 65 locals = {'Var': lambda _: locals["vars"][_],
65 'From': lambda *args: None} 66 'From': lambda *args: None}
66 execfile('DEPS', {}, locals) 67 execfile('DEPS', {}, locals)
67 return locals['vars']['webkit_revision'] 68 return locals['vars']['webkit_revision']
68 69
69 70
70 def FindSVNRev(target_rev): 71 def GetWebKitRevFromTarball(version):
72 """Extract the 'webkit_revision' variable out of tarball DEPS."""
73 deps_url = "http://src.chromium.org/svn/releases/" + version + "/DEPS"
74 f = urllib.urlopen(deps_url)
75 s = f.read()
76 m = re.search('(?<=Source@)\w+', s)
tony 2011/12/01 17:38:42 Nit: Can we make this match WebKit/Source? That m
77 return m.group(0)
78
79
80 def FindSVNRev(branch_name, target_rev):
71 """Map an SVN revision to a git hash. 81 """Map an SVN revision to a git hash.
72 Like 'git svn find-rev' but without the git-svn bits.""" 82 Like 'git svn find-rev' but without the git-svn bits."""
73 83
74 # We iterate through the commit log looking for "git-svn-id" lines, 84 # We iterate through the commit log looking for "git-svn-id" lines,
75 # which contain the SVN revision of that commit. We can stop once 85 # which contain the SVN revision of that commit. We can stop once
76 # we've found our target (or hit a revision number lower than what 86 # we've found our target (or hit a revision number lower than what
77 # we're looking for, indicating not found). 87 # we're looking for, indicating not found).
78 88
79 target_rev = int(target_rev) 89 target_rev = int(target_rev)
80 90
81 # regexp matching the "commit" line from the log. 91 # regexp matching the "commit" line from the log.
82 commit_re = re.compile(r'^commit ([a-f\d]{40})$') 92 commit_re = re.compile(r'^commit ([a-f\d]{40})$')
83 # regexp matching the git-svn line from the log. 93 # regexp matching the git-svn line from the log.
84 git_svn_re = re.compile(r'^\s+git-svn-id: [^@]+@(\d+) ') 94 git_svn_re = re.compile(r'^\s+git-svn-id: [^@]+@(\d+) ')
95 if not branch_name:
96 branch_name = 'origin/master'
85 cmd = ['git', 'log', '--no-color', '--first-parent', '--pretty=medium', 97 cmd = ['git', 'log', '--no-color', '--first-parent', '--pretty=medium',
86 'origin/master'] 98 branch_name]
87 logging.info(' '.join(cmd)) 99 logging.info(' '.join(cmd))
88 log = subprocess.Popen(cmd, shell=(os.name == 'nt'), stdout=subprocess.PIPE) 100 log = subprocess.Popen(cmd, shell=(os.name == 'nt'), stdout=subprocess.PIPE)
89 # Track whether we saw a revision *later* than the one we're seeking. 101 # Track whether we saw a revision *later* than the one we're seeking.
90 saw_later = False 102 saw_later = False
91 for line in log.stdout: 103 for line in log.stdout:
92 match = commit_re.match(line) 104 match = commit_re.match(line)
93 if match: 105 if match:
94 commit = match.group(1) 106 commit = match.group(1)
95 continue 107 continue
96 match = git_svn_re.match(line) 108 match = git_svn_re.match(line)
(...skipping 19 matching lines...) Expand all
116 branch = GetOverrideShortBranchName() 128 branch = GetOverrideShortBranchName()
117 if not branch: 129 if not branch:
118 branch = 'gclient' 130 branch = 'gclient'
119 131
120 remote = RunGit(['config', '--get', 'branch.' + branch + '.remote']) 132 remote = RunGit(['config', '--get', 'branch.' + branch + '.remote'])
121 if remote: 133 if remote:
122 return remote 134 return remote
123 return 'origin' 135 return 'origin'
124 136
125 137
126 def UpdateGClientBranch(webkit_rev, magic_gclient_branch): 138 def UpdateGClientBranch(branch_name, webkit_rev, magic_gclient_branch):
127 """Update the magic gclient branch to point at |webkit_rev|. 139 """Update the magic gclient branch to point at |webkit_rev|.
128 140
129 Returns: true if the branch didn't need changes.""" 141 Returns: true if the branch didn't need changes."""
130 target = FindSVNRev(webkit_rev) 142 target = FindSVNRev(branch_name, webkit_rev)
131 if not target: 143 if not target:
132 print "r%s not available; fetching." % webkit_rev 144 print "r%s not available; fetching." % webkit_rev
133 subprocess.check_call(['git', 'fetch', GetRemote()], 145 subprocess.check_call(['git', 'fetch', GetRemote()],
134 shell=(os.name == 'nt')) 146 shell=(os.name == 'nt'))
135 target = FindSVNRev(webkit_rev) 147 target = FindSVNRev(branch_name, webkit_rev)
136 if not target: 148 if not target:
137 print "ERROR: Couldn't map r%s to a git revision." % webkit_rev 149 print "ERROR: Couldn't map r%s to a git revision." % webkit_rev
138 sys.exit(1) 150 sys.exit(1)
139 151
140 current = RunGit(['show-ref', '--hash', magic_gclient_branch]) 152 current = RunGit(['show-ref', '--hash', magic_gclient_branch])
141 if current == target: 153 if current == target:
142 return False # No change necessary. 154 return False # No change necessary.
143 155
144 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync', 156 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync',
145 magic_gclient_branch, target], 157 magic_gclient_branch, target],
(...skipping 13 matching lines...) Expand all
159 171
160 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat', 172 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat',
161 'HEAD'], shell=(os.name == 'nt')): 173 'HEAD'], shell=(os.name == 'nt')):
162 print "Resetting tree state to new revision." 174 print "Resetting tree state to new revision."
163 subprocess.check_call(['git', 'reset', '--hard'], shell=(os.name == 'nt')) 175 subprocess.check_call(['git', 'reset', '--hard'], shell=(os.name == 'nt'))
164 176
165 177
166 def main(): 178 def main():
167 parser = optparse.OptionParser() 179 parser = optparse.OptionParser()
168 parser.add_option('-v', '--verbose', action='store_true') 180 parser.add_option('-v', '--verbose', action='store_true')
181 parser.add_option('-r', '--revision', help="switch to desired revision")
182 parser.add_option('-t', '--tarball', help="switch to desired tarball release")
183 parser.add_option('-b', '--branch', help="branch name that gclient generate")
169 options, args = parser.parse_args() 184 options, args = parser.parse_args()
170 if options.verbose: 185 if options.verbose:
171 logging.basicConfig(level=logging.INFO) 186 logging.basicConfig(level=logging.INFO)
172 if not os.path.exists('third_party/WebKit/.git'): 187 if not os.path.exists('third_party/WebKit/.git'):
173 if os.path.exists('third_party/WebKit'): 188 if os.path.exists('third_party/WebKit'):
174 print "ERROR: third_party/WebKit appears to not be under git control." 189 print "ERROR: third_party/WebKit appears to not be under git control."
175 else: 190 else:
176 print "ERROR: third_party/WebKit could not be found." 191 print "ERROR: third_party/WebKit could not be found."
177 print "Did you run this script from the right directory?" 192 print "Did you run this script from the right directory?"
178 193
179 print "See http://code.google.com/p/chromium/wiki/UsingWebKitGit for" 194 print "See http://code.google.com/p/chromium/wiki/UsingWebKitGit for"
180 print "setup instructions." 195 print "setup instructions."
181 return 1 196 return 1
182 197
183 webkit_rev = GetWebKitRev() 198 if options.revision:
199 webkit_rev = options.revision
200 if options.tarball:
201 print "WARNING: --revision is given, so ignore --tarball"
202 else:
203 if options.tarball:
204 webkit_rev = GetWebKitRevFromTarball(options.tarball)
205 else:
206 webkit_rev = GetWebKitRev()
207
184 print 'Desired revision: r%s.' % webkit_rev 208 print 'Desired revision: r%s.' % webkit_rev
185 os.chdir('third_party/WebKit') 209 os.chdir('third_party/WebKit')
186 magic_gclient_branch = GetGClientBranchName() 210 magic_gclient_branch = GetGClientBranchName()
187 changed = UpdateGClientBranch(webkit_rev, magic_gclient_branch) 211 changed = UpdateGClientBranch(options.branch, webkit_rev,
212 magic_gclient_branch)
188 if changed: 213 if changed:
189 return UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch) 214 return UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch)
190 else: 215 else:
191 print "Already on correct revision." 216 print "Already on correct revision."
192 return 0 217 return 0
193 218
194 219
195 if __name__ == '__main__': 220 if __name__ == '__main__':
196 sys.exit(main()) 221 sys.exit(main())
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698