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

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

Issue 507473002: Fix sync-webkit-git.py for git migration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months 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 | « no previous file | 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
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 def GetWebKitRevFromTarball(version): 71 def GetWebKitRevFromTarball(version):
72 """Extract the 'webkit_revision' variable out of tarball DEPS.""" 72 """Extract the 'webkit_revision' variable out of tarball DEPS."""
73 deps_url = "http://src.chromium.org/svn/releases/" + version + "/DEPS" 73 deps_url = "http://src.chromium.org/svn/releases/" + version + "/DEPS"
74 f = urllib.urlopen(deps_url) 74 f = urllib.urlopen(deps_url)
75 s = f.read() 75 s = f.read()
76 m = re.search('(?<=/Source@)\w+', s) 76 m = re.search('(?<=/Source@)\w+', s)
77 return m.group(0) 77 return m.group(0)
78 78
79 79
80 def FindSVNRev(branch_name, target_rev): 80 def HasGitRev(target_rev):
81 """Map an SVN revision to a git hash. 81 """Finds if a git hash exists in the repository."""
82 Like 'git svn find-rev' but without the git-svn bits."""
83 82
84 # We iterate through the commit log looking for "git-svn-id" lines, 83 cmd = ['git', 'rev-list', '--max-count=1', target_rev]
85 # which contain the SVN revision of that commit. We can stop once
86 # we've found our target (or hit a revision number lower than what
87 # we're looking for, indicating not found).
88
89 target_rev = int(target_rev)
90
91 # regexp matching the "commit" line from the log.
92 commit_re = re.compile(r'^commit ([a-f\d]{40})$')
93 # regexp matching the git-svn line from the log.
94 git_svn_re = re.compile(r'^\s+git-svn-id: [^@]+@(\d+) ')
95 if not branch_name:
96 branch_name = 'origin/master'
97 cmd = ['git', 'log', '--no-color', '--first-parent', '--pretty=medium',
98 branch_name]
99 logging.info(' '.join(cmd)) 84 logging.info(' '.join(cmd))
100 log = subprocess.Popen(cmd, shell=(os.name == 'nt'), stdout=subprocess.PIPE) 85 result = subprocess.call(cmd, shell=(os.name == 'nt'), stdout=subprocess.PIPE)
101 # Track whether we saw a revision *later* than the one we're seeking. 86 return result == 0
102 saw_later = False
103 for line in log.stdout:
104 match = commit_re.match(line)
105 if match:
106 commit = match.group(1)
107 continue
108 match = git_svn_re.match(line)
109 if match:
110 rev = int(match.group(1))
111 if rev <= target_rev:
112 log.stdout.close() # Break pipe.
113 if rev < target_rev:
114 if not saw_later:
115 return None # Can't be sure whether this rev is ok.
116 print ("WARNING: r%d not found, so using next nearest earlier r%d" %
117 (target_rev, rev))
118 return commit
119 else:
120 saw_later = True
121
122 print "Error: reached end of log without finding commit info."
123 print "Something has likely gone horribly wrong."
124 return None
125 87
126 88
127 def GetRemote(): 89 def GetRemote():
128 branch = GetOverrideShortBranchName() 90 branch = GetOverrideShortBranchName()
129 if not branch: 91 if not branch:
130 branch = 'gclient' 92 branch = 'gclient'
131 93
132 remote = RunGit(['config', '--get', 'branch.' + branch + '.remote']) 94 remote = RunGit(['config', '--get', 'branch.' + branch + '.remote'])
133 if remote: 95 if remote:
134 return remote 96 return remote
135 return 'origin' 97 return 'origin'
136 98
137 99
138 def UpdateGClientBranch(branch_name, webkit_rev, magic_gclient_branch): 100 def UpdateGClientBranch(webkit_rev, magic_gclient_branch):
139 """Update the magic gclient branch to point at |webkit_rev|. 101 """Update the magic gclient branch to point at |webkit_rev|.
140 102
141 Returns: true if the branch didn't need changes.""" 103 Returns: true if the branch didn't need changes."""
142 target = FindSVNRev(branch_name, webkit_rev) 104 if not HasGitRev(webkit_rev):
143 if not target: 105 print "%s not available; fetching." % webkit_rev
144 print "r%s not available; fetching." % webkit_rev
145 subprocess.check_call(['git', 'fetch', GetRemote()], 106 subprocess.check_call(['git', 'fetch', GetRemote()],
146 shell=(os.name == 'nt')) 107 shell=(os.name == 'nt'))
147 target = FindSVNRev(branch_name, webkit_rev) 108 if not HasGitRev(webkit_rev):
148 if not target: 109 print "ERROR: Couldn't find %s in the repository." % webkit_rev
149 print "ERROR: Couldn't map r%s to a git revision." % webkit_rev 110 sys.exit(1)
150 sys.exit(1)
151 111
152 current = RunGit(['show-ref', '--hash', magic_gclient_branch]) 112 current = RunGit(['show-ref', '--hash', magic_gclient_branch])
153 if current == target: 113 if current == webkit_rev:
154 return False # No change necessary. 114 return False # No change necessary.
155 115
156 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync', 116 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync',
157 magic_gclient_branch, target], 117 magic_gclient_branch, webkit_rev],
158 shell=(os.name == 'nt')) 118 shell=(os.name == 'nt'))
159 return True 119 return True
160 120
161 121
162 def UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch): 122 def UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch):
163 """Reset the current gclient branch if that's what we have checked out.""" 123 """Reset the current gclient branch if that's what we have checked out."""
164 branch = RunGit(['symbolic-ref', '-q', 'HEAD']) 124 branch = RunGit(['symbolic-ref', '-q', 'HEAD'])
165 if branch != magic_gclient_branch: 125 if branch != magic_gclient_branch:
166 print "We have now updated the 'gclient' branch, but third_party/WebKit" 126 print "We have now updated the 'gclient' branch, but third_party/WebKit"
167 print "has some other branch ('%s') checked out." % branch 127 print "has some other branch ('%s') checked out." % branch
168 print "Run 'git checkout gclient' under third_party/WebKit if you want" 128 print "Run 'git checkout gclient' under third_party/WebKit if you want"
169 print "to switch it to the version requested by DEPS." 129 print "to switch it to the version requested by DEPS."
170 return 1 130 return 1
171 131
172 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat', 132 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat',
173 'HEAD'], shell=(os.name == 'nt')): 133 'HEAD'], shell=(os.name == 'nt')):
174 print "Resetting tree state to new revision." 134 print "Resetting tree state to new revision."
175 subprocess.check_call(['git', 'reset', '--hard'], shell=(os.name == 'nt')) 135 subprocess.check_call(['git', 'reset', '--hard'], shell=(os.name == 'nt'))
176 136
177 137
178 def main(): 138 def main():
179 parser = optparse.OptionParser() 139 parser = optparse.OptionParser()
180 parser.add_option('-v', '--verbose', action='store_true') 140 parser.add_option('-v', '--verbose', action='store_true')
181 parser.add_option('-r', '--revision', help="switch to desired revision") 141 parser.add_option('-r', '--revision', help="switch to desired revision")
182 parser.add_option('-t', '--tarball', help="switch to desired tarball release") 142 parser.add_option('-t', '--tarball', help="switch to desired tarball release")
183 parser.add_option('-b', '--branch', help="branch name that gclient generate")
184 options, args = parser.parse_args() 143 options, args = parser.parse_args()
185 if options.verbose: 144 if options.verbose:
186 logging.basicConfig(level=logging.INFO) 145 logging.basicConfig(level=logging.INFO)
187 if not os.path.exists('third_party/WebKit/.git'): 146 if not os.path.exists('third_party/WebKit/.git'):
188 if os.path.exists('third_party/WebKit'): 147 if os.path.exists('third_party/WebKit'):
189 print "ERROR: third_party/WebKit appears to not be under git control." 148 print "ERROR: third_party/WebKit appears to not be under git control."
190 else: 149 else:
191 print "ERROR: third_party/WebKit could not be found." 150 print "ERROR: third_party/WebKit could not be found."
192 print "Did you run this script from the right directory?" 151 print "Did you run this script from the right directory?"
193 152
194 print "See http://code.google.com/p/chromium/wiki/UsingWebKitGit for" 153 print "See http://code.google.com/p/chromium/wiki/UsingWebKitGit for"
195 print "setup instructions." 154 print "setup instructions."
196 return 1 155 return 1
197 156
198 if options.revision: 157 if options.revision:
199 webkit_rev = options.revision 158 webkit_rev = options.revision
200 if options.tarball: 159 if options.tarball:
201 print "WARNING: --revision is given, so ignore --tarball" 160 print "WARNING: --revision is given, so ignore --tarball"
202 else: 161 else:
203 if options.tarball: 162 if options.tarball:
204 webkit_rev = GetWebKitRevFromTarball(options.tarball) 163 webkit_rev = GetWebKitRevFromTarball(options.tarball)
205 else: 164 else:
206 webkit_rev = GetWebKitRev() 165 webkit_rev = GetWebKitRev()
207 166
208 print 'Desired revision: r%s.' % webkit_rev 167 print 'Desired revision: %s.' % webkit_rev
209 os.chdir('third_party/WebKit') 168 os.chdir('third_party/WebKit')
210 magic_gclient_branch = GetGClientBranchName() 169 magic_gclient_branch = GetGClientBranchName()
211 changed = UpdateGClientBranch(options.branch, webkit_rev, 170 changed = UpdateGClientBranch(webkit_rev, magic_gclient_branch)
212 magic_gclient_branch)
213 if changed: 171 if changed:
214 return UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch) 172 return UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch)
215 else: 173 else:
216 print "Already on correct revision." 174 print "Already on correct revision."
217 return 0 175 return 0
218 176
219 177
220 if __name__ == '__main__': 178 if __name__ == '__main__':
221 sys.exit(main()) 179 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698