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

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

Issue 195098: sync-webkit-git: link to wiki, do some of Tony's review comments (Closed)
Patch Set: Created 11 years, 3 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 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 To use this: 11 See http://code.google.com/p/chromium/wiki/UsingWebKitGit for details on
12 1) rm -rf third_party/WebKit 12 how to use this.
13 2) git clone git://git.webkit.org/WebKit.git third_party/WebKit
14 3) edit your .gclient "custom_deps" section to exclude components underneath
15 third_party/WebKit:
16 "src/third_party/WebKit/LayoutTests": None,
17 "src/third_party/WebKit/JavaScriptCore": None,
18 "src/third_party/WebKit/WebCore": None,
19 4) run ./tools/sync-webkit-git.py now, and again whenever you run gclient
20 sync.
21
22 FAQ:
23 Q. Why not add this functionality to gclient itself?
24 A. DEPS actually specifies to only pull some subdirectories of
25 third_party/WebKit. So even if gclient supported git, we'd still need
26 to special-case this.
27 """ 13 """
28 14
29 import os 15 import os
30 import subprocess 16 import subprocess
31 import sys 17 import sys
32 18
33 # The name of the magic branch that lets us know that DEPS is managing 19 # The name of the magic branch that lets us know that DEPS is managing
34 # the update cycle. 20 # the update cycle.
35 MAGIC_GCLIENT_BRANCH = 'refs/heads/gclient' 21 MAGIC_GCLIENT_BRANCH = 'refs/heads/gclient'
36 22
37 def RunGit(command): 23 def RunGit(command):
38 """Run a git subcommand, returning its output.""" 24 """Run a git subcommand, returning its output."""
39 proc = subprocess.Popen(['git'] + command, stdout=subprocess.PIPE) 25 proc = subprocess.Popen(['git'] + command, stdout=subprocess.PIPE)
40 return proc.communicate()[0].strip() 26 return proc.communicate()[0].strip()
41 27
42 def GetWebKitRev(): 28 def GetWebKitRev():
43 """Extract the 'webkit_revision' variable out of DEPS.""" 29 """Extract the 'webkit_revision' variable out of DEPS."""
44 locals = {'Var': lambda _: ''} 30 locals = {'Var': lambda _: ''}
45 execfile('DEPS', {}, locals) 31 execfile('DEPS', {}, locals)
46 return locals['vars']['webkit_revision'] 32 return locals['vars']['webkit_revision']
47 33
48 def FindSVNRev(rev): 34 def FindSVNRev(rev):
49 """Map an SVN revision to a git hash. 35 """Map an SVN revision to a git hash.
50 Like 'git svn find-rev' but without the git-svn bits.""" 36 Like 'git svn find-rev' but without the git-svn bits."""
51 return RunGit(['rev-list', '-n', '1', '--grep=^git-svn-id: .*@%s' % rev, 37 # We find r123 by grepping for a line with "git-svn-id: blahblahblah@123".
38 return RunGit(['rev-list', '-n', '1', '--grep=^git-svn-id: .*@%s$' % rev,
52 'origin']) 39 'origin'])
53 40
54 def UpdateGClientBranch(webkit_rev): 41 def UpdateGClientBranch(webkit_rev):
55 """Update the magic gclient branch to point at |webkit_rev|. 42 """Update the magic gclient branch to point at |webkit_rev|.
56 43
57 Returns: true if the branch didn't need changes.""" 44 Returns: true if the branch didn't need changes."""
58 target = FindSVNRev(webkit_rev) 45 target = FindSVNRev(webkit_rev)
59 if not target: 46 if not target:
60 print "r%s not available; fetching." % webkit_rev 47 print "r%s not available; fetching." % webkit_rev
61 subprocess.check_call(['git', 'fetch']) 48 subprocess.check_call(['git', 'fetch'])
62 target = FindSVNRev(webkit_rev) 49 target = FindSVNRev(webkit_rev)
63 if not target: 50 if not target:
64 print "ERROR: Couldn't map r%s to a git revision." % webkit_rev 51 print "ERROR: Couldn't map r%s to a git revision." % webkit_rev
65 sys.exit(1) 52 sys.exit(1)
66 53
67 current = RunGit(['show-ref', '--hash', MAGIC_GCLIENT_BRANCH]) 54 current = RunGit(['show-ref', '--hash', MAGIC_GCLIENT_BRANCH])
68 if current == target: 55 if current == target:
69 return False # No change necessary. 56 return False # No change necessary.
70 57
71 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync', 58 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync',
72 MAGIC_GCLIENT_BRANCH, target]) 59 MAGIC_GCLIENT_BRANCH, target])
73 return True 60 return True
74 61
75 def UpdateCurrentCheckoutIfAppropriate(): 62 def UpdateCurrentCheckoutIfAppropriate():
76 """Reset the current gclient branch if that's what we have checked out.""" 63 """Reset the current gclient branch if that's what we have checked out."""
77 branch = RunGit(['symbolic-ref', '-q', 'HEAD']) 64 branch = RunGit(['symbolic-ref', '-q', 'HEAD'])
78 if branch != MAGIC_GCLIENT_BRANCH: 65 if branch != MAGIC_GCLIENT_BRANCH:
79 print "Directory has some other branch ('%s') checked out." % branch 66 print "third_party/WebKit has some other branch ('%s') checked out." % branc h
tony 2009/09/15 22:42:50 Nit: 80 cols.
80 print "Run 'git checkout gclient' to put this under control of gclient." 67 print "Run 'git checkout gclient' to put this under control of gclient."
81 return 68 return
82 69
83 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat', 70 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat',
84 'HEAD']): 71 'HEAD']):
85 print "Resetting tree state to new revision." 72 print "Resetting tree state to new revision."
86 subprocess.check_call(['git', 'reset', '--hard']) 73 subprocess.check_call(['git', 'reset', '--hard'])
87 74
88 def main(): 75 def main():
76 if not os.path.exists('third_party/WebKit/.git'):
77 print "ERROR: third_party/WebKit appears to not be under git control."
78 print "See http://code.google.com/p/chromium/wiki/UsingWebKitGit for"
79 print "setup instructions."
80 return
81
89 webkit_rev = GetWebKitRev() 82 webkit_rev = GetWebKitRev()
90 print 'Desired revision: r%s.' % webkit_rev 83 print 'Desired revision: r%s.' % webkit_rev
91 os.chdir('third_party/WebKit') 84 os.chdir('third_party/WebKit')
92 changed = UpdateGClientBranch(webkit_rev) 85 changed = UpdateGClientBranch(webkit_rev)
93 if changed: 86 if changed:
94 UpdateCurrentCheckoutIfAppropriate() 87 UpdateCurrentCheckoutIfAppropriate()
88 else:
89 print "Already on correct revision."
95 90
96 if __name__ == '__main__': 91 if __name__ == '__main__':
97 main() 92 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