OLD | NEW |
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 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 # we've found our target (or hit a revision number lower than what | 44 # we've found our target (or hit a revision number lower than what |
45 # we're looking for, indicating not found). | 45 # we're looking for, indicating not found). |
46 | 46 |
47 target_rev = int(target_rev) | 47 target_rev = int(target_rev) |
48 | 48 |
49 # regexp matching the "commit" line from the log. | 49 # regexp matching the "commit" line from the log. |
50 commit_re = re.compile(r'^commit ([a-f\d]{40})$') | 50 commit_re = re.compile(r'^commit ([a-f\d]{40})$') |
51 # regexp matching the git-svn line from the log. | 51 # regexp matching the git-svn line from the log. |
52 git_svn_re = re.compile(r'^\s+git-svn-id: [^@]+@(\d+) ') | 52 git_svn_re = re.compile(r'^\s+git-svn-id: [^@]+@(\d+) ') |
53 | 53 |
54 # On Windows, use shell=True to get PATH interpretation. | |
55 shell = (os.name == 'nt') | |
56 log = subprocess.Popen(['git', 'log', '--no-color', '--first-parent', | 54 log = subprocess.Popen(['git', 'log', '--no-color', '--first-parent', |
57 '--pretty=medium', 'origin'], shell=shell, | 55 '--pretty=medium', 'origin'], |
| 56 shell=(os.name == 'nt'), |
58 stdout=subprocess.PIPE) | 57 stdout=subprocess.PIPE) |
59 # Track whether we saw a revision *later* than the one we're seeking. | 58 # Track whether we saw a revision *later* than the one we're seeking. |
60 saw_later = False | 59 saw_later = False |
61 for line in log.stdout: | 60 for line in log.stdout: |
62 match = commit_re.match(line) | 61 match = commit_re.match(line) |
63 if match: | 62 if match: |
64 commit = match.group(1) | 63 commit = match.group(1) |
65 continue | 64 continue |
66 match = git_svn_re.match(line) | 65 match = git_svn_re.match(line) |
67 if match: | 66 if match: |
(...skipping 13 matching lines...) Expand all Loading... |
81 print "Something has likely gone horribly wrong." | 80 print "Something has likely gone horribly wrong." |
82 return None | 81 return None |
83 | 82 |
84 def UpdateGClientBranch(webkit_rev): | 83 def UpdateGClientBranch(webkit_rev): |
85 """Update the magic gclient branch to point at |webkit_rev|. | 84 """Update the magic gclient branch to point at |webkit_rev|. |
86 | 85 |
87 Returns: true if the branch didn't need changes.""" | 86 Returns: true if the branch didn't need changes.""" |
88 target = FindSVNRev(webkit_rev) | 87 target = FindSVNRev(webkit_rev) |
89 if not target: | 88 if not target: |
90 print "r%s not available; fetching." % webkit_rev | 89 print "r%s not available; fetching." % webkit_rev |
91 subprocess.check_call(['git', 'fetch']) | 90 subprocess.check_call(['git', 'fetch'], shell=(os.name == 'nt')) |
92 target = FindSVNRev(webkit_rev) | 91 target = FindSVNRev(webkit_rev) |
93 if not target: | 92 if not target: |
94 print "ERROR: Couldn't map r%s to a git revision." % webkit_rev | 93 print "ERROR: Couldn't map r%s to a git revision." % webkit_rev |
95 sys.exit(1) | 94 sys.exit(1) |
96 | 95 |
97 current = RunGit(['show-ref', '--hash', MAGIC_GCLIENT_BRANCH]) | 96 current = RunGit(['show-ref', '--hash', MAGIC_GCLIENT_BRANCH]) |
98 if current == target: | 97 if current == target: |
99 return False # No change necessary. | 98 return False # No change necessary. |
100 | 99 |
101 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync', | 100 subprocess.check_call(['git', 'update-ref', '-m', 'gclient sync', |
102 MAGIC_GCLIENT_BRANCH, target]) | 101 MAGIC_GCLIENT_BRANCH, target], |
| 102 shell=(os.name == 'nt')) |
103 return True | 103 return True |
104 | 104 |
105 def UpdateCurrentCheckoutIfAppropriate(): | 105 def UpdateCurrentCheckoutIfAppropriate(): |
106 """Reset the current gclient branch if that's what we have checked out.""" | 106 """Reset the current gclient branch if that's what we have checked out.""" |
107 branch = RunGit(['symbolic-ref', '-q', 'HEAD']) | 107 branch = RunGit(['symbolic-ref', '-q', 'HEAD']) |
108 if branch != MAGIC_GCLIENT_BRANCH: | 108 if branch != MAGIC_GCLIENT_BRANCH: |
109 print "We have now updated the 'gclient' branch, but third_party/WebKit" | 109 print "We have now updated the 'gclient' branch, but third_party/WebKit" |
110 print "has some other branch ('%s') checked out." % branch | 110 print "has some other branch ('%s') checked out." % branch |
111 print "Run 'git checkout gclient' under third_party/WebKit if you want" | 111 print "Run 'git checkout gclient' under third_party/WebKit if you want" |
112 print "to switch it to the version requested by DEPS." | 112 print "to switch it to the version requested by DEPS." |
113 return 1 | 113 return 1 |
114 | 114 |
115 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat', | 115 if subprocess.call(['git', 'diff-index', '--exit-code', '--shortstat', |
116 'HEAD']): | 116 'HEAD'], shell=(os.name == 'nt')): |
117 print "Resetting tree state to new revision." | 117 print "Resetting tree state to new revision." |
118 subprocess.check_call(['git', 'reset', '--hard']) | 118 subprocess.check_call(['git', 'reset', '--hard'], shell=(os.name == 'nt')) |
119 | 119 |
120 def main(): | 120 def main(): |
121 if not os.path.exists('third_party/WebKit/.git'): | 121 if not os.path.exists('third_party/WebKit/.git'): |
122 if os.path.exists('third_party/WebKit'): | 122 if os.path.exists('third_party/WebKit'): |
123 print "ERROR: third_party/WebKit appears to not be under git control." | 123 print "ERROR: third_party/WebKit appears to not be under git control." |
124 else: | 124 else: |
125 print "ERROR: third_party/WebKit could not be found." | 125 print "ERROR: third_party/WebKit could not be found." |
126 print "Did you run this script from the right directory?" | 126 print "Did you run this script from the right directory?" |
127 | 127 |
128 print "See http://code.google.com/p/chromium/wiki/UsingWebKitGit for" | 128 print "See http://code.google.com/p/chromium/wiki/UsingWebKitGit for" |
129 print "setup instructions." | 129 print "setup instructions." |
130 return 1 | 130 return 1 |
131 | 131 |
132 webkit_rev = GetWebKitRev() | 132 webkit_rev = GetWebKitRev() |
133 print 'Desired revision: r%s.' % webkit_rev | 133 print 'Desired revision: r%s.' % webkit_rev |
134 os.chdir('third_party/WebKit') | 134 os.chdir('third_party/WebKit') |
135 changed = UpdateGClientBranch(webkit_rev) | 135 changed = UpdateGClientBranch(webkit_rev) |
136 if changed: | 136 if changed: |
137 return UpdateCurrentCheckoutIfAppropriate() | 137 return UpdateCurrentCheckoutIfAppropriate() |
138 else: | 138 else: |
139 print "Already on correct revision." | 139 print "Already on correct revision." |
140 return 0 | 140 return 0 |
141 | 141 |
142 if __name__ == '__main__': | 142 if __name__ == '__main__': |
143 sys.exit(main()) | 143 sys.exit(main()) |
OLD | NEW |