OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 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 """This scripts takes the path to a dep and an svn revision, and updates the | 6 """This scripts takes the path to a dep and an svn revision, and updates the |
7 parent repo's DEPS file with the corresponding git revision. Sample invocation: | 7 parent repo's DEPS file with the corresponding git revision. Sample invocation: |
8 | 8 |
9 [chromium/src]$ roll-dep third_party/WebKit 12345 | 9 [chromium/src]$ roll-dep third_party/WebKit 12345 |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 m = GIT_SVN_ID_RE.match(line.strip()) | 100 m = GIT_SVN_ID_RE.match(line.strip()) |
101 if m: | 101 if m: |
102 return m.group(1) | 102 return m.group(1) |
103 return None | 103 return None |
104 | 104 |
105 | 105 |
106 def convert_svn_revision(dep_path, revision): | 106 def convert_svn_revision(dep_path, revision): |
107 """Find the git revision corresponding to an svn revision.""" | 107 """Find the git revision corresponding to an svn revision.""" |
108 err_msg = 'Unknown error' | 108 err_msg = 'Unknown error' |
109 revision = int(revision) | 109 revision = int(revision) |
| 110 latest_svn_rev = None |
110 with open(os.devnull, 'w') as devnull: | 111 with open(os.devnull, 'w') as devnull: |
111 for ref in ('HEAD', 'origin/master'): | 112 for ref in ('HEAD', 'origin/master'): |
112 try: | 113 try: |
113 log_p = Popen(['git', 'log', ref], | 114 log_p = Popen(['git', 'log', ref], |
114 cwd=dep_path, stdout=PIPE, stderr=devnull) | 115 cwd=dep_path, stdout=PIPE, stderr=devnull) |
115 grep_p = Popen(['grep', '-e', '^commit ', '-e', '^ *git-svn-id: '], | 116 grep_p = Popen(['grep', '-e', '^commit ', '-e', '^ *git-svn-id: '], |
116 stdin=log_p.stdout, stdout=PIPE, stderr=devnull) | 117 stdin=log_p.stdout, stdout=PIPE, stderr=devnull) |
117 git_rev = None | 118 git_rev = None |
118 prev_svn_rev = None | 119 prev_svn_rev = None |
119 for line in grep_p.stdout: | 120 for line in grep_p.stdout: |
120 if line.startswith('commit '): | 121 if line.startswith('commit '): |
121 git_rev = line.split()[1] | 122 git_rev = line.split()[1] |
122 continue | 123 continue |
123 try: | 124 try: |
124 svn_rev = int(line.split()[1].partition('@')[2]) | 125 svn_rev = int(line.split()[1].partition('@')[2]) |
125 except (IndexError, ValueError): | 126 except (IndexError, ValueError): |
126 print >> sys.stderr, ( | 127 print >> sys.stderr, ( |
127 'WARNING: Could not parse svn revision out of "%s"' % line) | 128 'WARNING: Could not parse svn revision out of "%s"' % line) |
128 continue | 129 continue |
| 130 if not latest_svn_rev or int(svn_rev) > int(latest_svn_rev): |
| 131 latest_svn_rev = svn_rev |
129 if svn_rev == revision: | 132 if svn_rev == revision: |
130 return git_rev | 133 return git_rev |
131 if svn_rev > revision: | 134 if svn_rev > revision: |
132 prev_svn_rev = svn_rev | 135 prev_svn_rev = svn_rev |
133 continue | 136 continue |
134 if prev_svn_rev: | 137 if prev_svn_rev: |
135 err_msg = 'git history skips from revision %d to revision %d.' % ( | 138 err_msg = 'git history skips from revision %d to revision %d.' % ( |
136 svn_rev, prev_svn_rev) | 139 svn_rev, prev_svn_rev) |
137 else: | 140 else: |
138 err_msg = ( | 141 err_msg = ( |
139 'latest available revision is %d; you may need to ' | 142 'latest available revision is %d; you may need to ' |
140 '"git fetch origin" to get the latest commits.' % svn_rev) | 143 '"git fetch origin" to get the latest commits.' % |
| 144 latest_svn_rev) |
141 finally: | 145 finally: |
142 log_p.terminate() | 146 log_p.terminate() |
143 grep_p.terminate() | 147 grep_p.terminate() |
144 raise RuntimeError('No match for revision %d; %s' % (revision, err_msg)) | 148 raise RuntimeError('No match for revision %d; %s' % (revision, err_msg)) |
145 | 149 |
146 | 150 |
147 def get_git_revision(dep_path, revision): | 151 def get_git_revision(dep_path, revision): |
148 """Convert the revision argument passed to the script to a git revision.""" | 152 """Convert the revision argument passed to the script to a git revision.""" |
149 svn_revision = None | 153 svn_revision = None |
150 if revision.startswith('r'): | 154 if revision.startswith('r'): |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 soln = get_solution(gclient_root, dep_path) | 351 soln = get_solution(gclient_root, dep_path) |
348 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name'])) | 352 soln_path = os.path.relpath(os.path.join(gclient_root, soln['name'])) |
349 dep_name = posix_path(os.path.relpath(dep_path, gclient_root)) | 353 dep_name = posix_path(os.path.relpath(dep_path, gclient_root)) |
350 (git_rev, svn_rev) = get_git_revision(dep_path, revision) | 354 (git_rev, svn_rev) = get_git_revision(dep_path, revision) |
351 comment = ('from svn revision %s' % svn_rev) if svn_rev else None | 355 comment = ('from svn revision %s' % svn_rev) if svn_rev else None |
352 assert git_rev, 'Could not find git revision matching %s.' % revision | 356 assert git_rev, 'Could not find git revision matching %s.' % revision |
353 return update_deps(soln_path, dep_path, dep_name, git_rev, comment) | 357 return update_deps(soln_path, dep_path, dep_name, git_rev, comment) |
354 | 358 |
355 if __name__ == '__main__': | 359 if __name__ == '__main__': |
356 sys.exit(main(sys.argv[1:])) | 360 sys.exit(main(sys.argv[1:])) |
OLD | NEW |